@es-joy/jsoe 0.23.1 → 0.24.1

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.
Files changed (54) hide show
  1. package/CHANGES.md +10 -0
  2. package/README.md +25 -1
  3. package/badges/coverage-badge.svg +1 -1
  4. package/dist/formatAndTypeChoices.d.ts +9 -2
  5. package/dist/formatAndTypeChoices.d.ts.map +1 -1
  6. package/dist/formats/arbitraryJS.d.ts +4 -0
  7. package/dist/formats/arbitraryJS.d.ts.map +1 -0
  8. package/dist/formats/schema.d.ts.map +1 -1
  9. package/dist/formats/structuredCloning.d.ts +1 -1
  10. package/dist/formats/structuredCloning.d.ts.map +1 -1
  11. package/dist/formats.d.ts +13 -10
  12. package/dist/formats.d.ts.map +1 -1
  13. package/dist/fundamentalTypes/blobType.d.ts.map +1 -1
  14. package/dist/fundamentalTypes/fileType.d.ts.map +1 -1
  15. package/dist/fundamentalTypes/functionType.d.ts +1 -0
  16. package/dist/fundamentalTypes/functionType.d.ts.map +1 -1
  17. package/dist/fundamentalTypes/promiseType.d.ts.map +1 -1
  18. package/dist/fundamentalTypes/stringType.d.ts.map +1 -1
  19. package/dist/fundamentalTypes/symbolType.d.ts.map +1 -1
  20. package/dist/index.js +1 -1
  21. package/dist/index.js.map +1 -1
  22. package/dist/types.d.ts +33 -27
  23. package/dist/types.d.ts.map +1 -1
  24. package/dist/vendor-imports.d.ts +2 -1
  25. package/package.json +13 -14
  26. package/rollup.config.js +12 -0
  27. package/src/formatAndTypeChoices.js +32 -7
  28. package/src/formats/arbitraryJS.js +27 -0
  29. package/src/formats/indexedDBKey.js +1 -1
  30. package/src/formats/json.js +1 -1
  31. package/src/formats/schema.js +17 -13
  32. package/src/formats/structuredCloning.js +37 -8
  33. package/src/formats.js +15 -7
  34. package/src/fundamentalTypes/arrayReferenceType.js +1 -1
  35. package/src/fundamentalTypes/bigintObjectType.js +1 -1
  36. package/src/fundamentalTypes/bigintType.js +1 -1
  37. package/src/fundamentalTypes/blobType.js +11 -3
  38. package/src/fundamentalTypes/fileType.js +9 -4
  39. package/src/fundamentalTypes/functionType.js +237 -69
  40. package/src/fundamentalTypes/numberType.js +3 -3
  41. package/src/fundamentalTypes/objectReferenceType.js +1 -1
  42. package/src/fundamentalTypes/promiseType.js +144 -15
  43. package/src/fundamentalTypes/stringType.js +8 -7
  44. package/src/fundamentalTypes/symbolType.js +14 -6
  45. package/src/subTypes/blobHTMLType.js +1 -1
  46. package/src/types.js +31 -25
  47. package/src/vendor-imports.js +6 -1
  48. package/vendor/acorn/dist/acorn.d.mts +856 -0
  49. package/vendor/acorn/dist/acorn.d.ts +856 -0
  50. package/vendor/acorn/dist/acorn.js +6065 -0
  51. package/vendor/acorn/dist/acorn.mjs +6036 -0
  52. package/vendor/acorn/dist/bin.js +90 -0
  53. package/vendor/jamilih/dist/jml-es.js +9 -14
  54. package/vendor/typeson-registry/dist/index.js +70 -26
@@ -0,0 +1,90 @@
1
+ 'use strict';
2
+
3
+ var path = require('path');
4
+ var fs = require('fs');
5
+ var acorn = require('./acorn.js');
6
+
7
+ function _interopNamespaceDefault(e) {
8
+ var n = Object.create(null);
9
+ if (e) {
10
+ Object.keys(e).forEach(function (k) {
11
+ if (k !== 'default') {
12
+ var d = Object.getOwnPropertyDescriptor(e, k);
13
+ Object.defineProperty(n, k, d.get ? d : {
14
+ enumerable: true,
15
+ get: function () { return e[k]; }
16
+ });
17
+ }
18
+ });
19
+ }
20
+ n.default = e;
21
+ return Object.freeze(n);
22
+ }
23
+
24
+ var acorn__namespace = /*#__PURE__*/_interopNamespaceDefault(acorn);
25
+
26
+ var inputFilePaths = [], forceFileName = false, fileMode = false, silent = false, compact = false, tokenize = false;
27
+ var options = {};
28
+
29
+ function help(status) {
30
+ var print = (status === 0) ? console.log : console.error;
31
+ print("usage: " + path.basename(process.argv[1]) + " [--ecma3|--ecma5|--ecma6|--ecma7|--ecma8|--ecma9|...|--ecma2015|--ecma2016|--ecma2017|--ecma2018|...]");
32
+ print(" [--tokenize] [--locations] [--allow-hash-bang] [--allow-await-outside-function] [--compact] [--silent] [--module] [--help] [--] [<infile>...]");
33
+ process.exit(status);
34
+ }
35
+
36
+ for (var i = 2; i < process.argv.length; ++i) {
37
+ var arg = process.argv[i];
38
+ if (arg[0] !== "-" || arg === "-") { inputFilePaths.push(arg); }
39
+ else if (arg === "--") {
40
+ inputFilePaths.push.apply(inputFilePaths, process.argv.slice(i + 1));
41
+ forceFileName = true;
42
+ break
43
+ } else if (arg === "--locations") { options.locations = true; }
44
+ else if (arg === "--allow-hash-bang") { options.allowHashBang = true; }
45
+ else if (arg === "--allow-await-outside-function") { options.allowAwaitOutsideFunction = true; }
46
+ else if (arg === "--silent") { silent = true; }
47
+ else if (arg === "--compact") { compact = true; }
48
+ else if (arg === "--help") { help(0); }
49
+ else if (arg === "--tokenize") { tokenize = true; }
50
+ else if (arg === "--module") { options.sourceType = "module"; }
51
+ else {
52
+ var match = arg.match(/^--ecma(\d+)$/);
53
+ if (match)
54
+ { options.ecmaVersion = +match[1]; }
55
+ else
56
+ { help(1); }
57
+ }
58
+ }
59
+
60
+ function run(codeList) {
61
+ var result = [], fileIdx = 0;
62
+ try {
63
+ codeList.forEach(function (code, idx) {
64
+ fileIdx = idx;
65
+ if (!tokenize) {
66
+ result = acorn__namespace.parse(code, options);
67
+ options.program = result;
68
+ } else {
69
+ var tokenizer = acorn__namespace.tokenizer(code, options), token;
70
+ do {
71
+ token = tokenizer.getToken();
72
+ result.push(token);
73
+ } while (token.type !== acorn__namespace.tokTypes.eof)
74
+ }
75
+ });
76
+ } catch (e) {
77
+ console.error(fileMode ? e.message.replace(/\(\d+:\d+\)$/, function (m) { return m.slice(0, 1) + inputFilePaths[fileIdx] + " " + m.slice(1); }) : e.message);
78
+ process.exit(1);
79
+ }
80
+ if (!silent) { console.log(JSON.stringify(result, null, compact ? null : 2)); }
81
+ }
82
+
83
+ if (fileMode = inputFilePaths.length && (forceFileName || !inputFilePaths.includes("-") || inputFilePaths.length !== 1)) {
84
+ run(inputFilePaths.map(function (path) { return fs.readFileSync(path, "utf8"); }));
85
+ } else {
86
+ var code = "";
87
+ process.stdin.resume();
88
+ process.stdin.on("data", function (chunk) { return code += chunk; });
89
+ process.stdin.on("end", function () { return run([code]); });
90
+ }
@@ -1,4 +1,3 @@
1
- var _win;
2
1
  /*
3
2
  Possible todos:
4
3
  0. Add XSLT to JML-string stylesheet (or even vice versa)
@@ -66,7 +65,7 @@ if (typeof window !== 'undefined' && window) {
66
65
  }
67
66
 
68
67
  /* c8 ignore next */
69
- let doc = typeof document !== 'undefined' && document || ((_win = win) === null || _win === void 0 ? void 0 : _win.document);
68
+ let doc = typeof document !== 'undefined' && document || win?.document;
70
69
 
71
70
  // STATIC PROPERTIES
72
71
 
@@ -737,7 +736,7 @@ function _DOMfromJMLOrString (childNodeJML) {
737
736
  * @returns {Promise<void>|string|null}
738
737
  */
739
738
  function checkPluginValue(elem, att, attVal, opts, state) {
740
- opts.$state = state !== null && state !== void 0 ? state : 'attributeValue';
739
+ opts.$state = state ?? 'attributeValue';
741
740
  if (attVal && typeof attVal === 'object') {
742
741
  const matchingPlugin = getMatchingPlugin(opts, Object.keys(attVal)[0]);
743
742
  if (matchingPlugin) {
@@ -808,8 +807,7 @@ const jml = function jml(...args) {
808
807
  throw new Error('No document object');
809
808
  }
810
809
  for (let [att, attVal] of Object.entries(atts)) {
811
- var _ATTR_MAP$get;
812
- att = (_ATTR_MAP$get = ATTR_MAP.get(att)) !== null && _ATTR_MAP$get !== void 0 ? _ATTR_MAP$get : att;
810
+ att = ATTR_MAP.get(att) ?? att;
813
811
 
814
812
  /**
815
813
  * @typedef {any} ElementExpando
@@ -1091,21 +1089,20 @@ const jml = function jml(...args) {
1091
1089
  jamlihDoc.childNodes.forEach(_childrenToJML(docNode));
1092
1090
  } else {
1093
1091
  if (jamlihDoc.$DOCTYPE) {
1094
- var _docNode$firstChild;
1095
1092
  const dt = {
1096
1093
  $DOCTYPE: jamlihDoc.$DOCTYPE
1097
1094
  };
1098
1095
  const doctype = jml(dt);
1099
- (_docNode$firstChild = docNode.firstChild) === null || _docNode$firstChild === void 0 ? void 0 : _docNode$firstChild.replaceWith(doctype);
1096
+ docNode.firstChild?.replaceWith(doctype);
1100
1097
  }
1101
1098
  const html = docNode.querySelector('html');
1102
- const head = html === null || html === void 0 ? void 0 : html.querySelector('head');
1103
- const body = html === null || html === void 0 ? void 0 : html.querySelector('body');
1099
+ const head = html?.querySelector('head');
1100
+ const body = html?.querySelector('body');
1104
1101
  if (jamlihDoc.title || jamlihDoc.head) {
1105
1102
  const meta = doc.createElement('meta');
1106
1103
  // eslint-disable-next-line unicorn/text-encoding-identifier-case -- HTML
1107
1104
  meta.setAttribute('charset', 'utf-8');
1108
- head === null || head === void 0 ? void 0 : head.append(meta);
1105
+ head?.append(meta);
1109
1106
  if (jamlihDoc.title) {
1110
1107
  docNode.title = jamlihDoc.title; // Appends after meta
1111
1108
  }
@@ -1897,10 +1894,9 @@ jml.toJML = function (nde, {
1897
1894
  }
1898
1895
  case 4:
1899
1896
  {
1900
- var _node$nodeValue;
1901
1897
  // CDATA
1902
1898
  const node = /** @type {CDATASection} */nodeOrEntity;
1903
- if ((_node$nodeValue = node.nodeValue) !== null && _node$nodeValue !== void 0 && _node$nodeValue.includes(']]' + '>')) {
1899
+ if (node.nodeValue?.includes(']]' + '>')) {
1904
1900
  invalidStateError('CDATA cannot end with closing ]]>');
1905
1901
  }
1906
1902
  set(['![', node.nodeValue]);
@@ -2312,9 +2308,8 @@ jml.command = function (elem, symOrMap, methodName, ...args) {
2312
2308
  * @returns {void}
2313
2309
  */
2314
2310
  jml.setWindow = wind => {
2315
- var _win2;
2316
2311
  win = wind;
2317
- doc = (_win2 = win) === null || _win2 === void 0 ? void 0 : _win2.document;
2312
+ doc = win?.document;
2318
2313
  if (doc && doc.body) {
2319
2314
  // eslint-disable-next-line prefer-destructuring -- Needed for typing
2320
2315
  body = /** @type {HTMLBodyElement} */doc.body;
@@ -157,8 +157,6 @@ const bigintObject = {
157
157
  },
158
158
  replace: String,
159
159
  revive (s) {
160
- // Filed this to avoid error: https://github.com/eslint/eslint/issues/11810
161
- // eslint-disable-next-line no-new-object
162
160
  return new Object(BigInt(/** @type {string} */ (s)));
163
161
  }
164
162
  }
@@ -173,7 +171,8 @@ const bigint = {
173
171
  return typeof x === 'bigint';
174
172
  },
175
173
  replace: String,
176
- // eslint-disable-next-line unicorn/prefer-native-coercion-functions
174
+ // eslint-disable-next-line @stylistic/max-len -- Long
175
+ // eslint-disable-next-line unicorn/prefer-native-coercion-functions -- Clearer
177
176
  revive (s) {
178
177
  return BigInt(/** @type {string} */ (s));
179
178
  }
@@ -252,7 +251,7 @@ function string2arraybuffer (str) {
252
251
  return array.buffer;
253
252
  }
254
253
 
255
- /* globals XMLHttpRequest, FileReader */
254
+ /* globals XMLHttpRequest, FileReader -- Polyfills */
256
255
 
257
256
  /**
258
257
  * @type {import('typeson').TypeSpecSet}
@@ -323,14 +322,12 @@ function generateUUID () { // Adapted from original: public domain/MIT: http://
323
322
  /* c8 ignore next */
324
323
  let d = Date.now();
325
324
 
326
- // eslint-disable-next-line @stylistic/max-len -- Long
327
- // eslint-disable-next-line no-use-extend-native/no-use-extend-native -- Need to update plugin
328
325
  return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replaceAll(/[xy]/gu, function (c) {
329
- /* eslint-disable no-bitwise */
326
+ /* eslint-disable no-bitwise -- Convenient */
330
327
  const r = Math.trunc((d + (Math.random() * 16)) % 16);
331
328
  d = Math.floor(d / 16);
332
329
  return (c === 'x' ? r : ((r & 0x3) | 0x8)).toString(16);
333
- /* eslint-enable no-bitwise */
330
+ /* eslint-enable no-bitwise -- Convenient */
334
331
  });
335
332
  }
336
333
 
@@ -519,7 +516,7 @@ const domexception = {
519
516
  }
520
517
  };
521
518
 
522
- /* globals DOMMatrix, DOMMatrixReadOnly */
519
+ /* globals DOMMatrix, DOMMatrixReadOnly -- Polyfills */
523
520
 
524
521
  /**
525
522
  * @type {import('typeson').TypeSpecSet}
@@ -586,7 +583,7 @@ function create$5 (Ctor) {
586
583
  };
587
584
  }
588
585
 
589
- /* globals DOMPoint, DOMPointReadOnly */
586
+ /* globals DOMPoint, DOMPointReadOnly -- Polyfills */
590
587
 
591
588
  /**
592
589
  * @type {import('typeson').TypeSpecSet}
@@ -623,7 +620,7 @@ function create$4 (Ctor) {
623
620
  };
624
621
  }
625
622
 
626
- /* globals DOMQuad */
623
+ /* globals DOMQuad -- Polyfills */
627
624
 
628
625
  /**
629
626
  * @type {import('typeson').TypeSpecSet}
@@ -645,7 +642,7 @@ const domquad = {
645
642
  }
646
643
  };
647
644
 
648
- /* globals DOMRect, DOMRectReadOnly */
645
+ /* globals DOMRect, DOMRectReadOnly -- Polyfills */
649
646
 
650
647
  /**
651
648
  * @type {import('typeson').TypeSpecSet}
@@ -718,8 +715,7 @@ const error = {
718
715
  }
719
716
  };
720
717
 
721
- /* globals InternalError */
722
- /* eslint-env browser, node */
718
+ /* globals InternalError -- Optional */
723
719
 
724
720
  /**
725
721
  * @type {import('typeson').TypeSpecSet}
@@ -810,7 +806,7 @@ function create$2 (Ctor) {
810
806
  };
811
807
  }
812
808
 
813
- /* globals XMLHttpRequest, FileReader */
809
+ /* globals XMLHttpRequest, FileReader -- Polyfills */
814
810
 
815
811
  /**
816
812
  * @type {import('typeson').TypeSpecSet}
@@ -897,7 +893,7 @@ const filelist = {
897
893
  * Set private properties and length.
898
894
  */
899
895
  constructor () {
900
- // eslint-disable-next-line prefer-rest-params
896
+ // eslint-disable-next-line prefer-rest-params -- API
901
897
  this._files = arguments[0];
902
898
  this.length = this._files.length;
903
899
  }
@@ -908,12 +904,12 @@ const filelist = {
908
904
  item (index) {
909
905
  return this._files[index];
910
906
  }
911
- /* eslint-disable class-methods-use-this */
907
+ /* eslint-disable class-methods-use-this -- Not needed */
912
908
  /**
913
909
  * @returns {"FileList"}
914
910
  */
915
911
  get [Symbol.toStringTag] () {
916
- /* eslint-enable class-methods-use-this */
912
+ /* eslint-enable class-methods-use-this -- Not needed */
917
913
  return 'FileList';
918
914
  }
919
915
  }
@@ -922,7 +918,7 @@ const filelist = {
922
918
  }
923
919
  };
924
920
 
925
- /* globals document, OffscreenCanvas, createImageBitmap */
921
+ /* globals document, OffscreenCanvas, createImageBitmap -- Polyfills */
926
922
  // `ImageBitmap` is browser / DOM specific. It also can only work
927
923
  // same-domain (or CORS)
928
924
 
@@ -1005,7 +1001,7 @@ const imagebitmap = {
1005
1001
  }
1006
1002
  };
1007
1003
 
1008
- /* globals ImageData */
1004
+ /* globals ImageData -- Polyfills */
1009
1005
  // `ImageData` is browser / DOM specific (though `node-canvas` has it
1010
1006
  // available on `Canvas`).
1011
1007
 
@@ -1163,7 +1159,7 @@ const nonbuiltinIgnore = {
1163
1159
 
1164
1160
  // This module is for objectified primitives (such as `new Number(3)` or
1165
1161
  // `new String("foo")`)
1166
- /* eslint-disable no-new-wrappers, unicorn/new-for-builtins */
1162
+ /* eslint-disable no-new-wrappers, unicorn/new-for-builtins -- Deliberate */
1167
1163
 
1168
1164
  /**
1169
1165
  * @type {import('typeson').TypeSpecSet}
@@ -1183,7 +1179,10 @@ const primitiveObjects = {
1183
1179
  return toStringTag(x) === 'Boolean' &&
1184
1180
  typeof x === 'object';
1185
1181
  },
1186
- replace: Boolean, // convert to primitive boolean
1182
+ replace (o) {
1183
+ // convert to primitive boolean
1184
+ return o.valueOf();
1185
+ },
1187
1186
  revive (b) {
1188
1187
  // Revive to an objectified Boolean
1189
1188
  return new Boolean(b);
@@ -1199,6 +1198,35 @@ const primitiveObjects = {
1199
1198
  }
1200
1199
  };
1201
1200
 
1201
+ /**
1202
+ * @type {import('typeson').TypeSpecSet}
1203
+ */
1204
+ const promise = {
1205
+ promise: {
1206
+ test (x) {
1207
+ return toStringTag(x) === 'Promise';
1208
+ },
1209
+ replaceAsync (prom) {
1210
+ return new e(async (resolve) => {
1211
+ try {
1212
+ resolve({
1213
+ value: await prom
1214
+ });
1215
+ } catch (error) {
1216
+ resolve({
1217
+ error
1218
+ });
1219
+ }
1220
+ });
1221
+ },
1222
+ revive (o) {
1223
+ return o.error
1224
+ ? Promise.reject(o.error)
1225
+ : Promise.resolve(o.value);
1226
+ }
1227
+ }
1228
+ };
1229
+
1202
1230
  /**
1203
1231
  * @type {import('typeson').TypeSpecSet}
1204
1232
  */
@@ -1266,7 +1294,25 @@ const set = {
1266
1294
  }
1267
1295
  };
1268
1296
 
1269
- /* eslint-env browser, node */
1297
+ /**
1298
+ * @type {import('typeson').TypeSpecSet}
1299
+ */
1300
+ const symbol = {
1301
+ symbol: {
1302
+ test (x) {
1303
+ return typeof x === 'symbol';
1304
+ },
1305
+ replace (sym) {
1306
+ return {
1307
+ global: Symbol.keyFor(sym) !== undefined,
1308
+ sym: String(sym).slice(7, -1)
1309
+ };
1310
+ },
1311
+ revive (o) {
1312
+ return o.global ? Symbol.for(o.sym) : Symbol(o.sym);
1313
+ }
1314
+ }
1315
+ };
1270
1316
 
1271
1317
  // Support all kinds of typed arrays (views of ArrayBuffers)
1272
1318
 
@@ -1334,8 +1380,6 @@ if (typeof Int8Array === 'function') {
1334
1380
  ].forEach((TypedArray) => create$1(TypedArray));
1335
1381
  }
1336
1382
 
1337
- /* eslint-env browser, node */
1338
-
1339
1383
  /**
1340
1384
  * @type {import('typeson').TypeSpecSet}
1341
1385
  */
@@ -1792,5 +1836,5 @@ const universal = [
1792
1836
  // built-in into ecmasript standard.
1793
1837
  ];
1794
1838
 
1795
- export { u as JSON_TYPES, c as Typeson, e as TypesonPromise, s as Undefined, arrayNonindexKeys, arraybuffer, bigint, bigintObject, blob, expObj$1 as builtin, cloneable, cryptokey, dataview, date, domexception, dommatrix, dompoint, domquad, domrect, error, errors, escapeKeyPathComponent, file, filelist, getByKeyPath, getJSONType, hasConstructorOf, imagebitmap, imagedata, infinity, intlTypes, isObject, isPlainObject, isThenable, isUserObject, map, nan, negativeInfinity, negativeZero, nonbuiltinIgnore, postmessage, primitiveObjects, regexp, resurrectable, set, setAtKeyPath, socketio, sparseUndefined, specialNumbers, expObj as structuredCloning, structuredCloningThrowing, toStringTag, typedArrays, typedArraysSocketIO as typedArraysSocketio, undef$1 as undef, undef as undefPreset, unescapeKeyPathComponent, universal, userObject };
1839
+ export { u as JSON_TYPES, c as Typeson, e as TypesonPromise, s as Undefined, arrayNonindexKeys, arraybuffer, bigint, bigintObject, blob, expObj$1 as builtin, cloneable, cryptokey, dataview, date, domexception, dommatrix, dompoint, domquad, domrect, error, errors, escapeKeyPathComponent, file, filelist, getByKeyPath, getJSONType, hasConstructorOf, imagebitmap, imagedata, infinity, intlTypes, isObject, isPlainObject, isThenable, isUserObject, map, nan, negativeInfinity, negativeZero, nonbuiltinIgnore, postmessage, primitiveObjects, promise, regexp, resurrectable, set, setAtKeyPath, socketio, sparseUndefined, specialNumbers, expObj as structuredCloning, structuredCloningThrowing, symbol, toStringTag, typedArrays, typedArraysSocketIO as typedArraysSocketio, undef$1 as undef, undef as undefPreset, unescapeKeyPathComponent, universal, userObject };
1796
1840
  //# sourceMappingURL=index.js.map