@cloudpss/yaml 0.5.38 → 0.5.40

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/dist/index.d.ts CHANGED
@@ -4,3 +4,4 @@ export declare function load(str: string, opts?: LoadOptions): unknown;
4
4
  /** 序列化为 YAML */
5
5
  export declare function dump(obj: unknown, opts?: DumpOptions): string;
6
6
  export type { LoadOptions, DumpOptions } from 'js-yaml';
7
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAIxD,cAAc;AACd,wBAAgB,IAAI,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,WAAW,GAAG,OAAO,CAK7D;AACD,gBAAgB;AAChB,wBAAgB,IAAI,CAAC,GAAG,EAAE,OAAO,EAAE,IAAI,CAAC,EAAE,WAAW,GAAG,MAAM,CAyB7D;AACD,YAAY,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC"}
package/dist/schema.d.ts CHANGED
@@ -1 +1,2 @@
1
- export const CLOUDPSS_SCHEMA: import("js-yaml").Schema;
1
+ export declare const CLOUDPSS_SCHEMA: import("js-yaml").Schema;
2
+ //# sourceMappingURL=schema.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../src/schema.ts"],"names":[],"mappings":"AAuFA,eAAO,MAAM,eAAe,0BAEiB,CAAC"}
package/dist/schema.js CHANGED
@@ -2,8 +2,6 @@ import { Type, DEFAULT_SCHEMA, CORE_SCHEMA } from 'js-yaml';
2
2
  import { toUint8Array, fromUint8Array } from 'js-base64';
3
3
  /**
4
4
  * Check if data is base64 encoded
5
- * @param {unknown} data
6
- * @returns {data is string}
7
5
  */
8
6
  function isBase64(data) {
9
7
  if (typeof data !== 'string')
@@ -13,11 +11,11 @@ function isBase64(data) {
13
11
  const buffer = new Type('tag:yaml.org,2002:js/ArrayBuffer', {
14
12
  kind: 'scalar',
15
13
  resolve: isBase64,
16
- construct: (/** @type {string} */ data) => toUint8Array(data || '').buffer,
14
+ construct: (data) => toUint8Array(data || '').buffer,
17
15
  instanceOf: ArrayBuffer,
18
16
  represent: (object) => fromUint8Array(new Uint8Array(object)),
19
17
  });
20
- const typedArrays = [
18
+ const TYPED_ARRAY = [
21
19
  Float32Array,
22
20
  Float64Array,
23
21
  Uint8Array,
@@ -27,17 +25,17 @@ const typedArrays = [
27
25
  Int8Array,
28
26
  Int16Array,
29
27
  Int32Array,
30
- ].flatMap((c) => {
28
+ ];
29
+ const typedArrays = TYPED_ARRAY.flatMap((c) => {
31
30
  const yamlType = `tag:yaml.org,2002:js/${c.name}`;
32
- /** @type {import('js-yaml').TypeConstructorOptions} */
33
31
  const commonInit = {
34
- resolve: (/** @type {string | number[]} */ data) => {
35
- if (Array.isArray(data)) {
32
+ resolve: (data) => {
33
+ if (Array.isArray(data) && (data.length === 0 || typeof data[0] == 'number')) {
36
34
  return true;
37
35
  }
38
36
  return isBase64(data);
39
37
  },
40
- construct: (/** @type {string | number[]} */ data) => {
38
+ construct: (data) => {
41
39
  if (Array.isArray(data)) {
42
40
  return c.from(data);
43
41
  }
@@ -47,13 +45,12 @@ const typedArrays = [
47
45
  instanceOf: c,
48
46
  defaultStyle: 'base64',
49
47
  represent: {
50
- base64: (
51
- /** @type {Float32Array|Float64Array|Uint8ClampedArray|Uint16Array|Uint32Array|Int8Array|Int16Array|Int32Array} */ object) => {
52
- const buf = new Uint8Array(object.buffer, object.byteOffset, object.byteLength);
48
+ base64: (object) => {
49
+ const av = object;
50
+ const buf = new Uint8Array(av.buffer, av.byteOffset, av.byteLength);
53
51
  return fromUint8Array(buf);
54
52
  },
55
- sequence: (
56
- /** @type {Float32Array|Float64Array|Uint8ClampedArray|Uint16Array|Uint32Array|Int8Array|Int16Array|Int32Array} */ object) => {
53
+ sequence: (object) => {
57
54
  return [...object];
58
55
  },
59
56
  },
@@ -71,15 +68,15 @@ const typedArrays = [
71
68
  });
72
69
  const map = new Type('tag:yaml.org,2002:js/map', {
73
70
  kind: 'sequence',
74
- construct: (/** @type {[unknown, unknown][]} */ data) => (data == null ? new Map() : new Map(data)),
71
+ construct: (data) => (data == null ? new Map() : new Map(data)),
75
72
  instanceOf: Map,
76
- represent: (/** @type {Map<unknown, unknown>} */ object) => [...object],
73
+ represent: (object) => [...object],
77
74
  });
78
75
  const set = new Type('tag:yaml.org,2002:js/set', {
79
76
  kind: 'sequence',
80
- construct: (/** @type {unknown[]} */ data) => (data == null ? new Set() : new Set(data)),
77
+ construct: (data) => (data == null ? new Set() : new Set(data)),
81
78
  instanceOf: Set,
82
- represent: (/** @type {Set<unknown>} */ object) => [...object],
79
+ represent: (object) => [...object],
83
80
  });
84
81
  export const CLOUDPSS_SCHEMA = CORE_SCHEMA.extend({
85
82
  explicit: [buffer, ...typedArrays, map, set],
@@ -1 +1 @@
1
- {"version":3,"file":"schema.js","sourceRoot":"","sources":["../src/schema.js"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAE5D,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAEzD;;;;GAIG;AACH,SAAS,QAAQ,CAAC,IAAI;IAClB,IAAI,OAAO,IAAI,KAAK,QAAQ;QAAE,OAAO,KAAK,CAAC;IAC3C,OAAO,wBAAwB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC/C,CAAC;AAED,MAAM,MAAM,GAAG,IAAI,IAAI,CAAC,kCAAkC,EAAE;IACxD,IAAI,EAAE,QAAQ;IACd,OAAO,EAAE,QAAQ;IACjB,SAAS,EAAE,CAAC,qBAAqB,CAAC,IAAI,EAAE,EAAE,CAAC,YAAY,CAAC,IAAI,IAAI,EAAE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ACf,IAAI,EAAE,UAAU;YAChB,GAAG,UAAU;SAChB,CAAC;KACL,CAAC;AACN,CAAC,CAAC,CAAC;AACH,MAAM,GAAG,GAAG,IAAI,IAAI,CAAC,0BAA0B,EAAE;IAC7C,IAAI,EAAE,UAAU;IAChB,SAAS,EAAE,CAAC,IAA+B,EAAE,EAAE,CAAC,CAAC,IAAI,IAAI,IAAI,CAAC,CAAC,CAAC,IAAI,GAAG,EAAE,CAAC,CAAC,CAAC,IAAI,GAAG,CAAC,IAAI,CAAC,CAAC;IAC1F,UAAU,EAAE,GAAG;IACf,SAAS,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,GAAI,MAAgC,CAAC;CAChE,CAAC,CAAC;AACH,MAAM,GAAG,GAAG,IAAI,IAAI,CAAC,0BAA0B,EAAE;IAC7C,IAAI,EAAE,UAAU;IAChB,SAAS,EAAE,CAAC,IAAe,EAAE,EAAE,CAAC,CAAC,IAAI,IAAI,IAAI,CAAC,CAAC,CAAC,IAAI,GAAG,EAAE,CAAC,CAAC,CAAC,IAAI,GAAG,CAAC,IAAI,CAAC,CAAC;IAC1E,UAAU,EAAE,GAAG;IACf,SAAS,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,GAAI,MAAuB,CAAC;CACvD,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,eAAe,GAAG,WAAW,CAAC,MAAM,CAAC;IAC9C,QAAQ,EAAE,CAAC,MAAM,EAAE,GAAG,WAAW,EAAE,GAAG,EAAE,GAAG,CAAC;CAC/C,CAAC,CAAC,MAAM,CAAC,cAAkC,CAAC,CAAC"}
package/jest.config.js CHANGED
@@ -1,3 +1,3 @@
1
- import { config } from '../../jest.config.js';
1
+ import { config } from '../jest.config.js';
2
2
 
3
3
  export default { ...config };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cloudpss/yaml",
3
- "version": "0.5.38",
3
+ "version": "0.5.40",
4
4
  "author": "CloudPSS",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -14,8 +14,7 @@
14
14
  "js-yaml": "^4.1.0"
15
15
  },
16
16
  "scripts": {
17
- "start": "pnpm clean && tsc --watch",
18
- "build": "pnpm clean && tsc",
17
+ "build": "pnpm clean && tsc --build --force",
19
18
  "clean": "rimraf dist",
20
19
  "benchmark": "node ./benchmark",
21
20
  "test": "NODE_OPTIONS=\"${NODE_OPTIONS:-} --experimental-vm-modules\" jest"
@@ -1,13 +1,10 @@
1
- import { Type, DEFAULT_SCHEMA, CORE_SCHEMA } from 'js-yaml';
2
-
1
+ import { Type, DEFAULT_SCHEMA, CORE_SCHEMA, type TypeConstructorOptions, type SchemaDefinition } from 'js-yaml';
3
2
  import { toUint8Array, fromUint8Array } from 'js-base64';
4
3
 
5
4
  /**
6
5
  * Check if data is base64 encoded
7
- * @param {unknown} data
8
- * @returns {data is string}
9
6
  */
10
- function isBase64(data) {
7
+ function isBase64(data: unknown): data is string {
11
8
  if (typeof data !== 'string') return false;
12
9
  return /^[A-Za-z0-9+/]*={0,2}$/.test(data);
13
10
  }
@@ -15,12 +12,12 @@ function isBase64(data) {
15
12
  const buffer = new Type('tag:yaml.org,2002:js/ArrayBuffer', {
16
13
  kind: 'scalar',
17
14
  resolve: isBase64,
18
- construct: (/** @type {string} */ data) => toUint8Array(data || '').buffer,
15
+ construct: (data: string) => toUint8Array(data || '').buffer,
19
16
  instanceOf: ArrayBuffer,
20
- represent: (object) => fromUint8Array(new Uint8Array(object)),
17
+ represent: (object) => fromUint8Array(new Uint8Array(object as ArrayBuffer)),
21
18
  });
22
19
 
23
- const typedArrays = [
20
+ const TYPED_ARRAY = [
24
21
  Float32Array,
25
22
  Float64Array,
26
23
  Uint8Array,
@@ -30,17 +27,21 @@ const typedArrays = [
30
27
  Int8Array,
31
28
  Int16Array,
32
29
  Int32Array,
33
- ].flatMap((c) => {
30
+ ];
31
+
32
+ /** TypedArray */
33
+ type TypedArray = (typeof TYPED_ARRAY)[number]['prototype'];
34
+
35
+ const typedArrays = TYPED_ARRAY.flatMap((c) => {
34
36
  const yamlType = `tag:yaml.org,2002:js/${c.name}`;
35
- /** @type {import('js-yaml').TypeConstructorOptions} */
36
- const commonInit = {
37
- resolve: (/** @type {string | number[]} */ data) => {
38
- if (Array.isArray(data)) {
37
+ const commonInit: TypeConstructorOptions = {
38
+ resolve: (data: string | number[]): boolean => {
39
+ if (Array.isArray(data) && (data.length === 0 || typeof data[0] == 'number')) {
39
40
  return true;
40
41
  }
41
42
  return isBase64(data);
42
43
  },
43
- construct: (/** @type {string | number[]} */ data) => {
44
+ construct: (data: string | number[]): TypedArray => {
44
45
  if (Array.isArray(data)) {
45
46
  return c.from(data);
46
47
  }
@@ -50,16 +51,13 @@ const typedArrays = [
50
51
  instanceOf: c,
51
52
  defaultStyle: 'base64',
52
53
  represent: {
53
- base64: (
54
- /** @type {Float32Array|Float64Array|Uint8ClampedArray|Uint16Array|Uint32Array|Int8Array|Int16Array|Int32Array} */ object,
55
- ) => {
56
- const buf = new Uint8Array(object.buffer, object.byteOffset, object.byteLength);
54
+ base64: (object) => {
55
+ const av = object as TypedArray;
56
+ const buf = new Uint8Array(av.buffer, av.byteOffset, av.byteLength);
57
57
  return fromUint8Array(buf);
58
58
  },
59
- sequence: (
60
- /** @type {Float32Array|Float64Array|Uint8ClampedArray|Uint16Array|Uint32Array|Int8Array|Int16Array|Int32Array} */ object,
61
- ) => {
62
- return [...object];
59
+ sequence: (object) => {
60
+ return [...(object as TypedArray)];
63
61
  },
64
62
  },
65
63
  };
@@ -76,17 +74,17 @@ const typedArrays = [
76
74
  });
77
75
  const map = new Type('tag:yaml.org,2002:js/map', {
78
76
  kind: 'sequence',
79
- construct: (/** @type {[unknown, unknown][]} */ data) => (data == null ? new Map() : new Map(data)),
77
+ construct: (data: Array<[unknown, unknown]>) => (data == null ? new Map() : new Map(data)),
80
78
  instanceOf: Map,
81
- represent: (/** @type {Map<unknown, unknown>} */ object) => [...object],
79
+ represent: (object) => [...(object as Map<unknown, unknown>)],
82
80
  });
83
81
  const set = new Type('tag:yaml.org,2002:js/set', {
84
82
  kind: 'sequence',
85
- construct: (/** @type {unknown[]} */ data) => (data == null ? new Set() : new Set(data)),
83
+ construct: (data: unknown[]) => (data == null ? new Set() : new Set(data)),
86
84
  instanceOf: Set,
87
- represent: (/** @type {Set<unknown>} */ object) => [...object],
85
+ represent: (object) => [...(object as Set<unknown>)],
88
86
  });
89
87
 
90
88
  export const CLOUDPSS_SCHEMA = CORE_SCHEMA.extend({
91
89
  explicit: [buffer, ...typedArrays, map, set],
92
- }).extend(DEFAULT_SCHEMA);
90
+ }).extend(DEFAULT_SCHEMA as SchemaDefinition);
@@ -5,6 +5,72 @@ exports[`ArrayBuffer should be dumped as base64 1`] = `
5
5
  "
6
6
  `;
7
7
 
8
+ exports[`Empty arrayBuffer should be dumped as base64 1`] = `
9
+ "!!js/ArrayBuffer ''
10
+ "
11
+ `;
12
+
13
+ exports[`Invalid base64 should be rejected 1`] = `
14
+ "cannot resolve a node with !<tag:yaml.org,2002:js/ArrayBuffer> explicit tag (2:1)
15
+
16
+ 1 | !!js/ArrayBuffer ====
17
+ 2 |
18
+ -----^"
19
+ `;
20
+
21
+ exports[`Invalid base64 should be rejected 2`] = `
22
+ "cannot resolve a node with !<tag:yaml.org,2002:js/ArrayBuffer> explicit tag (2:1)
23
+
24
+ 1 | !!js/ArrayBuffer
25
+ 2 |
26
+ -----^"
27
+ `;
28
+
29
+ exports[`TypedArray should be dumped as array Empty Float32Array 1`] = `
30
+ "!!js/Float32Array []
31
+ "
32
+ `;
33
+
34
+ exports[`TypedArray should be dumped as array Empty Float64Array 1`] = `
35
+ "!!js/Float64Array []
36
+ "
37
+ `;
38
+
39
+ exports[`TypedArray should be dumped as array Empty Int8Array 1`] = `
40
+ "!!js/Int8Array []
41
+ "
42
+ `;
43
+
44
+ exports[`TypedArray should be dumped as array Empty Int16Array 1`] = `
45
+ "!!js/Int16Array []
46
+ "
47
+ `;
48
+
49
+ exports[`TypedArray should be dumped as array Empty Int32Array 1`] = `
50
+ "!!js/Int32Array []
51
+ "
52
+ `;
53
+
54
+ exports[`TypedArray should be dumped as array Empty Uint8Array 1`] = `
55
+ "!!js/Uint8Array []
56
+ "
57
+ `;
58
+
59
+ exports[`TypedArray should be dumped as array Empty Uint8ClampedArray 1`] = `
60
+ "!!js/Uint8ClampedArray []
61
+ "
62
+ `;
63
+
64
+ exports[`TypedArray should be dumped as array Empty Uint16Array 1`] = `
65
+ "!!js/Uint16Array []
66
+ "
67
+ `;
68
+
69
+ exports[`TypedArray should be dumped as array Empty Uint32Array 1`] = `
70
+ "!!js/Uint32Array []
71
+ "
72
+ `;
73
+
8
74
  exports[`TypedArray should be dumped as array Float32Array 1`] = `
9
75
  "!!js/Float32Array
10
76
  - 5.4044744426519224e+32
@@ -89,6 +155,51 @@ exports[`TypedArray should be dumped as array Uint32Array 1`] = `
89
155
  "
90
156
  `;
91
157
 
158
+ exports[`TypedArray should be dumped as base64 Empty Float32Array 1`] = `
159
+ "!!js/Float32Array ''
160
+ "
161
+ `;
162
+
163
+ exports[`TypedArray should be dumped as base64 Empty Float64Array 1`] = `
164
+ "!!js/Float64Array ''
165
+ "
166
+ `;
167
+
168
+ exports[`TypedArray should be dumped as base64 Empty Int8Array 1`] = `
169
+ "!!js/Int8Array ''
170
+ "
171
+ `;
172
+
173
+ exports[`TypedArray should be dumped as base64 Empty Int16Array 1`] = `
174
+ "!!js/Int16Array ''
175
+ "
176
+ `;
177
+
178
+ exports[`TypedArray should be dumped as base64 Empty Int32Array 1`] = `
179
+ "!!js/Int32Array ''
180
+ "
181
+ `;
182
+
183
+ exports[`TypedArray should be dumped as base64 Empty Uint8Array 1`] = `
184
+ "!!js/Uint8Array ''
185
+ "
186
+ `;
187
+
188
+ exports[`TypedArray should be dumped as base64 Empty Uint8ClampedArray 1`] = `
189
+ "!!js/Uint8ClampedArray ''
190
+ "
191
+ `;
192
+
193
+ exports[`TypedArray should be dumped as base64 Empty Uint16Array 1`] = `
194
+ "!!js/Uint16Array ''
195
+ "
196
+ `;
197
+
198
+ exports[`TypedArray should be dumped as base64 Empty Uint32Array 1`] = `
199
+ "!!js/Uint32Array ''
200
+ "
201
+ `;
202
+
92
203
  exports[`TypedArray should be dumped as base64 Float32Array 1`] = `
93
204
  "!!js/Float32Array PyvVdTF6oNc=
94
205
  "
@@ -134,6 +245,51 @@ exports[`TypedArray should be dumped as base64 Uint32Array 1`] = `
134
245
  "
135
246
  `;
136
247
 
248
+ exports[`TypedArray should be dumped as base64 by default Empty Float32Array 1`] = `
249
+ "!!js/Float32Array ''
250
+ "
251
+ `;
252
+
253
+ exports[`TypedArray should be dumped as base64 by default Empty Float64Array 1`] = `
254
+ "!!js/Float64Array ''
255
+ "
256
+ `;
257
+
258
+ exports[`TypedArray should be dumped as base64 by default Empty Int8Array 1`] = `
259
+ "!!js/Int8Array ''
260
+ "
261
+ `;
262
+
263
+ exports[`TypedArray should be dumped as base64 by default Empty Int16Array 1`] = `
264
+ "!!js/Int16Array ''
265
+ "
266
+ `;
267
+
268
+ exports[`TypedArray should be dumped as base64 by default Empty Int32Array 1`] = `
269
+ "!!js/Int32Array ''
270
+ "
271
+ `;
272
+
273
+ exports[`TypedArray should be dumped as base64 by default Empty Uint8Array 1`] = `
274
+ "!!js/Uint8Array ''
275
+ "
276
+ `;
277
+
278
+ exports[`TypedArray should be dumped as base64 by default Empty Uint8ClampedArray 1`] = `
279
+ "!!js/Uint8ClampedArray ''
280
+ "
281
+ `;
282
+
283
+ exports[`TypedArray should be dumped as base64 by default Empty Uint16Array 1`] = `
284
+ "!!js/Uint16Array ''
285
+ "
286
+ `;
287
+
288
+ exports[`TypedArray should be dumped as base64 by default Empty Uint32Array 1`] = `
289
+ "!!js/Uint32Array ''
290
+ "
291
+ `;
292
+
137
293
  exports[`TypedArray should be dumped as base64 by default Float32Array 1`] = `
138
294
  "!!js/Float32Array PyvVdTF6oNc=
139
295
  "
@@ -1,9 +1,3 @@
1
1
  {
2
- "extends": "../tsconfig",
3
- "include": ["./"],
4
- "compilerOptions": {
5
- "checkJs": true,
6
- "noEmit": true,
7
- "rootDir": "."
8
- }
2
+ "extends": "../../tsconfig.test"
9
3
  }
package/tests/types.js CHANGED
@@ -19,6 +19,18 @@ it('ArrayBuffer should be dumped as base64', () => {
19
19
  expect(new Uint8Array(/** @type {ArrayBuffer} */ (load(dumped)))).toEqual(data);
20
20
  });
21
21
 
22
+ it('Empty arrayBuffer should be dumped as base64', () => {
23
+ const data = new ArrayBuffer(0);
24
+ const dumped = dump(data);
25
+ expect(dumped).toMatchSnapshot();
26
+ expect(load(dumped)).toEqual(data);
27
+ });
28
+
29
+ it('Invalid base64 should be rejected', () => {
30
+ expect(() => load('!!js/ArrayBuffer ====')).toThrowErrorMatchingSnapshot();
31
+ expect(() => load('!!js/ArrayBuffer')).toThrowErrorMatchingSnapshot();
32
+ });
33
+
22
34
  describe('TypedArray should be dumped as base64 by default', () => {
23
35
  for (const type of TypedArrays) {
24
36
  it(type.name, () => {
@@ -28,6 +40,12 @@ describe('TypedArray should be dumped as base64 by default', () => {
28
40
  expect(dumped).toMatchSnapshot();
29
41
  expect(load(dumped)).toEqual(data);
30
42
  });
43
+ it(`Empty ${type.name}`, () => {
44
+ const data = new type([]);
45
+ const dumped = dump(data);
46
+ expect(dumped).toMatchSnapshot();
47
+ expect(load(dumped)).toEqual(data);
48
+ });
31
49
  }
32
50
  });
33
51
 
@@ -42,6 +60,12 @@ describe('TypedArray should be dumped as base64', () => {
42
60
  expect(dumped2).toEqual(dumped);
43
61
  expect(load(dumped)).toEqual(data);
44
62
  });
63
+ it(`Empty ${type.name}`, () => {
64
+ const data = new type([]);
65
+ const dumped = dump(data, { styles: { [`!!js/TypedArray`]: 'base64' } });
66
+ expect(dumped).toMatchSnapshot();
67
+ expect(load(dumped)).toEqual(data);
68
+ });
45
69
  }
46
70
  });
47
71
 
@@ -56,6 +80,12 @@ describe('TypedArray should be dumped as array', () => {
56
80
  expect(dumped2).toEqual(dumped);
57
81
  expect(load(dumped)).toEqual(data);
58
82
  });
83
+ it(`Empty ${type.name}`, () => {
84
+ const data = new type([]);
85
+ const dumped = dump(data, { styles: { [`!!js/TypedArray`]: 'sequence' } });
86
+ expect(dumped).toMatchSnapshot();
87
+ expect(load(dumped)).toEqual(data);
88
+ });
59
89
  }
60
90
  });
61
91
 
package/tsconfig.json CHANGED
@@ -1,6 +1,3 @@
1
1
  {
2
- "extends": "../../tsconfig",
3
- "compilerOptions": {
4
- "allowJs": true
5
- }
2
+ "extends": "../tsconfig.build"
6
3
  }