UNPKG

@bitty/json

Version:
1 lines 1.56 kB
{"version":3,"file":"json.mjs","sources":["../src/fromJSON.js","../src/toJSON.js"],"sourcesContent":["/**\n * Transforms (parses) a JSON string to {@link Json} value.\n * @example\n * ```ts\n * type User = {\n * name: string;\n * };\n *\n * const user = fromJSON<User>('{\"name\":\"Carlos Marcos\"}');\n * //=> { name: 'Carlos Marcos' }\n * ```\n * @param json - The JSON string.\n */\nfunction fromJSON(json) {\n return JSON.parse(json);\n}\nexport default fromJSON;\n//# sourceMappingURL=fromJSON.js.map","/**\n * Transforms a {@link Json} value to JSON string.\n * @example\n * ```ts\n * type User = {\n * name: string;\n * };\n *\n * const user: User = {\n * name: 'Karl Marx',\n * };\n *\n * toJson(user, 0);\n * //=> '{\"name\":\"Karl Marx\"}'\n * ```\n * @param value - A {@link ReadonlyJson} value, usually an object or array.\n * @param space - A character or the number of spaces used for indentation.\n */\nfunction toJSON(value, space) {\n if (space === void 0) { space = 2; }\n return JSON.stringify(value, null, space);\n}\nexport default toJSON;\n//# sourceMappingURL=toJSON.js.map"],"names":[],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAAS,QAAQ,CAAC,IAAI,EAAE;AACxB,IAAI,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC;AAC3B;;ACfA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAAS,MAAM,CAAC,KAAK,EAAE,KAAK,EAAE;AAC9B,IAAI,IAAI,KAAK,KAAK,MAAM,EAAE,EAAE,KAAK,GAAG,CAAC,CAAC,CAAC;AACvC,IAAI,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,IAAI,EAAE,KAAK,CAAC;AAC7C;;;;"}