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AAa,EAAE,IAAU,EAAE,EAAE;QAC5D,OAAO,cAAc,IAAI,CAAC,GAAG,CAAC,QAAQ,EAAE,CAAC,GAAG,CAAC;IAC/C,CAAC;IACD,iBAAiB,EAAE,CAAC,GAAW,EAAE,EAAE;QACjC,OAAO,cAAc,GAAG,GAAG,CAAC;IAC9B,CAAC;IACD,kBAAkB,EAAE,CAAC,IAAa,EAAE,EAAE;QACpC,OAAO,eAAe,IAAI,GAAG,CAAC;IAChC,CAAC;IACD,cAAc,EAAE,CAAC,GAAa,EAAE,KAAa,EAAE,IAAU,EAAE,EAAE;QAC3D,OAAO,WAAW,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC;IAC7C,CAAC;IACD,cAAc,EAAE,CAAC,GAAkB,EAAE,KAAa,EAAE,IAAU,EAAE,EAAE;QAChE,OAAO,WAAW,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC;IAC7C,CAAC;IACD,iBAAiB,EAAE,MAAM;IACzB,iBAAiB,EAAE,cAAc;IACjC,iBAAiB,EAAE,cAAc;CAClC,CAAC","sourcesContent":["import { Next, ToString } from \"./types\";\nimport { quoteKey } from \"./quote\";\nimport { USED_METHOD_KEY } from \"./function\";\nimport { arrayToString } from \"./array\";\n\n/**\n * Transform an object into a string.\n */\nexport const objectToString: ToString = (value, space, next, key) => {\n if (typeof (Buffer as unknown) === \"function\" && Buffer.isBuffer(value)) {\n return `new Buffer(${next(value.toString())})`;\n }\n\n // Use the internal object string to select stringify method.\n const toString = OBJECT_TYPES[Object.prototype.toString.call(value)];\n return toString ? toString(value, space, next, key) : undefined;\n};\n\n/**\n * Stringify an object of keys and values.\n */\nconst rawObjectToString: ToString = (obj, indent, next) => {\n const eol = indent ? \"\\n\" : \"\";\n const space = indent ? \" \" : \"\";\n\n // Iterate over object keys and concat string together.\n const values = Object.keys(obj)\n .reduce(\n function(values, key) {\n const fn = obj[key];\n const result = next(fn, key);\n\n // Omit `undefined` object entries.\n if (result === undefined) return values;\n\n // String format the value data.\n const value = result.split(\"\\n\").join(`\\n${indent}`);\n\n // Skip `key` prefix for function parser.\n if (USED_METHOD_KEY.has(fn)) {\n values.push(`${indent}${value}`);\n return values;\n }\n\n values.push(`${indent}${quoteKey(key, next)}:${space}${value}`);\n return values;\n },\n [] as string[]\n )\n .join(`,${eol}`);\n\n // Avoid new lines in an empty object.\n if (values === \"\") return \"{}\";\n\n return `{${eol}${values}${eol}}`;\n};\n\n/**\n * Stringify global variable access.\n */\nconst globalToString: ToString = (value, space, next) => {\n return `Function(${next(\"return this\")})()`;\n};\n\n/**\n * Convert JavaScript objects into strings.\n */\nconst OBJECT_TYPES: Record<string, ToString> = {\n \"[object Array]\": arrayToString,\n \"[object Object]\": rawObjectToString,\n \"[object Error]\": (error: Error, space: string, next: Next) => {\n return `new Error(${next(error.message)})`;\n },\n \"[object Date]\": (date: Date) => {\n return `new Date(${date.getTime()})`;\n },\n \"[object String]\": (str: String, space: string, next: Next) => {\n return `new String(${next(str.toString())})`;\n },\n \"[object Number]\": (num: number) => {\n return `new Number(${num})`;\n },\n \"[object Boolean]\": (bool: boolean) => {\n return `new Boolean(${bool})`;\n },\n \"[object Set]\": (set: Set<any>, space: string, next: Next) => {\n return `new Set(${next(Array.from(set))})`;\n },\n \"[object Map]\": (map: Map<any, any>, space: string, next: Next) => {\n return `new Map(${next(Array.from(map))})`;\n },\n \"[object RegExp]\": String,\n \"[object global]\": globalToString,\n \"[object Window]\": globalToString\n};\n"]} |