UNPKG

814 BJavaScriptView Raw
1
2
3!function(exports) {
4 exports.encode = function(o) {
5 return encode(o, "")
6 }
7
8 var hasOwn = Object.prototype.hasOwnProperty
9
10 function encode(o, pre, opts) {
11 var i
12 , s = []
13 , c = typeof o
14 if (c === "string") {
15 i = o.split("'")
16 c = o.split('"')
17 if (i > 1 || c > 1) {
18 return pre + (
19 i > c ?
20 '"' + s.join("").replace(/"/, '\\"') + '"' :
21 "'" + s.join("").replace(/'/, "''") + "'"
22 )
23 }
24 return pre + o
25 }
26 if (o && c === "object") {
27 if(Array.isArray(o)) {
28 for (i = o.length; i--; s[i] = encode(o[i], " ").slice(2));
29 return pre + "- " + s.join("\n" + pre + "- ")
30 }
31 for (i in o) hasOwn.call(o,i) && s.push(i + ": " + encode(o[i], ""))
32 return pre + s.join("\n" + pre)
33 }
34 return o==null?'null':pre + o
35 }
36
37 function decode(str, opts) {
38 }
39}(this)
40
41