@awsless/json 0.0.1 → 0.0.2

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
@@ -5,7 +5,13 @@ The `@awsless/json` package adds support for more JavaScript native types to JSO
5
5
 
6
6
  ## The Problem
7
7
 
8
- JSON doesn't have support for types like Date, BigInt, or BigFloat.
8
+ JSON doesn't have support for types like:
9
+ - Set
10
+ - Map
11
+ - Date
12
+ - BigInt
13
+ - BigFloat - npm @awsless/bit-float
14
+
9
15
  Having to decode & encode these type of values can get quite annoying.
10
16
 
11
17
  ## Basic Usage
@@ -36,7 +42,7 @@ class Custom {
36
42
  }
37
43
  }
38
44
 
39
- const $custom: Serializable<Custom> = {
45
+ const $custom: Serializable<Custom, string> = {
40
46
  is: v => v instanceof Custom,
41
47
  parse: v => new Custom(v),
42
48
  stringify: v => v.value,
package/dist/index.cjs CHANGED
@@ -26,26 +26,50 @@ __export(src_exports, {
26
26
  stringify: () => stringify
27
27
  });
28
28
  module.exports = __toCommonJS(src_exports);
29
+
30
+ // src/type/bigfloat.ts
29
31
  var import_big_float = require("@awsless/big-float");
30
32
  var $bigfloat = {
31
33
  is: (v) => v instanceof import_big_float.BigFloat,
32
34
  parse: (v) => new import_big_float.BigFloat(v),
33
35
  stringify: (v) => v.toString()
34
36
  };
37
+
38
+ // src/type/bigint.ts
35
39
  var $bigint = {
36
40
  is: (v) => typeof v === "bigint",
37
41
  parse: (v) => BigInt(v),
38
42
  stringify: (v) => v.toString()
39
43
  };
44
+
45
+ // src/type/date.ts
40
46
  var $date = {
41
47
  is: (v) => v instanceof Date,
42
48
  parse: (v) => new Date(v),
43
49
  stringify: (v) => v.toISOString()
44
50
  };
51
+
52
+ // src/type/map.ts
53
+ var $map = {
54
+ is: (v) => v instanceof Map,
55
+ parse: (v) => new Map(v),
56
+ stringify: (v) => Array.from(v)
57
+ };
58
+
59
+ // src/type/set.ts
60
+ var $set = {
61
+ is: (v) => v instanceof Set,
62
+ parse: (v) => new Set(v),
63
+ stringify: (v) => Array.from(v)
64
+ };
65
+
66
+ // src/index.ts
45
67
  var baseTypes = {
46
68
  $bigfloat,
47
69
  $bigint,
48
- $date
70
+ $date,
71
+ $set,
72
+ $map
49
73
  };
50
74
  var parse = (json, types = {}) => {
51
75
  return JSON.parse(json, createReviver(types));
package/dist/index.d.cts CHANGED
@@ -1,9 +1,9 @@
1
- type Serializable<T> = {
2
- is: (value: unknown) => boolean;
3
- parse: (value: string) => T;
4
- stringify: (value: T) => string;
1
+ type Serializable<I, O> = {
2
+ is: (value: unknown) => value is I;
3
+ parse: (value: O) => I;
4
+ stringify: (value: I) => O;
5
5
  };
6
- type SerializableTypes = Record<string, Serializable<any>>;
6
+ type SerializableTypes = Record<string, Serializable<any, any>>;
7
7
  declare const parse: (json: string, types?: SerializableTypes) => any;
8
8
  type Reviver = (this: any, key: string, value: any) => any;
9
9
  type Replacer = (this: any, key: string, value: any) => any;
package/dist/index.d.ts CHANGED
@@ -1,9 +1,9 @@
1
- type Serializable<T> = {
2
- is: (value: unknown) => boolean;
3
- parse: (value: string) => T;
4
- stringify: (value: T) => string;
1
+ type Serializable<I, O> = {
2
+ is: (value: unknown) => value is I;
3
+ parse: (value: O) => I;
4
+ stringify: (value: I) => O;
5
5
  };
6
- type SerializableTypes = Record<string, Serializable<any>>;
6
+ type SerializableTypes = Record<string, Serializable<any, any>>;
7
7
  declare const parse: (json: string, types?: SerializableTypes) => any;
8
8
  type Reviver = (this: any, key: string, value: any) => any;
9
9
  type Replacer = (this: any, key: string, value: any) => any;
package/dist/index.js CHANGED
@@ -1,24 +1,46 @@
1
- // src/index.ts
1
+ // src/type/bigfloat.ts
2
2
  import { BigFloat } from "@awsless/big-float";
3
3
  var $bigfloat = {
4
4
  is: (v) => v instanceof BigFloat,
5
5
  parse: (v) => new BigFloat(v),
6
6
  stringify: (v) => v.toString()
7
7
  };
8
+
9
+ // src/type/bigint.ts
8
10
  var $bigint = {
9
11
  is: (v) => typeof v === "bigint",
10
12
  parse: (v) => BigInt(v),
11
13
  stringify: (v) => v.toString()
12
14
  };
15
+
16
+ // src/type/date.ts
13
17
  var $date = {
14
18
  is: (v) => v instanceof Date,
15
19
  parse: (v) => new Date(v),
16
20
  stringify: (v) => v.toISOString()
17
21
  };
22
+
23
+ // src/type/map.ts
24
+ var $map = {
25
+ is: (v) => v instanceof Map,
26
+ parse: (v) => new Map(v),
27
+ stringify: (v) => Array.from(v)
28
+ };
29
+
30
+ // src/type/set.ts
31
+ var $set = {
32
+ is: (v) => v instanceof Set,
33
+ parse: (v) => new Set(v),
34
+ stringify: (v) => Array.from(v)
35
+ };
36
+
37
+ // src/index.ts
18
38
  var baseTypes = {
19
39
  $bigfloat,
20
40
  $bigint,
21
- $date
41
+ $date,
42
+ $set,
43
+ $map
22
44
  };
23
45
  var parse = (json, types = {}) => {
24
46
  return JSON.parse(json, createReviver(types));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@awsless/json",
3
- "version": "0.0.1",
3
+ "version": "0.0.2",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "repository": {