@cloudpss/yaml 0.4.11 → 0.4.13

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/benchmark.js CHANGED
@@ -4,26 +4,24 @@ import { load, dump } from './dist/index.js';
4
4
 
5
5
  const LOOP = 1;
6
6
 
7
- const t = (time) => time.toFixed(2) + 'ms';
8
- const pb = (size) => prettyBytes(size, { binary: true });
7
+ const t = (/** @type {number} */ time) => time.toFixed(2) + 'ms';
8
+ const pb = (/** @type {number} */ size) => prettyBytes(size, { binary: true });
9
9
 
10
10
  /* eslint-disable no-console */
11
- (async function () {
12
- for await (const { file, data } of files()) {
13
- console.log(`File: ${file} \tRaw: ${pb(data.length)}`);
14
- const obj = load(data.toString());
15
- let encodeTime = 0;
16
- let decodeTime = 0;
17
- let obj2;
18
- for (let i = 0; i < LOOP; i++) {
19
- let start = performance.now();
20
- const encoded = dump(obj);
21
- encodeTime += performance.now() - start;
22
- start = performance.now();
23
- obj2 = load(encoded);
24
- decodeTime += performance.now() - start;
25
- }
26
- console.assert(dump(obj2) === dump(obj));
27
- console.log(` encode: \t${t(encodeTime / LOOP)}\tdecode: \t${t(decodeTime / LOOP)}`);
11
+ for await (const { file, data } of files()) {
12
+ console.log(`File: ${file} \tRaw: ${pb(data.length)}`);
13
+ const obj = load(data.toString());
14
+ let encodeTime = 0;
15
+ let decodeTime = 0;
16
+ let obj2;
17
+ for (let i = 0; i < LOOP; i++) {
18
+ let start = performance.now();
19
+ const encoded = dump(obj);
20
+ encodeTime += performance.now() - start;
21
+ start = performance.now();
22
+ obj2 = load(encoded);
23
+ decodeTime += performance.now() - start;
28
24
  }
29
- })();
25
+ console.assert(dump(obj2) === dump(obj));
26
+ console.log(` encode: \t${t(encodeTime / LOOP)}\tdecode: \t${t(decodeTime / LOOP)}`);
27
+ }
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
- import type { LoadOptions, DumpOptions } from 'js-yaml';
2
- /** 解析 YAML */
3
- export declare function load(str: string, opts?: LoadOptions): unknown;
4
- /** 序列化为 YAML */
5
- export declare function dump(obj: unknown, opts?: DumpOptions): string;
6
- export type { LoadOptions, DumpOptions };
1
+ import type { LoadOptions, DumpOptions } from 'js-yaml';
2
+ /** 解析 YAML */
3
+ export declare function load(str: string, opts?: LoadOptions): unknown;
4
+ /** 序列化为 YAML */
5
+ export declare function dump(obj: unknown, opts?: DumpOptions): string;
6
+ export type { LoadOptions, DumpOptions };
package/dist/index.js CHANGED
@@ -1,21 +1,21 @@
1
- import { load as _load, dump as _dump } from 'js-yaml';
2
- import { CLOUDPSS_SCHEMA } from './schema.js';
3
- /** 解析 YAML */
4
- export function load(str, opts) {
5
- return _load(str, {
6
- ...opts,
7
- schema: CLOUDPSS_SCHEMA,
8
- });
9
- }
10
- /** 序列化为 YAML */
11
- export function dump(obj, opts) {
12
- return _dump(obj, {
13
- lineWidth: 200,
14
- flowLevel: 3,
15
- noRefs: true,
16
- ...opts,
17
- schema: CLOUDPSS_SCHEMA,
18
- skipInvalid: true,
19
- });
20
- }
1
+ import { load as _load, dump as _dump } from 'js-yaml';
2
+ import { CLOUDPSS_SCHEMA } from './schema.js';
3
+ /** 解析 YAML */
4
+ export function load(str, opts) {
5
+ return _load(str, {
6
+ ...opts,
7
+ schema: CLOUDPSS_SCHEMA,
8
+ });
9
+ }
10
+ /** 序列化为 YAML */
11
+ export function dump(obj, opts) {
12
+ return _dump(obj, {
13
+ lineWidth: 200,
14
+ flowLevel: 3,
15
+ noRefs: true,
16
+ ...opts,
17
+ schema: CLOUDPSS_SCHEMA,
18
+ skipInvalid: true,
19
+ });
20
+ }
21
21
  //# sourceMappingURL=index.js.map
package/dist/schema.d.ts CHANGED
@@ -1 +1 @@
1
- export const CLOUDPSS_SCHEMA: import("js-yaml").Schema;
1
+ export const CLOUDPSS_SCHEMA: import("js-yaml").Schema;
package/dist/schema.js CHANGED
@@ -1,51 +1,49 @@
1
- import { Type, DEFAULT_SCHEMA } from 'js-yaml';
2
- import { toUint8Array, fromUint8Array } from 'js-base64';
3
- const buffer = new Type('tag:yaml.org,2002:js/ArrayBuffer', {
4
- kind: 'scalar',
5
- resolve: (data) => data != null,
6
- construct: (data) => toUint8Array(data || '').buffer,
7
- instanceOf: ArrayBuffer,
8
- represent: (object) => fromUint8Array(new Uint8Array(object)),
9
- });
10
- const typedArrays = [
11
- Float32Array,
12
- Float64Array,
13
- Uint8Array,
14
- Uint8ClampedArray,
15
- Uint16Array,
16
- Uint32Array,
17
- Int8Array,
18
- Int16Array,
19
- Int32Array,
20
- ].map((c) => new Type(`tag:yaml.org,2002:js/${c.name}`, {
21
- kind: 'scalar',
22
- resolve: (data) => data != null,
23
- construct: (data) => {
24
- const buf = toUint8Array(data || '');
25
- return new c(buf.buffer, buf.byteOffset, buf.byteLength / c.BYTES_PER_ELEMENT);
26
- },
27
- instanceOf: c,
28
- /**
29
- * @param {Float32Array|Float64Array|Uint8ClampedArray|Uint16Array|Uint32Array|Int8Array|Int16Array|Int32Array} object
30
- */
31
- represent: (object) => {
32
- const buf = new Uint8Array(object.buffer, object.byteOffset, object.byteLength);
33
- return fromUint8Array(buf);
34
- },
35
- }));
36
- const map = new Type('tag:yaml.org,2002:js/map', {
37
- kind: 'sequence',
38
- construct: (data) => (data == null ? new Map() : new Map(data)),
39
- instanceOf: Map,
40
- represent: (object) => [...object],
41
- });
42
- const set = new Type('tag:yaml.org,2002:js/set', {
43
- kind: 'sequence',
44
- construct: (data) => (data == null ? new Set() : new Set(data)),
45
- instanceOf: Set,
46
- represent: (object) => [...object],
47
- });
48
- export const CLOUDPSS_SCHEMA = DEFAULT_SCHEMA.extend({
49
- explicit: [buffer, ...typedArrays, map, set],
50
- });
1
+ import { Type, DEFAULT_SCHEMA } from 'js-yaml';
2
+ import { toUint8Array, fromUint8Array } from 'js-base64';
3
+ const buffer = new Type('tag:yaml.org,2002:js/ArrayBuffer', {
4
+ kind: 'scalar',
5
+ resolve: (data) => data != null,
6
+ construct: (/** @type {string} */ data) => toUint8Array(data || '').buffer,
7
+ instanceOf: ArrayBuffer,
8
+ represent: (object) => fromUint8Array(new Uint8Array(object)),
9
+ });
10
+ const typedArrays = [
11
+ Float32Array,
12
+ Float64Array,
13
+ Uint8Array,
14
+ Uint8ClampedArray,
15
+ Uint16Array,
16
+ Uint32Array,
17
+ Int8Array,
18
+ Int16Array,
19
+ Int32Array,
20
+ ].map((c) => new Type(`tag:yaml.org,2002:js/${c.name}`, {
21
+ kind: 'scalar',
22
+ resolve: (data) => data != null,
23
+ construct: (/** @type {string} */ data) => {
24
+ const buf = toUint8Array(data || '');
25
+ return new c(buf.buffer, buf.byteOffset, buf.byteLength / c.BYTES_PER_ELEMENT);
26
+ },
27
+ instanceOf: c,
28
+ represent: (
29
+ /** @type {Float32Array|Float64Array|Uint8ClampedArray|Uint16Array|Uint32Array|Int8Array|Int16Array|Int32Array} */ object) => {
30
+ const buf = new Uint8Array(object.buffer, object.byteOffset, object.byteLength);
31
+ return fromUint8Array(buf);
32
+ },
33
+ }));
34
+ const map = new Type('tag:yaml.org,2002:js/map', {
35
+ kind: 'sequence',
36
+ construct: (/** @type {[unknown, unknown][]} */ data) => (data == null ? new Map() : new Map(data)),
37
+ instanceOf: Map,
38
+ represent: (/** @type {Map<unknown, unknown>} */ object) => [...object],
39
+ });
40
+ const set = new Type('tag:yaml.org,2002:js/set', {
41
+ kind: 'sequence',
42
+ construct: (/** @type {unknown[]} */ data) => (data == null ? new Set() : new Set(data)),
43
+ instanceOf: Set,
44
+ represent: (/** @type {Set<unknown>} */ object) => [...object],
45
+ });
46
+ export const CLOUDPSS_SCHEMA = DEFAULT_SCHEMA.extend({
47
+ explicit: [buffer, ...typedArrays, map, set],
48
+ });
51
49
  //# sourceMappingURL=schema.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"schema.js","sourceRoot":"","sources":["../src/schema.js"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAE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I,EAAE,UAAU;IAChB,SAAS,EAAE,CAAC,mCAAmC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,IAAI,IAAI,IAAI,CAAC,CAAC,CAAC,IAAI,GAAG,EAAE,CAAC,CAAC,CAAC,IAAI,GAAG,CAAC,IAAI,CAAC,CAAC;IACnG,UAAU,EAAE,GAAG;IACf,SAAS,EAAE,CAAC,oCAAoC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,GAAG,MAAM,CAAC;CAC1E,CAAC,CAAC;AACH,MAAM,GAAG,GAAG,IAAI,IAAI,CAAC,0BAA0B,EAAE;IAC7C,IAAI,EAAE,UAAU;IAChB,SAAS,EAAE,CAAC,wBAAwB,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,IAAI,IAAI,IAAI,CAAC,CAAC,CAAC,IAAI,GAAG,EAAE,CAAC,CAAC,CAAC,IAAI,GAAG,CAAC,IAAI,CAAC,CAAC;IACxF,UAAU,EAAE,GAAG;IACf,SAAS,EAAE,CAAC,2BAA2B,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,GAAG,MAAM,CAAC;CACjE,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,eAAe,GAAG,cAAc,CAAC,MAAM,CAAC;IACjD,QAAQ,EAAE,CAAC,MAAM,EAAE,GAAG,WAAW,EAAE,GAAG,EAAE,GAAG,CAAC;CAC/C,CAAC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cloudpss/yaml",
3
- "version": "0.4.11",
3
+ "version": "0.4.13",
4
4
  "author": "CloudPSS",
5
5
  "license": "MIT",
6
6
  "type": "module",
package/src/schema.js CHANGED
@@ -5,7 +5,7 @@ import { toUint8Array, fromUint8Array } from 'js-base64';
5
5
  const buffer = new Type('tag:yaml.org,2002:js/ArrayBuffer', {
6
6
  kind: 'scalar',
7
7
  resolve: (data) => data != null,
8
- construct: (data) => toUint8Array(data || '').buffer,
8
+ construct: (/** @type {string} */ data) => toUint8Array(data || '').buffer,
9
9
  instanceOf: ArrayBuffer,
10
10
  represent: (object) => fromUint8Array(new Uint8Array(object)),
11
11
  });
@@ -25,15 +25,14 @@ const typedArrays = [
25
25
  new Type(`tag:yaml.org,2002:js/${c.name}`, {
26
26
  kind: 'scalar',
27
27
  resolve: (data) => data != null,
28
- construct: (data) => {
28
+ construct: (/** @type {string} */ data) => {
29
29
  const buf = toUint8Array(data || '');
30
30
  return new c(buf.buffer, buf.byteOffset, buf.byteLength / c.BYTES_PER_ELEMENT);
31
31
  },
32
32
  instanceOf: c,
33
- /**
34
- * @param {Float32Array|Float64Array|Uint8ClampedArray|Uint16Array|Uint32Array|Int8Array|Int16Array|Int32Array} object
35
- */
36
- represent: (object) => {
33
+ represent: (
34
+ /** @type {Float32Array|Float64Array|Uint8ClampedArray|Uint16Array|Uint32Array|Int8Array|Int16Array|Int32Array} */ object,
35
+ ) => {
37
36
  const buf = new Uint8Array(object.buffer, object.byteOffset, object.byteLength);
38
37
  return fromUint8Array(buf);
39
38
  },
@@ -41,15 +40,15 @@ const typedArrays = [
41
40
  );
42
41
  const map = new Type('tag:yaml.org,2002:js/map', {
43
42
  kind: 'sequence',
44
- construct: (data) => (data == null ? new Map() : new Map(data)),
43
+ construct: (/** @type {[unknown, unknown][]} */ data) => (data == null ? new Map() : new Map(data)),
45
44
  instanceOf: Map,
46
- represent: (object) => [...object],
45
+ represent: (/** @type {Map<unknown, unknown>} */ object) => [...object],
47
46
  });
48
47
  const set = new Type('tag:yaml.org,2002:js/set', {
49
48
  kind: 'sequence',
50
- construct: (data) => (data == null ? new Set() : new Set(data)),
49
+ construct: (/** @type {unknown[]} */ data) => (data == null ? new Set() : new Set(data)),
51
50
  instanceOf: Set,
52
- represent: (object) => [...object],
51
+ represent: (/** @type {Set<unknown>} */ object) => [...object],
53
52
  });
54
53
 
55
54
  export const CLOUDPSS_SCHEMA = DEFAULT_SCHEMA.extend({