typeson-registry 1.0.0-alpha.7 → 2.0.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/{LICENSE → LICENSE-MIT.txt} +0 -0
- package/README.md +189 -77
- package/dist/index.js +1205 -0
- package/dist/index.js.map +1 -0
- package/dist/index.min.js +2 -0
- package/dist/index.min.js.map +1 -0
- package/dist/index.umd.js +2274 -0
- package/dist/index.umd.js.map +1 -0
- package/dist/index.umd.min.js +2 -0
- package/dist/index.umd.min.js.map +1 -0
- package/dist/presets/array-nonindex-keys.umd.js +2 -0
- package/dist/presets/array-nonindex-keys.umd.js.map +1 -0
- package/dist/presets/builtin.umd.js +2 -0
- package/dist/presets/builtin.umd.js.map +1 -0
- package/dist/presets/postmessage.umd.js +2 -0
- package/dist/presets/postmessage.umd.js.map +1 -0
- package/dist/presets/socketio.umd.js +2 -0
- package/dist/presets/socketio.umd.js.map +1 -0
- package/dist/presets/sparse-undefined.umd.js +2 -0
- package/dist/presets/sparse-undefined.umd.js.map +1 -0
- package/dist/presets/special-numbers.umd.js +2 -0
- package/dist/presets/special-numbers.umd.js.map +1 -0
- package/dist/presets/structured-cloning-throwing.umd.js +2 -0
- package/dist/presets/structured-cloning-throwing.umd.js.map +1 -0
- package/dist/presets/structured-cloning.umd.js +2 -0
- package/dist/presets/structured-cloning.umd.js.map +1 -0
- package/dist/presets/undef.umd.js +2 -0
- package/dist/presets/undef.umd.js.map +1 -0
- package/dist/presets/universal.umd.js +2 -0
- package/dist/presets/universal.umd.js.map +1 -0
- package/dist/types/arraybuffer.umd.js +2 -0
- package/dist/types/arraybuffer.umd.js.map +1 -0
- package/dist/types/bigint-object.umd.js +2 -0
- package/dist/types/bigint-object.umd.js.map +1 -0
- package/dist/types/bigint.umd.js +2 -0
- package/dist/types/bigint.umd.js.map +1 -0
- package/dist/types/blob.umd.js +2 -0
- package/dist/types/blob.umd.js.map +1 -0
- package/dist/types/cloneable.umd.js +2 -0
- package/dist/types/cloneable.umd.js.map +1 -0
- package/dist/types/cryptokey.umd.js +2 -0
- package/dist/types/cryptokey.umd.js.map +1 -0
- package/dist/types/dataview.umd.js +2 -0
- package/dist/types/dataview.umd.js.map +1 -0
- package/dist/types/date.umd.js +2 -0
- package/dist/types/date.umd.js.map +1 -0
- package/dist/types/error.umd.js +2 -0
- package/dist/types/error.umd.js.map +1 -0
- package/dist/types/errors.umd.js +2 -0
- package/dist/types/errors.umd.js.map +1 -0
- package/dist/types/file.umd.js +2 -0
- package/dist/types/file.umd.js.map +1 -0
- package/dist/types/filelist.umd.js +2 -0
- package/dist/types/filelist.umd.js.map +1 -0
- package/dist/types/imagebitmap.umd.js +2 -0
- package/dist/types/imagebitmap.umd.js.map +1 -0
- package/dist/types/imagedata.umd.js +2 -0
- package/dist/types/imagedata.umd.js.map +1 -0
- package/dist/types/infinity.umd.js +2 -0
- package/dist/types/infinity.umd.js.map +1 -0
- package/dist/types/intl-types.umd.js +2 -0
- package/dist/types/intl-types.umd.js.map +1 -0
- package/dist/types/map.umd.js +2 -0
- package/dist/types/map.umd.js.map +1 -0
- package/dist/types/nan.umd.js +2 -0
- package/dist/types/nan.umd.js.map +1 -0
- package/dist/types/negative-infinity.umd.js +2 -0
- package/dist/types/negative-infinity.umd.js.map +1 -0
- package/dist/types/nonbuiltin-ignore.umd.js +2 -0
- package/dist/types/nonbuiltin-ignore.umd.js.map +1 -0
- package/dist/types/primitive-objects.umd.js +2 -0
- package/dist/types/primitive-objects.umd.js.map +1 -0
- package/dist/types/regexp.umd.js +2 -0
- package/dist/types/regexp.umd.js.map +1 -0
- package/dist/types/resurrectable.umd.js +2 -0
- package/dist/types/resurrectable.umd.js.map +1 -0
- package/dist/types/set.umd.js +2 -0
- package/dist/types/set.umd.js.map +1 -0
- package/dist/types/typed-arrays-socketio.umd.js +2 -0
- package/dist/types/typed-arrays-socketio.umd.js.map +1 -0
- package/dist/types/typed-arrays.umd.js +2 -0
- package/dist/types/typed-arrays.umd.js.map +1 -0
- package/dist/types/undef.umd.js +2 -0
- package/dist/types/undef.umd.js.map +1 -0
- package/dist/types/user-object.umd.js +2 -0
- package/dist/types/user-object.umd.js.map +1 -0
- package/package.json +98 -27
- package/polyfills/createObjectURL.js +96 -0
- package/polyfills/createObjectURL.umd.js +2 -0
- package/polyfills/createObjectURL.umd.js.map +1 -0
- package/utils/generateUUID.js +29 -0
- package/utils/stringArrayBuffer.js +72 -0
- package/CHANGES +0 -126
- package/browser-test/index.html +0 -30
- package/browser-test/testLoading.js +0 -57
- package/browser-test/worker.html +0 -31
- package/browser-test/worker.js +0 -16
- package/build.js +0 -99
- package/dist/all.js +0 -126
- package/dist/all.js.map +0 -89
- package/dist/presets/builtin.js +0 -78
- package/dist/presets/builtin.js.map +0 -59
- package/dist/presets/post-message.js +0 -21
- package/dist/presets/post-message.js.map +0 -23
- package/dist/presets/socketio.js +0 -87
- package/dist/presets/socketio.js.map +0 -63
- package/dist/presets/sparse-undefined.js +0 -12
- package/dist/presets/sparse-undefined.js.map +0 -19
- package/dist/presets/special-numbers.js +0 -21
- package/dist/presets/special-numbers.js.map +0 -25
- package/dist/presets/structured-cloning-throwing.js +0 -90
- package/dist/presets/structured-cloning-throwing.js.map +0 -69
- package/dist/presets/structured-cloning.js +0 -87
- package/dist/presets/structured-cloning.js.map +0 -67
- package/dist/presets/undefined.js +0 -18
- package/dist/presets/undefined.js.map +0 -23
- package/dist/presets/universal.js +0 -81
- package/dist/presets/universal.js.map +0 -61
- package/dist/types/Infinity.js +0 -12
- package/dist/types/Infinity.js.map +0 -19
- package/dist/types/NaN.js +0 -12
- package/dist/types/NaN.js.map +0 -19
- package/dist/types/NegativeInfinity.js +0 -12
- package/dist/types/NegativeInfinity.js.map +0 -19
- package/dist/types/arraybuffer.js +0 -15
- package/dist/types/arraybuffer.js.map +0 -21
- package/dist/types/blob.js +0 -12
- package/dist/types/blob.js.map +0 -19
- package/dist/types/cloneable.js +0 -12
- package/dist/types/cloneable.js.map +0 -19
- package/dist/types/dataview.js +0 -15
- package/dist/types/dataview.js.map +0 -21
- package/dist/types/date.js +0 -12
- package/dist/types/date.js.map +0 -19
- package/dist/types/error.js +0 -12
- package/dist/types/error.js.map +0 -19
- package/dist/types/errors.js +0 -15
- package/dist/types/errors.js.map +0 -19
- package/dist/types/file.js +0 -12
- package/dist/types/file.js.map +0 -19
- package/dist/types/filelist.js +0 -15
- package/dist/types/filelist.js.map +0 -21
- package/dist/types/imagebitmap.js +0 -12
- package/dist/types/imagebitmap.js.map +0 -19
- package/dist/types/imagedata.js +0 -12
- package/dist/types/imagedata.js.map +0 -19
- package/dist/types/intl-types.js +0 -12
- package/dist/types/intl-types.js.map +0 -19
- package/dist/types/map.js +0 -15
- package/dist/types/map.js.map +0 -21
- package/dist/types/nonbuiltin-ignore.js +0 -12
- package/dist/types/nonbuiltin-ignore.js.map +0 -19
- package/dist/types/primitive-objects.js +0 -12
- package/dist/types/primitive-objects.js.map +0 -19
- package/dist/types/regexp.js +0 -12
- package/dist/types/regexp.js.map +0 -19
- package/dist/types/resurrectable.js +0 -12
- package/dist/types/resurrectable.js.map +0 -19
- package/dist/types/set.js +0 -15
- package/dist/types/set.js.map +0 -21
- package/dist/types/special-numbers.js +0 -12
- package/dist/types/special-numbers.js.map +0 -19
- package/dist/types/typed-arrays-socketio.js +0 -15
- package/dist/types/typed-arrays-socketio.js.map +0 -19
- package/dist/types/typed-arrays.js +0 -18
- package/dist/types/typed-arrays.js.map +0 -21
- package/dist/types/undefined.js +0 -12
- package/dist/types/undefined.js.map +0 -19
- package/dist/types/user-object.js +0 -12
- package/dist/types/user-object.js.map +0 -19
- package/index.js +0 -39
- package/presets/builtin.js +0 -24
- package/presets/post-message.js +0 -15
- package/presets/socketio.js +0 -5
- package/presets/sparse-undefined.js +0 -19
- package/presets/special-numbers.js +0 -5
- package/presets/structured-cloning-throwing.js +0 -32
- package/presets/structured-cloning.js +0 -24
- package/presets/undefined.js +0 -4
- package/presets/universal.js +0 -4
- package/server.js +0 -10
- package/test/Flag_of_the_United_Nations.png +0 -0
- package/test/createObjectURL.js +0 -28
- package/test/test-entry.js +0 -49
- package/test/test-environment.js +0 -119
- package/test/test-node.js +0 -56
- package/test/test-utils.js +0 -38
- package/test/test.js +0 -885
- package/types/Infinity.js +0 -5
- package/types/NaN.js +0 -5
- package/types/NegativeInfinity.js +0 -5
- package/types/arraybuffer.js +0 -9
- package/types/blob.js +0 -36
- package/types/cloneable.js +0 -30
- package/types/dataview.js +0 -7
- package/types/date.js +0 -17
- package/types/error.js +0 -11
- package/types/errors.js +0 -20
- package/types/file.js +0 -41
- package/types/filelist.js +0 -23
- package/types/imagebitmap.js +0 -49
- package/types/imagedata.js +0 -14
- package/types/intl-types.js +0 -18
- package/types/map.js +0 -7
- package/types/nonbuiltin-ignore.js +0 -16
- package/types/primitive-objects.js +0 -23
- package/types/regexp.js +0 -11
- package/types/resurrectable.js +0 -28
- package/types/set.js +0 -7
- package/types/typed-arrays-socketio.js +0 -32
- package/types/typed-arrays.js +0 -23
- package/types/undefined.js +0 -9
- package/types/user-object.js +0 -6
- package/utils/array-from-iterator.js +0 -7
- package/windows-devinstall.js +0 -41
|
File without changes
|
package/README.md
CHANGED
|
@@ -1,43 +1,91 @@
|
|
|
1
1
|
# typeson-registry
|
|
2
2
|
|
|
3
|
-
The type registry for [typeson](https://github.com/dfahlander/typeson)
|
|
3
|
+
The type registry for [typeson](https://github.com/dfahlander/typeson).
|
|
4
4
|
|
|
5
|
-
- Types listed under
|
|
6
|
-
|
|
5
|
+
- Types listed under
|
|
6
|
+
[types](https://github.com/dfahlander/typeson-registry/tree/master/types)
|
|
7
|
+
- Presets listed under
|
|
8
|
+
[presets](https://github.com/dfahlander/typeson-registry/tree/master/presets)
|
|
7
9
|
|
|
8
10
|
See below for notes on these types and presets.
|
|
9
11
|
|
|
10
|
-
Note that some types will require polyfills in Node such as via
|
|
12
|
+
Note that some types will require polyfills in Node such as via
|
|
13
|
+
[`jsdom`](https://github.com/jsdom/jsdom).
|
|
11
14
|
See the testing environment of `test/test.js` for some examples.
|
|
12
15
|
|
|
13
16
|
## Installation
|
|
14
17
|
|
|
15
|
-
|
|
16
|
-
|
|
18
|
+
Note that for Node.js, to use the `file` or `blob` types (or the `filelist`
|
|
19
|
+
type or `structuredCloning` and `structuredCloningThrowing` presets which
|
|
20
|
+
include them), you will need a polyfill for `Blob` or `File`, respectively,
|
|
21
|
+
as well as `FileReader` and `URL.createObjectURL` (and a
|
|
22
|
+
polyfill for `URL` if you are using Node < 10.0.0 or an older browser).
|
|
23
|
+
Note that our `URL.createObjectURL` polyfill expects a global
|
|
24
|
+
`XMLHttpRequest` and `location.href` predefined before it as well (and one
|
|
25
|
+
which can handle `data:` URLs). For Node, you can add it like this:
|
|
17
26
|
|
|
18
|
-
|
|
27
|
+
```js
|
|
28
|
+
const url = require('url'); // This line only needed to support Node < 10.0.0
|
|
29
|
+
const {createObjectURL} = require('typeson-registry/polyfills/createObjectURL.umd.js');
|
|
30
|
+
|
|
31
|
+
const URL = url.Url; // This line only needed to support Node < 10.0.0
|
|
32
|
+
URL.createObjectURL = createObjectURL;
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
We have not added `jsdom` as a dependency, but it is required if this
|
|
36
|
+
polyfill is used.
|
|
37
|
+
|
|
38
|
+
Besides the polyfills for `file` or `blob`, the `structuredCloningThrowing`
|
|
39
|
+
preset also needs a global `DOMException` polyfill.
|
|
40
|
+
|
|
41
|
+
The `filelist` type, in addition to the polyfills for `file`, will need
|
|
42
|
+
a `FileList` polyfill (including a `FileList` string tag).
|
|
43
|
+
|
|
44
|
+
The `imagebitmap` type requires a global `createImageBitmap` polyfill (and
|
|
45
|
+
an `ImageBitmap` polyfill (including an `ImageBitmap` string tag).
|
|
46
|
+
|
|
47
|
+
The `imagedata` type requires a global `ImageData` polyfill (including an
|
|
48
|
+
`ImageData` string tag).
|
|
49
|
+
|
|
50
|
+
You may wish to see our `test-node.js` and `test-environment.js` files
|
|
51
|
+
for how some polyfilling may be done (largely using `jsdom`).
|
|
52
|
+
|
|
53
|
+
The `cloneable` and `resurrectable` types (and the `createObjectURL`
|
|
54
|
+
polyill) each accept an optional global `performance` polyfill (through
|
|
55
|
+
the common file `utils/generateUUID.js`).
|
|
56
|
+
|
|
57
|
+
### Building files from Git clone (as opposed to npm installs)
|
|
58
|
+
|
|
59
|
+
If you have cloned the repo (and not the npm package), you must run
|
|
60
|
+
`npm install` to get the `devDependencies` and then run
|
|
61
|
+
`npm run rollup` to get the individual browser scripts built locally
|
|
62
|
+
(into `dist`) or to get `index.js` to be rebuilt based on existing
|
|
63
|
+
presets and types).
|
|
64
|
+
|
|
65
|
+
## Usage (Pre-rollup in Node or browser)
|
|
19
66
|
|
|
20
67
|
```js
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
68
|
+
import {Typeson, date, error, regexp, typedArrays} from 'typeson-registry';
|
|
69
|
+
|
|
70
|
+
const TSON = new Typeson().register([
|
|
71
|
+
date,
|
|
72
|
+
error,
|
|
73
|
+
regexp,
|
|
74
|
+
typedArrays
|
|
27
75
|
// ...
|
|
28
76
|
]);
|
|
29
77
|
|
|
30
|
-
|
|
31
|
-
Hello:
|
|
78
|
+
const tson = TSON.stringify({
|
|
79
|
+
Hello: 'world',
|
|
32
80
|
date: new Date(),
|
|
33
|
-
error: new Error(),
|
|
81
|
+
error: new Error('test'),
|
|
34
82
|
inner: {
|
|
35
|
-
x: /foo/
|
|
83
|
+
x: /foo/gui,
|
|
36
84
|
bin: new Uint8Array(64)
|
|
37
85
|
}
|
|
38
86
|
}, null, 2);
|
|
39
87
|
|
|
40
|
-
console.log(tson);
|
|
88
|
+
console.log(tson);
|
|
41
89
|
/* Output:
|
|
42
90
|
|
|
43
91
|
{
|
|
@@ -45,7 +93,7 @@ console.log(tson);
|
|
|
45
93
|
"date": 1464049031538,
|
|
46
94
|
"error": {
|
|
47
95
|
"name": "Error",
|
|
48
|
-
"message": ""
|
|
96
|
+
"message": "test"
|
|
49
97
|
},
|
|
50
98
|
"inner": {
|
|
51
99
|
"x": {
|
|
@@ -63,37 +111,60 @@ console.log(tson);
|
|
|
63
111
|
}
|
|
64
112
|
*/
|
|
65
113
|
|
|
66
|
-
|
|
114
|
+
const parsedBack = TSON.parse(tson);
|
|
67
115
|
|
|
68
|
-
|
|
69
|
-
|
|
116
|
+
console.log(parsedBack.date instanceof Date);
|
|
117
|
+
console.log(parsedBack.inner.bin instanceof Uint8Array);
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
## Usage (Node without own Rollup)
|
|
121
|
+
|
|
122
|
+
```js
|
|
123
|
+
const {Typeson, builtin} = require('typeson-registry');
|
|
124
|
+
|
|
125
|
+
const tson = new Typeson().register([
|
|
126
|
+
builtin
|
|
127
|
+
]);
|
|
128
|
+
```
|
|
70
129
|
|
|
130
|
+
## Usage (`import` in supporting browsers without own Rollup)
|
|
131
|
+
|
|
132
|
+
```html
|
|
133
|
+
<script type="module">
|
|
134
|
+
|
|
135
|
+
import {Typeson, builtin} from './node_modules/typeson-registry/dist/index.js';
|
|
136
|
+
|
|
137
|
+
const TSON = new Typeson().register([
|
|
138
|
+
builtin
|
|
139
|
+
]);
|
|
140
|
+
</script>
|
|
71
141
|
```
|
|
72
142
|
|
|
73
|
-
## Usage (with plain script tags)
|
|
143
|
+
## Usage (with plain script tags without own Rollup)
|
|
74
144
|
|
|
75
|
-
All types and presets under dist are UMD modules so you could also
|
|
145
|
+
All types and presets under `dist/` are UMD modules so you could also
|
|
146
|
+
require them as AMD modules with requirejs if you prefer.
|
|
76
147
|
|
|
77
148
|
```html
|
|
78
149
|
<!DOCTYPE html>
|
|
79
150
|
<html>
|
|
80
151
|
<head>
|
|
81
|
-
<script src="https://unpkg.com/typeson/dist/typeson.js"></script>
|
|
82
|
-
<script src="https://unpkg.com/typeson-registry/dist/presets/builtin.js"></script>
|
|
152
|
+
<script src="https://unpkg.com/typeson/dist/typeson.umd.min.js"></script>
|
|
153
|
+
<script src="https://unpkg.com/typeson-registry/dist/presets/builtin.umd.js"></script>
|
|
83
154
|
<script>
|
|
84
155
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
Hello:
|
|
156
|
+
const TSON = new Typeson().register(builtin);
|
|
157
|
+
const tson = TSON.stringify({
|
|
158
|
+
Hello: 'world',
|
|
88
159
|
date: new Date(),
|
|
89
|
-
error: new Error(),
|
|
160
|
+
error: new Error('err'),
|
|
90
161
|
inner: {
|
|
91
|
-
x: /foo/
|
|
162
|
+
x: /foo/giu,
|
|
92
163
|
bin: new Uint8Array(64)
|
|
93
164
|
}
|
|
94
165
|
}, null, 2);
|
|
95
166
|
|
|
96
|
-
alert(tson);
|
|
167
|
+
alert(tson);
|
|
97
168
|
/* Alerts:
|
|
98
169
|
|
|
99
170
|
{
|
|
@@ -101,7 +172,7 @@ All types and presets under dist are UMD modules so you could also require them
|
|
|
101
172
|
"date": 1464049031538,
|
|
102
173
|
"error": {
|
|
103
174
|
"name": "Error",
|
|
104
|
-
"message": ""
|
|
175
|
+
"message": "err"
|
|
105
176
|
},
|
|
106
177
|
"inner": {
|
|
107
178
|
"x": {
|
|
@@ -126,101 +197,142 @@ All types and presets under dist are UMD modules so you could also require them
|
|
|
126
197
|
|
|
127
198
|
## Notes on types and presets
|
|
128
199
|
|
|
200
|
+
Note that the type name corresponds to the file name in the following manner:
|
|
201
|
+
|
|
202
|
+
1. Genuine separate words are camel-cased in the type name but hyphenated in
|
|
203
|
+
the file name (e.g., `negativeInfinity` and `negativity-infinity.js`);
|
|
204
|
+
names whose original API is camel-cased are not hyphenated, however
|
|
205
|
+
(e.g., `arraybuffer` and `arraybuffer.js` given `ArrayBuffer`).
|
|
206
|
+
1. All other portions of names are lower-cased (e.g., `date` and `date.js`).
|
|
207
|
+
1. Type names that would clash with existing objects when exported (even after
|
|
208
|
+
lower-casing) must have a separate, preferably abbreviated form (e.g.,
|
|
209
|
+
the type and preset `undef` and `undef.js` was necessary for `undefined`)
|
|
210
|
+
1. Type names which are not allowed as ES6 exports (e.g., periods in `Intl`
|
|
211
|
+
types are now removed: `Intl.Collator` -> `IntlCollator`)
|
|
212
|
+
1. Type names should indicate the singular (e.g., `userObject`) except for
|
|
213
|
+
files containing multiple related exports (e.g., `errors`, `typed-arrays`,
|
|
214
|
+
and `typed-arrays-socketio.js`); files with multiple exports whose extra
|
|
215
|
+
exports are incidental (e.g., `filelist`) do not need a plural.
|
|
216
|
+
|
|
129
217
|
### Types
|
|
130
218
|
|
|
131
|
-
- `
|
|
132
|
-
- `
|
|
219
|
+
- `arraybuffer`
|
|
220
|
+
- `bigintObject`
|
|
221
|
+
- `bigint`
|
|
222
|
+
- `blob` - Has sync and async encapsulation/replacements (though sync only
|
|
133
223
|
via deprecated means)
|
|
134
|
-
- `cloneable` - Looks for `
|
|
224
|
+
- `cloneable` - Looks for `Symbol.for('cloneEncapsulate')` and
|
|
225
|
+
`Symbol.for('cloneRevive')` methods to allow
|
|
135
226
|
for a means of extending our built-in structured cloning presets (though if
|
|
136
227
|
you are polyfilling a standard object, we welcome you to submit back as a
|
|
137
|
-
PR!). The clones cannot be revived past the current window session,
|
|
138
|
-
|
|
139
|
-
- `
|
|
228
|
+
PR!). The clones cannot be revived past the current window session,
|
|
229
|
+
however.
|
|
230
|
+
- `dataview`
|
|
231
|
+
- `date`
|
|
140
232
|
- `error.js` (`Error`) and `errors.js` (`TypeError`, `RangeError`, `SyntaxError`, `ReferenceError`, `EvalError`, `URIError`, `InternalError`) - These
|
|
141
233
|
provide a means of resurrecting error object across cloning boundaries
|
|
142
234
|
(since they are not otherwise treated as cloneable by the Structured
|
|
143
235
|
Cloning Algorithm).
|
|
144
|
-
- `
|
|
236
|
+
- `file` - Has sync and async encapsulation/replacements (though sync only
|
|
145
237
|
via deprecated means)
|
|
146
|
-
- `
|
|
238
|
+
- `filelist` - HTML does not provide a means of creating a `FileList` object
|
|
147
239
|
dynamically, so we polyfill one for revival. This method also sets `File`
|
|
148
|
-
- `
|
|
240
|
+
- `imagebitmap` - Has sync and async revivers. The sync method does not produce
|
|
149
241
|
a genuine `ImageBitmap` but instead produces a canvas element which can
|
|
150
242
|
frequently be used in a similar context to `ImageBitmap`.
|
|
151
|
-
- `
|
|
152
|
-
- `
|
|
243
|
+
- `imagedata`
|
|
244
|
+
- `infinity` - Preserves positive infinity
|
|
153
245
|
- `intl-types.js` (`Intl.Collator`, `Intl.DateTimeFormat`, `Intl.NumberFormat`) -
|
|
154
246
|
Not all properties can be preserved
|
|
155
|
-
- `
|
|
156
|
-
- `
|
|
247
|
+
- `map`
|
|
248
|
+
- `nan` - Preserves `NaN` (not a number)
|
|
157
249
|
- `NegativeInfinity` - Preserves negative infinity
|
|
158
250
|
- `nonBuiltInIgnore` - For roughly detecting non-builtin objects and to avoid
|
|
159
251
|
adding them as properties
|
|
160
252
|
- `primitive-objects.js` (`StringObject`, `BooleanObject`, `NumberObject`)
|
|
161
|
-
- `
|
|
253
|
+
- `regexp`
|
|
162
254
|
- `resurrectable` - Resurrects any non-array object, function, or symbol; can
|
|
163
255
|
only be revived for the current window session.
|
|
164
|
-
- `
|
|
165
|
-
- `typed-arrays-socketio.js` (`Int8Array`, `Uint8Array`, `Uint8ClampedArray`,
|
|
166
|
-
|
|
167
|
-
|
|
256
|
+
- `set`
|
|
257
|
+
- `typed-arrays-socketio.js` (`Int8Array`, `Uint8Array`, `Uint8ClampedArray`,
|
|
258
|
+
`Int16Array`, `Uint16Array`, `Int32Array`, `Uint32Array`, `Float32Array`,
|
|
259
|
+
`Float64Array`) - See
|
|
260
|
+
[typeson#environmentformat-support](https://github.com/dfahlander/typeson#environmentformat-support)
|
|
261
|
+
and `presets/socketio.js`
|
|
262
|
+
- `typed-arrays.js` (`Int8Array`, `Uint8Array`, `Uint8ClampedArray`,
|
|
263
|
+
`Int16Array`, `Uint16Array`, `Int32Array`, `Uint32Array`,
|
|
264
|
+
`Float32Array`, `Float64Array`) - Base64-encodes
|
|
265
|
+
- `undef` (for `undefined`) (See also `presets/undefined.js` and
|
|
266
|
+
`presets/sparse-undefined.js`)
|
|
168
267
|
- `userObjects` - Allows for inherited objects but ensures the prototype chain
|
|
169
|
-
inherits from `Object` (or `null`). Should be low priority if one is
|
|
170
|
-
other objects as it will readily match many objects.
|
|
268
|
+
inherits from `Object` (or `null`). Should be low priority if one is
|
|
269
|
+
matching other objects as it will readily match many objects.
|
|
171
270
|
|
|
172
271
|
### Presets
|
|
173
272
|
|
|
174
|
-
- `
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
273
|
+
- `array-nonindex-keys.js`
|
|
274
|
+
- `builtin.js` - Types that are built into the JavaScript language itself.
|
|
275
|
+
Types that were added in ES6 or beyond will be checked before inclusion
|
|
276
|
+
so that this module can be consumed by both ES5 and ES6 environments.
|
|
277
|
+
Some imperfectly serializable objects (such as functions and Symbols)
|
|
278
|
+
are not included in this preset.
|
|
279
|
+
- `postmessage.js` - This preset is intended as a utility to expand on what is
|
|
180
280
|
cloneable via `strcutured-cloning.js` and supports Error objects.
|
|
281
|
+
- `socketio.js`
|
|
181
282
|
- `sparse-undefined.js` (`sparseArrays` and `sparseUndefined`) - Supports
|
|
182
283
|
reconstructing sparse arrays (with missing properties not even assigned
|
|
183
|
-
an explicit `undefined`). See `types/undefined.js` for the explicit case
|
|
284
|
+
an explicit `undefined`). See `types/undefined.js` for the explicit case
|
|
285
|
+
or `presets/undefined.js` for a utility combining both.
|
|
184
286
|
- `special-numbers.js` (preserves `NaN`, `Infinity`, `-Infinity`)
|
|
185
|
-
- `structured-cloning.js` - For the Structured Cloning Algorithm used by the
|
|
186
|
-
|
|
187
|
-
- `
|
|
188
|
-
|
|
287
|
+
- `structured-cloning.js` - For the Structured Cloning Algorithm used by the
|
|
288
|
+
likes of `postMessage` and `indexedDB`. See also the `cloneable` type.
|
|
289
|
+
- `structured-cloning-throwing.js` - Same as `structured-cloning.js` but
|
|
290
|
+
throws with non-recognized types. See also the `cloneable` type.
|
|
291
|
+
- `undef.js` - Supports reconstructing explicit and implicit (sparse)
|
|
292
|
+
uses of `undefined`.
|
|
293
|
+
- `universal.js`- Meant for de-facto universal types. Currently includes
|
|
294
|
+
built-ins only.
|
|
189
295
|
|
|
190
296
|
### Functions (support not included)
|
|
191
297
|
|
|
192
298
|
If you are looking for a way to resurrect functions, you can use the following,
|
|
193
299
|
but please bear in mind that it uses `eval` which is prohibited by some
|
|
194
300
|
Content Security Policies (CSP) (so we are not packaging it with our builds),
|
|
195
|
-
that it is unsafe, and also that the function might not behave
|
|
196
|
-
when revived (e.g., if the function were provided from
|
|
301
|
+
that it is unsafe, and also that the function might not behave
|
|
302
|
+
deterministically when revived (e.g., if the function were provided from
|
|
303
|
+
another context).
|
|
197
304
|
|
|
198
305
|
```js
|
|
199
|
-
|
|
306
|
+
const functionType = {functionType: [
|
|
200
307
|
function (x) { return typeof x === 'function'; },
|
|
201
|
-
function (
|
|
308
|
+
function (funcType) { return '(' + funcType.toString() + ')'; },
|
|
309
|
+
// eslint-disable-next-line no-eval
|
|
202
310
|
function (o) { return eval(o); }
|
|
203
311
|
]};
|
|
204
312
|
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
back() // 'abc'
|
|
313
|
+
const typeson = new Typeson().register(functionType);
|
|
314
|
+
const tson = typeson.stringify(function () { return 'abc'; });
|
|
315
|
+
const back = typeson.parse(tson);
|
|
316
|
+
back(); // 'abc'
|
|
209
317
|
```
|
|
210
318
|
|
|
211
319
|
## Development
|
|
212
320
|
|
|
213
|
-
[node-canvas](https://github.com/Automattic/node-canvas) is used to test
|
|
321
|
+
[node-canvas](https://github.com/Automattic/node-canvas) is used to test
|
|
322
|
+
`ImageData`.
|
|
323
|
+
|
|
214
324
|
Be sure to follow the installation steps.
|
|
215
325
|
|
|
216
|
-
On Windows, besides following the
|
|
326
|
+
On Windows, besides following the
|
|
327
|
+
[Windows installation steps](https://github.com/Automattic/node-canvas/wiki/Installation---Windows),
|
|
328
|
+
[this](https://github.com/nodejs/node-gyp/issues/94#issuecomment-278587021)
|
|
217
329
|
helped complete the installation. If you need to have it rebuilt, you can
|
|
218
330
|
run `npm i` inside of the `node_modules/canvas` directory.
|
|
219
331
|
|
|
220
332
|
[These steps](https://github.com/Automattic/node-canvas/issues/191#issuecomment-7681555)
|
|
221
|
-
were also necessary but you can run `npm run windows` after install to get
|
|
222
|
-
applied. These are the only steps which should need to be re-run
|
|
223
|
-
your local `node-canvas` copy.
|
|
333
|
+
were also necessary but you can run `npm run windows` after install to get
|
|
334
|
+
these steps applied. These are the only steps which should need to be re-run
|
|
335
|
+
if you have deleted your local `node-canvas` copy.
|
|
224
336
|
|
|
225
337
|
## See also
|
|
226
338
|
|