@awsless/json
Advanced tools
+8
-3
@@ -27,3 +27,4 @@ "use strict"; | ||
| patch: () => patch, | ||
| stringify: () => stringify | ||
| stringify: () => stringify, | ||
| unpatch: () => unpatch | ||
| }); | ||
@@ -134,4 +135,7 @@ module.exports = __toCommonJS(src_exports); | ||
| var patch = (value, types = {}) => { | ||
| return parse(stringify(value, types), types); | ||
| return parse(JSON.stringify(value), types); | ||
| }; | ||
| var unpatch = (value, types = {}) => { | ||
| return JSON.parse(stringify(value, types)); | ||
| }; | ||
| // Annotate the CommonJS export names for ESM import in node: | ||
@@ -143,3 +147,4 @@ 0 && (module.exports = { | ||
| patch, | ||
| stringify | ||
| stringify, | ||
| unpatch | ||
| }); |
+8
-3
@@ -27,3 +27,4 @@ "use strict"; | ||
| patch: () => patch, | ||
| stringify: () => stringify | ||
| stringify: () => stringify, | ||
| unpatch: () => unpatch | ||
| }); | ||
@@ -134,4 +135,7 @@ module.exports = __toCommonJS(src_exports); | ||
| var patch = (value, types = {}) => { | ||
| return parse(stringify(value, types), types); | ||
| return parse(JSON.stringify(value), types); | ||
| }; | ||
| var unpatch = (value, types = {}) => { | ||
| return JSON.parse(stringify(value, types)); | ||
| }; | ||
| // Annotate the CommonJS export names for ESM import in node: | ||
@@ -143,3 +147,4 @@ 0 && (module.exports = { | ||
| patch, | ||
| stringify | ||
| stringify, | ||
| unpatch | ||
| }); |
+3
-2
@@ -8,3 +8,4 @@ type Serializable<I, O> = { | ||
| declare const patch: <T>(value: T, types?: SerializableTypes) => T; | ||
| declare const patch: (value: unknown, types?: SerializableTypes) => any; | ||
| declare const unpatch: (value: unknown, types?: SerializableTypes) => any; | ||
@@ -19,2 +20,2 @@ declare const parse: (json: string, types?: SerializableTypes) => any; | ||
| export { type Serializable, createReplacer, createReviver, parse, patch, stringify }; | ||
| export { type Serializable, createReplacer, createReviver, parse, patch, stringify, unpatch }; |
+3
-2
@@ -8,3 +8,4 @@ type Serializable<I, O> = { | ||
| declare const patch: <T>(value: T, types?: SerializableTypes) => T; | ||
| declare const patch: (value: unknown, types?: SerializableTypes) => any; | ||
| declare const unpatch: (value: unknown, types?: SerializableTypes) => any; | ||
@@ -19,2 +20,2 @@ declare const parse: (json: string, types?: SerializableTypes) => any; | ||
| export { type Serializable, createReplacer, createReviver, parse, patch, stringify }; | ||
| export { type Serializable, createReplacer, createReviver, parse, patch, stringify, unpatch }; |
+6
-2
@@ -103,4 +103,7 @@ // src/type/bigfloat.ts | ||
| var patch = (value, types = {}) => { | ||
| return parse(stringify(value, types), types); | ||
| return parse(JSON.stringify(value), types); | ||
| }; | ||
| var unpatch = (value, types = {}) => { | ||
| return JSON.parse(stringify(value, types)); | ||
| }; | ||
| export { | ||
@@ -111,3 +114,4 @@ createReplacer, | ||
| patch, | ||
| stringify | ||
| stringify, | ||
| unpatch | ||
| }; |
+1
-1
| { | ||
| "name": "@awsless/json", | ||
| "version": "0.0.4", | ||
| "version": "0.0.5", | ||
| "license": "MIT", | ||
@@ -5,0 +5,0 @@ "type": "module", |
+10
-6
@@ -68,6 +68,6 @@ | ||
| // Stringify your custom type | ||
| // Stringify your custom type. | ||
| const json = stringify(new Custom('example'), { $custom }) | ||
| // Parse the json with your custom type | ||
| // Parse the json with your custom type. | ||
| const value = parse(json, { $custom }) | ||
@@ -78,13 +78,17 @@ ``` | ||
| Object properties with `undefined` as value type will be stripped away. | ||
| ### Don't use the $ character inside your JSON. | ||
| We use the `$` character to encode our special types inside JSON. In order to prevent parsing errors we recommend to avoid using the `$` character inside your object property names. | ||
| ### Object properties with `undefined` as value type will be stripped away. | ||
| ```ts | ||
| // Will result in an empty object | ||
| // Will result in an empty object. | ||
| const result = parse(stringify({ key: undefined })) | ||
| // Will log false | ||
| // Will log false. | ||
| console.log('key' in result) | ||
| // Will log true | ||
| // Will log true. | ||
| console.log(result.key === undefined) | ||
| ``` |
14404
5.59%393
3.97%93
4.49%