@awsless/json 0.0.4 → 0.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.MD CHANGED
@@ -65,24 +65,28 @@ const $custom: Serializable<Custom, string> = {
65
65
  stringify: v => v.value,
66
66
  }
67
67
 
68
- // Stringify your custom type
68
+ // Stringify your custom type.
69
69
  const json = stringify(new Custom('example'), { $custom })
70
70
 
71
- // Parse the json with your custom type
71
+ // Parse the json with your custom type.
72
72
  const value = parse(json, { $custom })
73
73
  ```
74
74
 
75
75
  ## Known Issue's
76
76
 
77
- Object properties with `undefined` as value type will be stripped away.
77
+ ### Don't use the $ character inside your JSON.
78
+
79
+ 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.
80
+
81
+ ### Object properties with `undefined` as value type will be stripped away.
78
82
 
79
83
  ```ts
80
- // Will result in an empty object
84
+ // Will result in an empty object.
81
85
  const result = parse(stringify({ key: undefined }))
82
86
 
83
- // Will log false
87
+ // Will log false.
84
88
  console.log('key' in result)
85
89
 
86
- // Will log true
90
+ // Will log true.
87
91
  console.log(result.key === undefined)
88
92
  ```
package/dist/index.cjs CHANGED
@@ -24,7 +24,8 @@ __export(src_exports, {
24
24
  createReviver: () => createReviver,
25
25
  parse: () => parse,
26
26
  patch: () => patch,
27
- stringify: () => stringify
27
+ stringify: () => stringify,
28
+ unpatch: () => unpatch
28
29
  });
29
30
  module.exports = __toCommonJS(src_exports);
30
31
 
@@ -130,7 +131,10 @@ var createReplacer = (types = {}) => {
130
131
 
131
132
  // src/patch.ts
132
133
  var patch = (value, types = {}) => {
133
- return parse(stringify(value, types), types);
134
+ return parse(JSON.stringify(value), types);
135
+ };
136
+ var unpatch = (value, types = {}) => {
137
+ return JSON.parse(stringify(value, types));
134
138
  };
135
139
  // Annotate the CommonJS export names for ESM import in node:
136
140
  0 && (module.exports = {
@@ -138,5 +142,6 @@ var patch = (value, types = {}) => {
138
142
  createReviver,
139
143
  parse,
140
144
  patch,
141
- stringify
145
+ stringify,
146
+ unpatch
142
147
  });
package/dist/index.d.cts CHANGED
@@ -5,7 +5,8 @@ type Serializable<I, O> = {
5
5
  };
6
6
  type SerializableTypes = Record<string, Serializable<any, any>>;
7
7
 
8
- declare const patch: <T>(value: T, types?: SerializableTypes) => T;
8
+ declare const patch: (value: unknown, types?: SerializableTypes) => any;
9
+ declare const unpatch: (value: unknown, types?: SerializableTypes) => any;
9
10
 
10
11
  declare const parse: (json: string, types?: SerializableTypes) => any;
11
12
  type Reviver = (this: any, key: string, value: any) => any;
@@ -15,4 +16,4 @@ declare const stringify: (value: unknown, types?: SerializableTypes) => string;
15
16
  type Replacer = (this: any, key: string, value: any) => any;
16
17
  declare const createReplacer: (types?: SerializableTypes) => Replacer;
17
18
 
18
- export { type Serializable, createReplacer, createReviver, parse, patch, stringify };
19
+ export { type Serializable, createReplacer, createReviver, parse, patch, stringify, unpatch };
package/dist/index.d.ts CHANGED
@@ -5,7 +5,8 @@ type Serializable<I, O> = {
5
5
  };
6
6
  type SerializableTypes = Record<string, Serializable<any, any>>;
7
7
 
8
- declare const patch: <T>(value: T, types?: SerializableTypes) => T;
8
+ declare const patch: (value: unknown, types?: SerializableTypes) => any;
9
+ declare const unpatch: (value: unknown, types?: SerializableTypes) => any;
9
10
 
10
11
  declare const parse: (json: string, types?: SerializableTypes) => any;
11
12
  type Reviver = (this: any, key: string, value: any) => any;
@@ -15,4 +16,4 @@ declare const stringify: (value: unknown, types?: SerializableTypes) => string;
15
16
  type Replacer = (this: any, key: string, value: any) => any;
16
17
  declare const createReplacer: (types?: SerializableTypes) => Replacer;
17
18
 
18
- export { type Serializable, createReplacer, createReviver, parse, patch, stringify };
19
+ export { type Serializable, createReplacer, createReviver, parse, patch, stringify, unpatch };
package/dist/index.js CHANGED
@@ -100,12 +100,16 @@ var createReplacer = (types = {}) => {
100
100
 
101
101
  // src/patch.ts
102
102
  var patch = (value, types = {}) => {
103
- return parse(stringify(value, types), types);
103
+ return parse(JSON.stringify(value), types);
104
+ };
105
+ var unpatch = (value, types = {}) => {
106
+ return JSON.parse(stringify(value, types));
104
107
  };
105
108
  export {
106
109
  createReplacer,
107
110
  createReviver,
108
111
  parse,
109
112
  patch,
110
- stringify
113
+ stringify,
114
+ unpatch
111
115
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@awsless/json",
3
- "version": "0.0.4",
3
+ "version": "0.0.5",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "keywords": [