ig-serialize 1.1.0 → 1.2.0
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 +25 -0
- package/package.json +2 -2
- package/serialize.js +13 -7
package/README.md
CHANGED
|
@@ -7,6 +7,9 @@ This extends the default JSON serialization adding the following:
|
|
|
7
7
|
- Function serialization (off by default)
|
|
8
8
|
- Deep and partial-deep cleen object copy
|
|
9
9
|
|
|
10
|
+
Possible differences to JSON output:
|
|
11
|
+
- Repeating long strings and BigInts can be referenced instead of
|
|
12
|
+
reincluded in the output.
|
|
10
13
|
|
|
11
14
|
|
|
12
15
|
## Motivation
|
|
@@ -20,6 +23,13 @@ and tooling design, basic parsing, among others.
|
|
|
20
23
|
|
|
21
24
|
## Installation
|
|
22
25
|
|
|
26
|
+
```shell
|
|
27
|
+
$ npm install ig-serilaize
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
Or just download and drop [serialize.js](serialize.js) into your code.
|
|
31
|
+
|
|
32
|
+
|
|
23
33
|
|
|
24
34
|
## Introduction
|
|
25
35
|
|
|
@@ -38,6 +48,7 @@ loosing:
|
|
|
38
48
|
Thus, care must be taken when serializing structures containing function.
|
|
39
49
|
|
|
40
50
|
|
|
51
|
+
|
|
41
52
|
## API
|
|
42
53
|
|
|
43
54
|
### `serialize(..)` / `eJSON.stringify(..)`
|
|
@@ -49,6 +60,20 @@ Thus, care must be taken when serializing structures containing function.
|
|
|
49
60
|
### `partialDeepCopy(..)`
|
|
50
61
|
|
|
51
62
|
|
|
63
|
+
### `MIN_LENGTH_REF` / `<options>.min_length_ref`
|
|
64
|
+
|
|
65
|
+
Defines the default minimum length of repeating string or bin-int to
|
|
66
|
+
include as a reference in the output.
|
|
67
|
+
|
|
68
|
+
If set to `0`, referencing will be disabled.
|
|
69
|
+
|
|
70
|
+
Default: 96
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
### `DEBUG`
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
|
|
52
77
|
## Format
|
|
53
78
|
|
|
54
79
|
The output of `.serialize(..)` is a strict superset of [standard JSON](https://www.json.org/json-en.html),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ig-serialize",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"description": "experimental extended json serializaion...",
|
|
5
5
|
"main": "serialize.js",
|
|
6
6
|
"scripts": {
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
},
|
|
11
11
|
"repository": {
|
|
12
12
|
"type": "git",
|
|
13
|
-
"url": "git+https://github.com/flynx/serialize.js"
|
|
13
|
+
"url": "git+https://github.com/flynx/serialize.js.git"
|
|
14
14
|
},
|
|
15
15
|
"keywords": [
|
|
16
16
|
"JSON",
|
package/serialize.js
CHANGED
|
@@ -77,7 +77,7 @@ var debug = {
|
|
|
77
77
|
|
|
78
78
|
//---------------------------------------------------------------------
|
|
79
79
|
|
|
80
|
-
module.
|
|
80
|
+
module.MIN_LENGTH_REF = REFERENCE.length * 16
|
|
81
81
|
|
|
82
82
|
|
|
83
83
|
//
|
|
@@ -144,9 +144,13 @@ module.STRING_LENGTH_REF = REFERENCE.length * 8
|
|
|
144
144
|
var _serialize =
|
|
145
145
|
module._serialize =
|
|
146
146
|
function(obj, path=[], seen=new Map(), indent, depth=0, options={}){
|
|
147
|
-
var
|
|
148
|
-
options.
|
|
149
|
-
?? module.
|
|
147
|
+
var min_length_ref =
|
|
148
|
+
options.min_length_ref
|
|
149
|
+
?? module.MIN_LENGTH_REF
|
|
150
|
+
min_length_ref =
|
|
151
|
+
min_length_ref <= 0 ?
|
|
152
|
+
Infinity
|
|
153
|
+
: min_length_ref
|
|
150
154
|
|
|
151
155
|
// reference...
|
|
152
156
|
var p = seen.get(obj)
|
|
@@ -171,12 +175,14 @@ function(obj, path=[], seen=new Map(), indent, depth=0, options={}){
|
|
|
171
175
|
// long strings...
|
|
172
176
|
// NOTE: this saves on output size...
|
|
173
177
|
if(typeof(obj) == 'string'
|
|
174
|
-
&& obj.length >
|
|
178
|
+
&& obj.length > min_length_ref){
|
|
175
179
|
seen.set(obj, path) }
|
|
176
180
|
// BigInt...
|
|
177
181
|
if(typeof(obj) == 'bigint'){
|
|
178
|
-
|
|
179
|
-
|
|
182
|
+
var res = obj.toString() +'n'
|
|
183
|
+
if(res.length > min_length_ref){
|
|
184
|
+
seen.set(obj, path) }
|
|
185
|
+
return res }
|
|
180
186
|
|
|
181
187
|
// atomics...
|
|
182
188
|
// NOTE: these are not stored in seen thus are not re-referenced...
|