json-6 1.0.8 → 1.1.4
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 +26 -1
- package/dist/index.js +244 -17
- package/dist/index.min.js +1 -1
- package/dist/index.min.mjs +1 -1
- package/dist/index.mjs +243 -16
- package/lib/cli.js +0 -0
- package/lib/import.mjs +92 -0
- package/lib/json6.js +222 -3
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# JSON6 – JSON for Humans
|
|
2
2
|
|
|
3
|
-
[](https://travis-ci.com/d3x0r/JSON6)
|
|
4
4
|
|
|
5
5
|
[](https://gitter.im/sack-vfs/json6?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
|
|
6
6
|
|
|
@@ -399,8 +399,33 @@ Feel free to [file issues](https://github.com/d3x0r/json6/issues) and submit
|
|
|
399
399
|
welcome. If you do submit a pull request, please be sure to add or update the
|
|
400
400
|
tests, and ensure that `npm test` continues to pass.
|
|
401
401
|
|
|
402
|
+
## Continuous Integration Testing
|
|
403
|
+
|
|
404
|
+
Travis CI is used to automatically test the package when pushed to github. Recently .mjs tests have been
|
|
405
|
+
added, and rather than 1) build a switch to test `mocha/test/*.js` instead of just `*`, and 2) depending on node version
|
|
406
|
+
switch the test command which is run, the older platforms were removed from testing.
|
|
407
|
+
|
|
408
|
+
The product of this should run on very old platforms also, especially `node_modules/json-6/dist/index.min.js`.
|
|
409
|
+
|
|
402
410
|
|
|
403
411
|
## Changelog
|
|
412
|
+
|
|
413
|
+
- 1.1.5(pre)
|
|
414
|
+
- 1.1.4
|
|
415
|
+
- fixes benchmark test for hex number conversion
|
|
416
|
+
- 1.1.3
|
|
417
|
+
- fixes '\v' decoding.
|
|
418
|
+
- fixes parsing hex numbers with a-f.
|
|
419
|
+
- 1.1.2
|
|
420
|
+
- Updated document about CI tests.
|
|
421
|
+
- added tests from sack.vfs JSON6 updates.
|
|
422
|
+
- 1.1.1
|
|
423
|
+
- Added stringifier
|
|
424
|
+
- emits unquoted object field names, if valid to be unquoted.
|
|
425
|
+
- emits Infinity
|
|
426
|
+
- emits NaN
|
|
427
|
+
- Added forgiving '+' collection for numbers.
|
|
428
|
+
- Improved(implemented) node module loader interface `lib/import.mjs` which enables `.json6` extension for import.
|
|
404
429
|
- 1.0.8
|
|
405
430
|
- throw error when streaming, and an error is encountered, persist throwing on new writes.
|
|
406
431
|
- 1.0.7
|
package/dist/index.js
CHANGED
|
@@ -6,18 +6,8 @@
|
|
|
6
6
|
|
|
7
7
|
var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
|
|
8
8
|
|
|
9
|
-
function createCommonjsModule(fn,
|
|
10
|
-
return module = {
|
|
11
|
-
path: basedir,
|
|
12
|
-
exports: {},
|
|
13
|
-
require: function (path, base) {
|
|
14
|
-
return commonjsRequire(path, (base === undefined || base === null) ? module.path : base);
|
|
15
|
-
}
|
|
16
|
-
}, fn(module, module.exports), module.exports;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
function commonjsRequire () {
|
|
20
|
-
throw new Error('Dynamic requires are not currently supported by @rollup/plugin-commonjs');
|
|
9
|
+
function createCommonjsModule(fn, module) {
|
|
10
|
+
return module = { exports: {} }, fn(module, module.exports), module.exports;
|
|
21
11
|
}
|
|
22
12
|
|
|
23
13
|
var check = function (it) {
|
|
@@ -219,7 +209,7 @@
|
|
|
219
209
|
(module.exports = function (key, value) {
|
|
220
210
|
return sharedStore[key] || (sharedStore[key] = value !== undefined ? value : {});
|
|
221
211
|
})('versions', []).push({
|
|
222
|
-
version: '3.6.
|
|
212
|
+
version: '3.6.4',
|
|
223
213
|
mode: 'global',
|
|
224
214
|
copyright: '© 2020 Denis Pushkarev (zloirock.ru)'
|
|
225
215
|
});
|
|
@@ -634,6 +624,7 @@
|
|
|
634
624
|
|
|
635
625
|
var json6 = createCommonjsModule(function (module, exports) {
|
|
636
626
|
|
|
627
|
+
const version = "1.1.1";
|
|
637
628
|
const VALUE_UNDEFINED = -1;
|
|
638
629
|
const VALUE_UNSET = 0;
|
|
639
630
|
const VALUE_NULL = 1;
|
|
@@ -741,11 +732,13 @@
|
|
|
741
732
|
if (!string) return string;
|
|
742
733
|
|
|
743
734
|
for (let n = 0; n < string.length; n++) {
|
|
744
|
-
|
|
735
|
+
const ch = string[n];
|
|
736
|
+
|
|
737
|
+
if (ch == '"' || ch == '\\' || ch == '`' || ch == '\'') {
|
|
745
738
|
output += '\\';
|
|
746
739
|
}
|
|
747
740
|
|
|
748
|
-
output +=
|
|
741
|
+
output += ch;
|
|
749
742
|
}
|
|
750
743
|
|
|
751
744
|
return output;
|
|
@@ -1268,6 +1261,12 @@
|
|
|
1268
1261
|
val.string += '\f';
|
|
1269
1262
|
break;
|
|
1270
1263
|
|
|
1264
|
+
case 118
|
|
1265
|
+
/*'v'*/
|
|
1266
|
+
:
|
|
1267
|
+
val.string += '\v';
|
|
1268
|
+
break;
|
|
1269
|
+
|
|
1271
1270
|
case 120
|
|
1272
1271
|
/*'x'*/
|
|
1273
1272
|
:
|
|
@@ -1359,7 +1358,17 @@
|
|
|
1359
1358
|
status = false;
|
|
1360
1359
|
throwError("fault while parsing number;", cInt); // break;
|
|
1361
1360
|
}
|
|
1362
|
-
} else if (cInt
|
|
1361
|
+
} else if (fromHex && (cInt >= 95
|
|
1362
|
+
/*'a'*/
|
|
1363
|
+
&& cInt <= 102
|
|
1364
|
+
/*'f'*/
|
|
1365
|
+
|| cInt >= 65
|
|
1366
|
+
/*'A'*/
|
|
1367
|
+
&& cInt <= 70
|
|
1368
|
+
/*'F'*/
|
|
1369
|
+
)) {
|
|
1370
|
+
val.string += str;
|
|
1371
|
+
} else if (cInt == 120
|
|
1363
1372
|
/*'x'*/
|
|
1364
1373
|
|| cInt == 98
|
|
1365
1374
|
/*'b'*/
|
|
@@ -1995,6 +2004,16 @@
|
|
|
1995
2004
|
throwError("fault parsing", cInt);
|
|
1996
2005
|
} // fault
|
|
1997
2006
|
|
|
2007
|
+
break;
|
|
2008
|
+
|
|
2009
|
+
case 43:
|
|
2010
|
+
//'+':
|
|
2011
|
+
if (word !== WORD_POS_RESET) {
|
|
2012
|
+
status = false;
|
|
2013
|
+
throwError("fault parsing", cInt);
|
|
2014
|
+
} // fault
|
|
2015
|
+
|
|
2016
|
+
|
|
1998
2017
|
break;
|
|
1999
2018
|
//
|
|
2000
2019
|
//----------------------------------------------------------
|
|
@@ -2168,7 +2187,215 @@
|
|
|
2168
2187
|
return undefined;
|
|
2169
2188
|
};
|
|
2170
2189
|
|
|
2171
|
-
JSON6.stringify = JSON.stringify;
|
|
2190
|
+
JSON6.stringify = JSON.stringify; //---------------------------------------------------------------------------
|
|
2191
|
+
// Stringify
|
|
2192
|
+
//---------------------------------------------------------------------------
|
|
2193
|
+
|
|
2194
|
+
JSON6.stringifierActive = null;
|
|
2195
|
+
|
|
2196
|
+
JSON6.stringifier = function () {
|
|
2197
|
+
const keywords = {
|
|
2198
|
+
["true"]: true,
|
|
2199
|
+
["false"]: false,
|
|
2200
|
+
["null"]: null,
|
|
2201
|
+
["NaN"]: NaN,
|
|
2202
|
+
["Infinity"]: Infinity,
|
|
2203
|
+
["undefined"]: undefined
|
|
2204
|
+
};
|
|
2205
|
+
let useQuote = '"';
|
|
2206
|
+
let ignoreNonEnumerable = false;
|
|
2207
|
+
return {
|
|
2208
|
+
stringify(o, r, s, as) {
|
|
2209
|
+
return stringify(this, o, r, s, as);
|
|
2210
|
+
},
|
|
2211
|
+
|
|
2212
|
+
setQuote(q) {
|
|
2213
|
+
useQuote = q;
|
|
2214
|
+
},
|
|
2215
|
+
|
|
2216
|
+
get ignoreNonEnumerable() {
|
|
2217
|
+
return ignoreNonEnumerable;
|
|
2218
|
+
},
|
|
2219
|
+
|
|
2220
|
+
set ignoreNonEnumerable(val) {
|
|
2221
|
+
ignoreNonEnumerable = val;
|
|
2222
|
+
}
|
|
2223
|
+
|
|
2224
|
+
};
|
|
2225
|
+
|
|
2226
|
+
function getIdentifier(s) {
|
|
2227
|
+
if ("number" === typeof s && !isNaN(s)) {
|
|
2228
|
+
return ["'", s.toString(), "'"].join();
|
|
2229
|
+
}
|
|
2230
|
+
|
|
2231
|
+
if (!s.length) return useQuote + useQuote; // should check also for if any non ident in string...
|
|
2232
|
+
|
|
2233
|
+
return s in keywords
|
|
2234
|
+
/* [ "true","false","null","NaN","Infinity","undefined"].find( keyword=>keyword===s )*/
|
|
2235
|
+
|| /([0-9-])/.test(s[0]) || /((\n|\r|\t)|[ #{}()<>!+\-*/.:,])/.test(s) ? useQuote + JSON6.escape(s) + useQuote : s;
|
|
2236
|
+
}
|
|
2237
|
+
|
|
2238
|
+
function stringify(stringifier, object, replacer, space, asField) {
|
|
2239
|
+
if (object === undefined) return "undefined";
|
|
2240
|
+
if (object === null) return "null";
|
|
2241
|
+
let gap;
|
|
2242
|
+
let indent;
|
|
2243
|
+
let i;
|
|
2244
|
+
const spaceType = typeof space;
|
|
2245
|
+
const repType = typeof replacer;
|
|
2246
|
+
gap = "";
|
|
2247
|
+
indent = "";
|
|
2248
|
+
const stringifier_ = JSON6.stringifierActive;
|
|
2249
|
+
JSON6.stringifierActive = stringifier;
|
|
2250
|
+
|
|
2251
|
+
if (!asField) {
|
|
2252
|
+
asField = "";
|
|
2253
|
+
} // If the space parameter is a number, make an indent string containing that
|
|
2254
|
+
// many spaces.
|
|
2255
|
+
|
|
2256
|
+
|
|
2257
|
+
if (spaceType === "number") {
|
|
2258
|
+
for (i = 0; i < space; i += 1) {
|
|
2259
|
+
indent += " ";
|
|
2260
|
+
} // If the space parameter is a string, it will be used as the indent string.
|
|
2261
|
+
|
|
2262
|
+
} else if (spaceType === "string") {
|
|
2263
|
+
indent = space;
|
|
2264
|
+
} // If there is a replacer, it must be a function or an array.
|
|
2265
|
+
// Otherwise, throw an error.
|
|
2266
|
+
|
|
2267
|
+
|
|
2268
|
+
const rep = replacer;
|
|
2269
|
+
|
|
2270
|
+
if (replacer && repType !== "function" && (repType !== "object" || typeof replacer.length !== "number")) {
|
|
2271
|
+
throw new Error("JSON6.stringify unknown replacer type.");
|
|
2272
|
+
}
|
|
2273
|
+
|
|
2274
|
+
const r = str(asField, {
|
|
2275
|
+
[asField]: object
|
|
2276
|
+
});
|
|
2277
|
+
JSON6.stringifierActive = stringifier_; //DEBUG_STRINGIFY_OUTPUT && console.trace( "Stringify Result:", r );
|
|
2278
|
+
|
|
2279
|
+
return r; // from https://github.com/douglascrockford/JSON-js/blob/master/json2.js#L181
|
|
2280
|
+
|
|
2281
|
+
function str(key, holder) {
|
|
2282
|
+
// Produce a string from holder[key].
|
|
2283
|
+
let i; // The loop counter.
|
|
2284
|
+
|
|
2285
|
+
let k; // The member key.
|
|
2286
|
+
|
|
2287
|
+
let v; // The member value.
|
|
2288
|
+
|
|
2289
|
+
let length;
|
|
2290
|
+
const mind = gap;
|
|
2291
|
+
let partial;
|
|
2292
|
+
let value = holder[key];
|
|
2293
|
+
if ("string" === typeof value) value = getIdentifier(value);
|
|
2294
|
+
|
|
2295
|
+
if (value !== undefined && value !== null && typeof value === "object" && typeof toJSOX === "function") {
|
|
2296
|
+
// is encoding?
|
|
2297
|
+
gap += indent;
|
|
2298
|
+
gap = mind;
|
|
2299
|
+
} // If we were called with a replacer function, then call the replacer to
|
|
2300
|
+
// obtain a replacement value.
|
|
2301
|
+
|
|
2302
|
+
|
|
2303
|
+
if (typeof rep === "function") {
|
|
2304
|
+
value = rep.call(holder, key, value);
|
|
2305
|
+
} // What happens next depends on the value's type.
|
|
2306
|
+
|
|
2307
|
+
|
|
2308
|
+
switch (typeof value) {
|
|
2309
|
+
case "string":
|
|
2310
|
+
return value;
|
|
2311
|
+
|
|
2312
|
+
case "number":
|
|
2313
|
+
return '' + value;
|
|
2314
|
+
//useQuote+JSOX.escape( value )+useQuote;
|
|
2315
|
+
|
|
2316
|
+
case "boolean":
|
|
2317
|
+
return String(value);
|
|
2318
|
+
|
|
2319
|
+
case "object":
|
|
2320
|
+
//_DEBUG_STRINGIFY && console.log( "ENTERING OBJECT EMISSION WITH:", v );
|
|
2321
|
+
//if( v ) return v;
|
|
2322
|
+
// Due to a specification blunder in ECMAScript, typeof null is "object",
|
|
2323
|
+
// so watch out for that case.
|
|
2324
|
+
if (!value) {
|
|
2325
|
+
return "null";
|
|
2326
|
+
} // Make an array to hold the partial results of stringifying this object value.
|
|
2327
|
+
|
|
2328
|
+
|
|
2329
|
+
gap += indent;
|
|
2330
|
+
partial = []; // If the replacer is an array, use it to select the members to be stringified.
|
|
2331
|
+
|
|
2332
|
+
if (rep && typeof rep === "object") {
|
|
2333
|
+
length = rep.length; //_DEBUG_STRINGIFY && console.log( "Working through replacer" );
|
|
2334
|
+
|
|
2335
|
+
for (i = 0; i < length; i += 1) {
|
|
2336
|
+
if (typeof rep[i] === "string") {
|
|
2337
|
+
k = rep[i];
|
|
2338
|
+
v = str(k, value);
|
|
2339
|
+
|
|
2340
|
+
if (v) {
|
|
2341
|
+
partial.push(getIdentifier(k) + (gap ? ": " : ":") + v);
|
|
2342
|
+
}
|
|
2343
|
+
}
|
|
2344
|
+
}
|
|
2345
|
+
} else {
|
|
2346
|
+
// Otherwise, iterate through all of the keys in the object.
|
|
2347
|
+
const keys = []; //_DEBUG_STRINGIFY && console.log( "is something in something?", k, value );
|
|
2348
|
+
|
|
2349
|
+
for (k in value) {
|
|
2350
|
+
if (ignoreNonEnumerable) if (!Object.prototype.propertyIsEnumerable.call(value, k)) {
|
|
2351
|
+
//_DEBUG_STRINGIFY && console.log( "skipping non-enuerable?", k );
|
|
2352
|
+
continue;
|
|
2353
|
+
} // sort properties into keys.
|
|
2354
|
+
|
|
2355
|
+
if (Object.prototype.hasOwnProperty.call(value, k)) {
|
|
2356
|
+
let n;
|
|
2357
|
+
|
|
2358
|
+
for (n = 0; n < keys.length; n++) if (keys[n] > k) {
|
|
2359
|
+
keys.splice(n, 0, k);
|
|
2360
|
+
break;
|
|
2361
|
+
}
|
|
2362
|
+
|
|
2363
|
+
if (n === keys.length) keys.push(k);
|
|
2364
|
+
}
|
|
2365
|
+
} //_DEBUG_STRINGIFY && console.log( "Expanding object keys:", v, keys );
|
|
2366
|
+
|
|
2367
|
+
|
|
2368
|
+
for (let n = 0; n < keys.length; n++) {
|
|
2369
|
+
k = keys[n];
|
|
2370
|
+
|
|
2371
|
+
if (Object.prototype.hasOwnProperty.call(value, k)) {
|
|
2372
|
+
v = str(k, value);
|
|
2373
|
+
|
|
2374
|
+
if (v) {
|
|
2375
|
+
partial.push(getIdentifier(k) + (gap ? ": " : ":") + v);
|
|
2376
|
+
}
|
|
2377
|
+
}
|
|
2378
|
+
}
|
|
2379
|
+
} // Join all of the member texts together, separated with commas,
|
|
2380
|
+
// and wrap them in braces.
|
|
2381
|
+
//_DEBUG_STRINGIFY && console.log( "partial:", partial, protoConverter )
|
|
2382
|
+
|
|
2383
|
+
|
|
2384
|
+
v = '' + (partial.length === 0 ? "{}" : gap ? "{\n" + gap + partial.join(",\n" + gap) + "\n" + mind + "}" : "{" + partial.join(",") + "}");
|
|
2385
|
+
gap = mind; //_DEBUG_STRINGIFY && console.log(" Resulting phrase from this part is:", v );
|
|
2386
|
+
|
|
2387
|
+
return v;
|
|
2388
|
+
}
|
|
2389
|
+
}
|
|
2390
|
+
}
|
|
2391
|
+
};
|
|
2392
|
+
|
|
2393
|
+
JSON6.stringify = function (object, replacer, space) {
|
|
2394
|
+
const stringifier = JSON6.stringifier();
|
|
2395
|
+
return stringifier.stringify(object, replacer, space);
|
|
2396
|
+
};
|
|
2397
|
+
|
|
2398
|
+
JSON6.version = version;
|
|
2172
2399
|
});
|
|
2173
2400
|
|
|
2174
2401
|
var lib = json6;
|
package/dist/index.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e=e||self).JSON5=t()}(this,(function(){"use strict";var e="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function t(e,t,n){return e(n={path:t,exports:{},require:function(e,t){return function(){throw new Error("Dynamic requires are not currently supported by @rollup/plugin-commonjs")}(null==t&&n.path)}},n.exports),n.exports}var n=function(e){return e&&e.Math==Math&&e},r=n("object"==typeof globalThis&&globalThis)||n("object"==typeof window&&window)||n("object"==typeof self&&self)||n("object"==typeof e&&e)||Function("return this")(),a=function(e){try{return!!e()}catch(e){return!0}},i=!a((function(){return 7!=Object.defineProperty({},1,{get:function(){return 7}})[1]})),o={}.propertyIsEnumerable,s=Object.getOwnPropertyDescriptor,c={f:s&&!o.call({1:2},1)?function(e){var t=s(this,e);return!!t&&t.enumerable}:o},u=function(e,t){return{enumerable:!(1&e),configurable:!(2&e),writable:!(4&e),value:t}},l={}.toString,f="".split,p=a((function(){return!Object("z").propertyIsEnumerable(0)}))?function(e){return"String"==function(e){return l.call(e).slice(8,-1)}(e)?f.call(e,""):Object(e)}:Object,h=function(e){if(null==e)throw TypeError("Can't call method on "+e);return e},g=function(e){return p(h(e))},d=function(e){return"object"==typeof e?null!==e:"function"==typeof e},b=function(e,t){if(!d(e))return e;var n,r;if(t&&"function"==typeof(n=e.toString)&&!d(r=n.call(e)))return r;if("function"==typeof(n=e.valueOf)&&!d(r=n.call(e)))return r;if(!t&&"function"==typeof(n=e.toString)&&!d(r=n.call(e)))return r;throw TypeError("Can't convert object to primitive value")},y={}.hasOwnProperty,v=function(e,t){return y.call(e,t)},m=r.document,k=d(m)&&d(m.createElement),w=!i&&!a((function(){return 7!=Object.defineProperty((e="div",k?m.createElement(e):{}),"a",{get:function(){return 7}}).a;var e})),_=Object.getOwnPropertyDescriptor,x={f:i?_:function(e,t){if(e=g(e),t=b(t,!0),w)try{return _(e,t)}catch(e){}if(v(e,t))return u(!c.f.call(e,t),e[t])}},S=function(e){if(!d(e))throw TypeError(String(e)+" is not an object");return e},j=Object.defineProperty,O={f:i?j:function(e,t,n){if(S(e),t=b(t,!0),S(n),w)try{return j(e,t,n)}catch(e){}if("get"in n||"set"in n)throw TypeError("Accessors not supported");return"value"in n&&(e[t]=n.value),e}},P=i?function(e,t,n){return O.f(e,t,u(1,n))}:function(e,t,n){return e[t]=n,e},E=function(e,t){try{P(r,e,t)}catch(n){r[e]=t}return t},A=r["__core-js_shared__"]||E("__core-js_shared__",{}),C=Function.toString;"function"!=typeof A.inspectSource&&(A.inspectSource=function(e){return C.call(e)});var N,T,$,I,M=A.inspectSource,F=r.WeakMap,q="function"==typeof F&&/native code/.test(M(F)),z=t((function(e){(e.exports=function(e,t){return A[e]||(A[e]=void 0!==t?t:{})})("versions",[]).push({version:"3.6.5",mode:"global",copyright:"© 2020 Denis Pushkarev (zloirock.ru)"})})),L=0,D=Math.random(),W=z("keys"),G={},J=r.WeakMap;if(q){var R=new J,U=R.get,K=R.has,V=R.set;N=function(e,t){return V.call(R,e,t),t},T=function(e){return U.call(R,e)||{}},$=function(e){return K.call(R,e)}}else{var Y=W[I="state"]||(W[I]=function(e){return"Symbol("+String(void 0===e?"":e)+")_"+(++L+D).toString(36)}(I));G[Y]=!0,N=function(e,t){return P(e,Y,t),t},T=function(e){return v(e,Y)?e[Y]:{}},$=function(e){return v(e,Y)}}var B={set:N,get:T,has:$,enforce:function(e){return $(e)?T(e):N(e,{})},getterFor:function(e){return function(t){var n;if(!d(t)||(n=T(t)).type!==e)throw TypeError("Incompatible receiver, "+e+" required");return n}}},H=t((function(e){var t=B.get,n=B.enforce,a=String(String).split("String");(e.exports=function(e,t,i,o){var s=!!o&&!!o.unsafe,c=!!o&&!!o.enumerable,u=!!o&&!!o.noTargetGet;"function"==typeof i&&("string"!=typeof t||v(i,"name")||P(i,"name",t),n(i).source=a.join("string"==typeof t?t:"")),e!==r?(s?!u&&e[t]&&(c=!0):delete e[t],c?e[t]=i:P(e,t,i)):c?e[t]=i:E(t,i)})(Function.prototype,"toString",(function(){return"function"==typeof this&&t(this).source||M(this)}))})),Q=r,X=function(e){return"function"==typeof e?e:void 0},Z=Math.ceil,ee=Math.floor,te=function(e){return isNaN(e=+e)?0:(e>0?ee:Z)(e)},ne=Math.min,re=Math.max,ae=Math.min,ie=function(e,t){var n=te(e);return n<0?re(n+t,0):ae(n,t)},oe=function(e){return function(t,n,r){var a,i,o=g(t),s=(a=o.length)>0?ne(te(a),9007199254740991):0,c=ie(r,s);if(e&&n!=n){for(;s>c;)if((i=o[c++])!=i)return!0}else for(;s>c;c++)if((e||c in o)&&o[c]===n)return e||c||0;return!e&&-1}},se={includes:oe(!0),indexOf:oe(!1)}.indexOf,ce=["constructor","hasOwnProperty","isPrototypeOf","propertyIsEnumerable","toLocaleString","toString","valueOf"].concat("length","prototype"),ue={f:Object.getOwnPropertyNames||function(e){return function(e,t){var n,r=g(e),a=0,i=[];for(n in r)!v(G,n)&&v(r,n)&&i.push(n);for(;t.length>a;)v(r,n=t[a++])&&(~se(i,n)||i.push(n));return i}(e,ce)}},le={f:Object.getOwnPropertySymbols},fe=function(e,t){return arguments.length<2?X(Q[e])||X(r[e]):Q[e]&&Q[e][t]||r[e]&&r[e][t]}("Reflect","ownKeys")||function(e){var t=ue.f(S(e)),n=le.f;return n?t.concat(n(e)):t},pe=function(e,t){for(var n=fe(t),r=O.f,a=x.f,i=0;i<n.length;i++){var o=n[i];v(e,o)||r(e,o,a(t,o))}},he=/#|\.prototype\./,ge=function(e,t){var n=be[de(e)];return n==ve||n!=ye&&("function"==typeof t?a(t):!!t)},de=ge.normalize=function(e){return String(e).replace(he,".").toLowerCase()},be=ge.data={},ye=ge.NATIVE="N",ve=ge.POLYFILL="P",me=ge,ke=x.f,we=function(e,t){var n,a,i,o,s,c=e.target,u=e.global,l=e.stat;if(n=u?r:l?r[c]||E(c,{}):(r[c]||{}).prototype)for(a in t){if(o=t[a],i=e.noTargetGet?(s=ke(n,a))&&s.value:n[a],!me(u?a:c+(l?".":"#")+a,e.forced)&&void 0!==i){if(typeof o==typeof i)continue;pe(o,i)}(e.sham||i&&i.sham)&&P(o,"sham",!0),H(n,a,o,e)}},_e=function(e){return function(t,n){var r,a,i=String(h(t)),o=te(n),s=i.length;return o<0||o>=s?e?"":void 0:(r=i.charCodeAt(o))<55296||r>56319||o+1===s||(a=i.charCodeAt(o+1))<56320||a>57343?e?i.charAt(o):r:e?i.slice(o,o+2):a-56320+(r-55296<<10)+65536}},xe={codeAt:_e(!1),charAt:_e(!0)}.codeAt;we({target:"String",proto:!0},{codePointAt:function(e){return xe(this,e)}});var Se,je,Oe=function(e,t,n){if(function(e){if("function"!=typeof e)throw TypeError(String(e)+" is not a function")}(e),void 0===t)return e;switch(n){case 0:return function(){return e.call(t)};case 1:return function(n){return e.call(t,n)};case 2:return function(n,r){return e.call(t,n,r)};case 3:return function(n,r,a){return e.call(t,n,r,a)}}return function(){return e.apply(t,arguments)}},Pe=Function.call,Ee=(Se="codePointAt",Oe(Pe,r["String"].prototype[Se],je),String.fromCharCode),Ae=String.fromCodePoint;we({target:"String",stat:!0,forced:!!Ae&&1!=Ae.length},{fromCodePoint:function(e){for(var t,n=[],r=arguments.length,a=0;r>a;){if(t=+arguments[a++],ie(t,1114111)!==t)throw RangeError(t+" is not a valid code point");n.push(t<65536?Ee(t):Ee(55296+((t-=65536)>>10),t%1024+56320))}return n.join("")}});Q.String.fromCodePoint;return t((function(e,t){const n=[];function r(){return n.pop()||{context:0,elements:null,element_array:null}}function a(e){n.push(e)}const i=[];function o(e){i.push(e)}const s=t;s.escape=function(e){let t="";if(!e)return e;for(let n=0;n<e.length;n++)'"'!=e[n]&&"\\"!=e[n]&&"`"!=e[n]&&"'"!=e[n]||(t+="\\"),t+=e[n];return t},s.begin=function(e,t){const n={name:null,value_type:0,string:"",contains:null},s={line:1,col:1};let c=0,u=0,l=!0,f=!1,p=null,h=void 0,g=[],d=0,b=0,y=!1,v=!1,m=!1,k=!1,w=!1,_=null,x=!1,S=!1,j=!1,O=!1,P=!1,E=!1,A=!1,C=0,N=0,T=!1;const $={first:null,last:null,saved:null,push(e){let t=this.saved;t?(this.saved=t.next,t.node=e,t.next=null,t.prior=this.last):t={node:e,next:null,prior:this.last},this.last||(this.first=t),this.last=t},pop(){const e=this.last;return(this.last=e.prior)||(this.first=null),e.next=this.saved,this.saved=e,e.node}},I={first:null,last:null,saved:null,push(e){let t=this.saved;t?(this.saved=t.next,t.node=e,t.next=null,t.prior=this.last):t={node:e,next:null,prior:this.last},this.last?this.last.next=t:this.first=t,this.last=t},shift(){const e=this.first;return e?(this.first=e.next,this.first||(this.last=null),e.next=this.saved,this.saved=e,e.node):null},unshift(e){const t=this.saved;this.saved=t.next,t.node=e,t.next=this.first,t.prior=null,this.first||(this.last=t),this.first=t}};function M(e){throw new Error(`${e} at ${c} [${s.line}:${s.col}]`)}return{finalError(){if(0!==b)switch(b){case 1:return M("Comment began at end of document");case 2:console.log("Warning: '//' comment without end of line ended document");break;case 3:return M("Open comment '/*' is missing close at end of document");case 4:return M("Incomplete '/* *' close at end of document")}x&&M("Incomplete string")},value(){this.finalError();const e=p;return p=void 0,e},reset(){u=0,l=!0,I.last&&(I.last.next=I.save),I.save=I.first,I.first=I.last=null,$.last&&($.last.next=$.save),$.save=I.first,$.first=$.last=null,g=null,h=void 0,d=0,n.value_type=0,n.name=null,n.string="",s.line=1,s.col=1,f=!1,b=0,T=!1,x=!1,j=!1,O=!1},write(n){let r;if(void 0!==n&&"string"!=typeof n&&(n=String(n)),!l)throw new Error("Parser is in an error state, please reset.");for(r=this._write(n,!1);r>0&&(this.finalError(),"function"==typeof t&&function e(n,r){const a=n[r];if(a&&"object"==typeof a)for(const t in a)if(Object.prototype.hasOwnProperty.call(a,t)){const n=e(a,t);void 0!==n?a[t]=n:delete a[t]}return t.call(n,r,a)}({"":p},""),e(p),p=void 0,!(r<2));r=this._write());r&&this.finalError()},_write(e,t){let M,F,q=0;function z(e,t){throw new Error(`${e} '${String.fromCodePoint(t)}' unexpected at ${c} (near '${F.substr(c>4?c-4:0,c>4?3:c-1)}[${String.fromCodePoint(t)}]${F.substr(c,10)}') [${s.line}:${s.col}]`)}function L(){n.value_type=0,n.string=""}function D(){switch(n.value_type){case 5:g.push((f?-1:1)*Number(n.string));break;case 4:g.push(n.string);break;case 2:g.push(!0);break;case 3:g.push(!1);break;case 8:case 9:g.push(NaN);break;case 10:g.push(-1/0);break;case 11:g.push(1/0);break;case 1:g.push(null);break;case-1:g.push(void 0);break;case 13:g.push(void 0),delete g[g.length-1];break;case 6:case 7:g.push(n.contains)}}function W(){switch(n.value_type){case 5:h[n.name]=(f?-1:1)*Number(n.string);break;case 4:h[n.name]=n.string;break;case 2:h[n.name]=!0;break;case 3:h[n.name]=!1;break;case 8:case 9:h[n.name]=NaN;break;case 10:h[n.name]=-1/0;break;case 11:h[n.name]=1/0;break;case 1:h[n.name]=null;break;case-1:h[n.name]=void 0;break;case 6:case 7:h[n.name]=n.contains}}function G(e){let t=0;for(;0==t&&c<F.length;){let r=F.charAt(c);const a=F.codePointAt(c++);if(a>=65536&&(r+=F.charAt(c),c++),s.col++,a==e)j?(A?z("Incomplete hexidecimal sequence",a):P?z("Incomplete long unicode sequence",a):E&&z("Incomplete unicode sequence",a),O?(O=!1,t=1):n.string+=r,j=!1):t=1;else if(j){if(P){if(125==a){n.string+=String.fromCodePoint(C),P=!1,E=!1,j=!1;continue}C*=16,a>=48&&a<=57?C+=a-48:a>=65&&a<=70?C+=a-65+10:a>=97&&a<=102?C+=a-97+10:z("(escaped character, parsing hex of \\u)",a);continue}if(A||E){if(0===N&&123===a){P=!0;continue}C*=16,a>=48&&a<=57?C+=a-48:a>=65&&a<=70?C+=a-65+10:a>=97&&a<=102?C+=a-97+10:z(E?"(escaped character, parsing hex of \\u)":"(escaped character, parsing hex of \\x)",a),N++,E?4==N&&(n.string+=String.fromCodePoint(C),E=!1,j=!1):2==N&&(n.string+=String.fromCodePoint(C),A=!1,j=!1);continue}switch(a){case 13:O=!0,s.col=1;continue;case 8232:case 8233:s.col=1;case 10:O?O=!1:s.col=1,s.line++;break;case 116:n.string+="\t";break;case 98:n.string+="\b";break;case 48:n.string+="\0";break;case 110:n.string+="\n";break;case 114:n.string+="\r";break;case 102:n.string+="\f";break;case 120:A=!0,N=0,C=0;continue;case 117:E=!0,N=0,C=0;continue;default:n.string+=r}j=!1}else 92===a?j=!0:(O&&(O=!1,s.line++,s.col=2),n.string+=r)}return t}function J(){let e;for(;(e=c)<F.length;){const r=F.charAt(e),a=F.codePointAt(c++);if(a>=65536&&z("fault while parsing number;",a),95!=a)if(s.col++,a>=48&&a<=57)m&&(w=!0),n.string+=r;else if(45==a||43==a)0==n.string.length||m&&!k&&!w?(n.string+=r,k=!0):(l=!1,z("fault while parsing number;",a));else if(46==a)v||y||m?(l=!1,z("fault while parsing number;",a)):(n.string+=r,v=!0);else if(120==a||98==a||111==a||88==a||66==a||79==a)y||"0"!=n.string?(l=!1,z("fault while parsing number;",a)):(y=!0,n.string+=r);else{if(101!=a&&69!=a){if(32==a||160==a||13==a||10==a||9==a||65279==a||44==a||125==a||93==a||58==a)break;t&&(l=!1,z("fault while parsing number;",a));break}m?(l=!1,z("fault while parsing number;",a)):(n.string+=r,m=!0)}}c=e,t||c!=F.length?(S=!1,n.value_type=5,0==d&&(T=!0)):S=!0}if(!l)return-1;if(e&&e.length)M=function(){let e=i.pop();return e?e.n=0:e={buf:null,n:0},e}(),M.buf=e,I.push(M);else if(S){if(S=!1,n.value_type=5,0!=d)throw new Error("context stack is not empty at flush");T=!0,q=1}for(;l&&(M=I.shift());){if(c=M.n,F=M.buf,x){G(_)>0&&(x=!1,n.value_type=4)}for(S&&J();!T&&l&&c<F.length;){let e=F.charAt(c);const t=F.codePointAt(c++);if(t>=65536&&(e+=F.charAt(c),c++),s.col++,b)1==b?42==t?b=3:47!=t?z("fault while parsing;",t):b=2:2==b?10!=t&&13!=t||(b=0):3==b?42==t&&(b=4):b=47==t?0:3;else{switch(t){case 47:b=1;break;case 123:(29==u||30==u||3==d&&0==u)&&z("fault while parsing; getting field name unexpected ",t);{const e=r();n.value_type=6;const t={};0==d&&(p=h=t),e.context=d,e.elements=h,e.element_array=g,e.name=n.name,h=t,$.push(e),L(),d=3}break;case 91:if(3!=d&&29!=u&&30!=u||z("Fault while parsing; while getting field name unexpected",t),0==n.value_type||-1==n.value_type){const e=r();n.value_type=7;const t=[];0==d?p=g=t:4==d&&(h[n.name]=t),e.context=d,e.elements=h,e.element_array=g,e.name=n.name,g=t,$.push(e),L(),d=1}else z("Unexpected array open after previous value",t);break;case 58:3==d?(u=0,n.name=n.string,n.string="",d=4,n.value_type=0):z(1==d?"(in array, got colon out of string):parsing fault;":"(outside any object, got colon out of string):parsing fault;",t);break;case 125:if(31==u&&(u=0),3==d){n.value_type=6,n.contains=h;const e=$.pop();n.name=e.name,d=e.context,h=e.elements,g=e.element_array,a(e),0==d&&(T=!0)}else if(4==d){0!=n.value_type?W():z("Fault while parsing field value, close with no value",t),n.value_type=6,n.contains=h;const e=$.pop();n.name=e.name,d=e.context,h=e.elements,g=e.element_array,a(e),0==d&&(T=!0)}else z("Fault while parsing; unexpected",t);f=!1;break;case 93:if(31==u&&(u=0),1==d){0!=n.value_type&&D(),n.value_type=7,n.contains=g;{const e=$.pop();n.name=e.name,d=e.context,h=e.elements,g=e.element_array,a(e)}0==d&&(T=!0)}else z(`bad context ${d}; fault while parsing`,t);f=!1;break;case 44:31==u&&(u=0),1==d?(0==n.value_type&&(n.value_type=13),D(),L()):4==d?(d=3,0!=n.value_type?(W(),L()):z("Unexpected comma after object field name",t)):(l=!1,z("bad context; excessive commas while parsing;",t)),f=!1;break;default:if(3==d)switch(t){case 96:case 34:case 39:if(0==u){0!=n.value_type&&z("String begin after previous value",t);G(t)?n.value_type=4:(_=t,x=!0)}else z("fault while parsing; quote not at start of field name",t);break;case 10:s.line++,s.col=1;case 13:case 32:case 160:case 9:case 65279:31==u?u=0:29==u&&(u=30);break;default:30==u&&(l=!1,z("fault while parsing; character unexpected",t)),0==u&&(u=29),n.string+=e}else switch(t){case 96:case 34:case 39:if(0===n.value_type){G(t)?(n.value_type=4,u=31):(_=t,x=!0)}else z("String unexpected",t);break;case 10:s.line++,s.col=1;case 32:case 160:case 9:case 13:case 65279:if(31==u){u=0,0==d&&(T=!0);break}0!==u&&(l=!1,z("fault parsing whitespace",t));break;case 116:0==u?u=1:27==u?u=28:(l=!1,z("fault parsing",t));break;case 114:1==u?u=2:(l=!1,z("fault parsing",t));break;case 117:2==u?u=3:9==u?u=10:0==u?u=12:(l=!1,z("fault parsing",t));break;case 101:3==u?(n.value_type=2,u=31):8==u?(n.value_type=3,u=31):14==u?u=15:18==u?u=19:(l=!1,z("fault parsing",t));break;case 110:0==u?u=9:12==u?u=13:17==u?u=18:22==u?u=23:25==u?u=26:(l=!1,z("fault parsing",t));break;case 100:13==u?u=14:19==u?(n.value_type=-1,u=31):(l=!1,z("fault parsing",t));break;case 105:16==u?u=17:24==u?u=25:26==u?u=27:(l=!1,z("fault parsing",t));break;case 108:10==u?u=11:11==u?(n.value_type=1,u=31):6==u?u=7:(l=!1,z("fault parsing",t));break;case 102:0==u?u=5:15==u?u=16:23==u?u=24:(l=!1,z("fault parsing",t));break;case 97:5==u?u=6:20==u?u=21:(l=!1,z("fault parsing",t));break;case 115:7==u?u=8:(l=!1,z("fault parsing",t));break;case 73:0==u?u=22:(l=!1,z("fault parsing",t));break;case 78:0==u?u=20:21==u?(n.value_type=f?8:9,f=!1,u=31):(l=!1,z("fault parsing",t));break;case 121:28==u?(n.value_type=f?10:11,f=!1,u=31):(l=!1,z("fault parsing",t));break;case 45:0==u?f=!f:(l=!1,z("fault parsing",t));break;default:t>=48&&t<=57||43==t||46==t||45==t?(y=!1,m=!1,k=!1,w=!1,v=!1,n.string=e,M.n=c,J()):(l=!1,z("fault parsing",t))}}if(T){31==u&&(u=0);break}}}if(c==F.length?(o(M),x||S||3==d?q=0:0!=d||0==n.value_type&&!p||(T=!0,q=1)):(M.n=c,I.unshift(M),q=2),T)break}if(T&&0!=n.value_type){switch(n.value_type){case 5:p=(f?-1:1)*Number(n.string);break;case 4:p=n.string;break;case 2:p=!0;break;case 3:p=!1;break;case 1:p=null;break;case-1:p=void 0;break;case 9:case 8:p=NaN;break;case 11:p=1/0;break;case 10:p=-1/0;break;case 6:case 7:p=n.contains}f=!1,n.string="",n.value_type=0}return T=!1,q}}};const c=[Object.freeze(s.begin())];let u=0;s.parse=function(e,t){const n=u++;c.length<=n&&c.push(Object.freeze(s.begin()));const r=c[n];if("string"!=typeof e&&(e=String(e)),r.reset(),r._write(e,!0)>0){const e=r.value();return"function"==typeof t&&function e(n,r){const a=n[r];if(a&&"object"==typeof a)for(const t in a)if(Object.prototype.hasOwnProperty.call(a,t)){const n=e(a,t);void 0!==n?a[t]=n:delete a[t]}return t.call(n,r,a)}({"":e},""),u--,e}r.finalError()},s.stringify=JSON.stringify}))}));
|
|
1
|
+
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e=e||self).JSON5=t()}(this,(function(){"use strict";var e="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function t(e,t){return e(t={exports:{}},t.exports),t.exports}var n=function(e){return e&&e.Math==Math&&e},r=n("object"==typeof globalThis&&globalThis)||n("object"==typeof window&&window)||n("object"==typeof self&&self)||n("object"==typeof e&&e)||Function("return this")(),i=function(e){try{return!!e()}catch(e){return!0}},a=!i((function(){return 7!=Object.defineProperty({},1,{get:function(){return 7}})[1]})),o={}.propertyIsEnumerable,s=Object.getOwnPropertyDescriptor,c={f:s&&!o.call({1:2},1)?function(e){var t=s(this,e);return!!t&&t.enumerable}:o},u=function(e,t){return{enumerable:!(1&e),configurable:!(2&e),writable:!(4&e),value:t}},l={}.toString,f="".split,p=i((function(){return!Object("z").propertyIsEnumerable(0)}))?function(e){return"String"==function(e){return l.call(e).slice(8,-1)}(e)?f.call(e,""):Object(e)}:Object,g=function(e){if(null==e)throw TypeError("Can't call method on "+e);return e},h=function(e){return p(g(e))},b=function(e){return"object"==typeof e?null!==e:"function"==typeof e},y=function(e,t){if(!b(e))return e;var n,r;if(t&&"function"==typeof(n=e.toString)&&!b(r=n.call(e)))return r;if("function"==typeof(n=e.valueOf)&&!b(r=n.call(e)))return r;if(!t&&"function"==typeof(n=e.toString)&&!b(r=n.call(e)))return r;throw TypeError("Can't convert object to primitive value")},d={}.hasOwnProperty,v=function(e,t){return d.call(e,t)},m=r.document,k=b(m)&&b(m.createElement),w=!a&&!i((function(){return 7!=Object.defineProperty((e="div",k?m.createElement(e):{}),"a",{get:function(){return 7}}).a;var e})),_=Object.getOwnPropertyDescriptor,x={f:a?_:function(e,t){if(e=h(e),t=y(t,!0),w)try{return _(e,t)}catch(e){}if(v(e,t))return u(!c.f.call(e,t),e[t])}},S=function(e){if(!b(e))throw TypeError(String(e)+" is not an object");return e},j=Object.defineProperty,O={f:a?j:function(e,t,n){if(S(e),t=y(t,!0),S(n),w)try{return j(e,t,n)}catch(e){}if("get"in n||"set"in n)throw TypeError("Accessors not supported");return"value"in n&&(e[t]=n.value),e}},P=a?function(e,t,n){return O.f(e,t,u(1,n))}:function(e,t,n){return e[t]=n,e},E=function(e,t){try{P(r,e,t)}catch(n){r[e]=t}return t},N=r["__core-js_shared__"]||E("__core-js_shared__",{}),A=Function.toString;"function"!=typeof N.inspectSource&&(N.inspectSource=function(e){return A.call(e)});var C,I,T,$,M=N.inspectSource,F=r.WeakMap,q="function"==typeof F&&/native code/.test(M(F)),z=t((function(e){(e.exports=function(e,t){return N[e]||(N[e]=void 0!==t?t:{})})("versions",[]).push({version:"3.6.4",mode:"global",copyright:"© 2020 Denis Pushkarev (zloirock.ru)"})})),L=0,J=Math.random(),D=z("keys"),W={},G=r.WeakMap;if(q){var R=new G,U=R.get,K=R.has,Q=R.set;C=function(e,t){return Q.call(R,e,t),t},I=function(e){return U.call(R,e)||{}},T=function(e){return K.call(R,e)}}else{var V=D[$="state"]||(D[$]=function(e){return"Symbol("+String(void 0===e?"":e)+")_"+(++L+J).toString(36)}($));W[V]=!0,C=function(e,t){return P(e,V,t),t},I=function(e){return v(e,V)?e[V]:{}},T=function(e){return v(e,V)}}var X={set:C,get:I,has:T,enforce:function(e){return T(e)?I(e):C(e,{})},getterFor:function(e){return function(t){var n;if(!b(t)||(n=I(t)).type!==e)throw TypeError("Incompatible receiver, "+e+" required");return n}}},Y=t((function(e){var t=X.get,n=X.enforce,i=String(String).split("String");(e.exports=function(e,t,a,o){var s=!!o&&!!o.unsafe,c=!!o&&!!o.enumerable,u=!!o&&!!o.noTargetGet;"function"==typeof a&&("string"!=typeof t||v(a,"name")||P(a,"name",t),n(a).source=i.join("string"==typeof t?t:"")),e!==r?(s?!u&&e[t]&&(c=!0):delete e[t],c?e[t]=a:P(e,t,a)):c?e[t]=a:E(t,a)})(Function.prototype,"toString",(function(){return"function"==typeof this&&t(this).source||M(this)}))})),B=r,H=function(e){return"function"==typeof e?e:void 0},Z=Math.ceil,ee=Math.floor,te=function(e){return isNaN(e=+e)?0:(e>0?ee:Z)(e)},ne=Math.min,re=Math.max,ie=Math.min,ae=function(e,t){var n=te(e);return n<0?re(n+t,0):ie(n,t)},oe=function(e){return function(t,n,r){var i,a,o=h(t),s=(i=o.length)>0?ne(te(i),9007199254740991):0,c=ae(r,s);if(e&&n!=n){for(;s>c;)if((a=o[c++])!=a)return!0}else for(;s>c;c++)if((e||c in o)&&o[c]===n)return e||c||0;return!e&&-1}},se={includes:oe(!0),indexOf:oe(!1)}.indexOf,ce=["constructor","hasOwnProperty","isPrototypeOf","propertyIsEnumerable","toLocaleString","toString","valueOf"].concat("length","prototype"),ue={f:Object.getOwnPropertyNames||function(e){return function(e,t){var n,r=h(e),i=0,a=[];for(n in r)!v(W,n)&&v(r,n)&&a.push(n);for(;t.length>i;)v(r,n=t[i++])&&(~se(a,n)||a.push(n));return a}(e,ce)}},le={f:Object.getOwnPropertySymbols},fe=function(e,t){return arguments.length<2?H(B[e])||H(r[e]):B[e]&&B[e][t]||r[e]&&r[e][t]}("Reflect","ownKeys")||function(e){var t=ue.f(S(e)),n=le.f;return n?t.concat(n(e)):t},pe=function(e,t){for(var n=fe(t),r=O.f,i=x.f,a=0;a<n.length;a++){var o=n[a];v(e,o)||r(e,o,i(t,o))}},ge=/#|\.prototype\./,he=function(e,t){var n=ye[be(e)];return n==ve||n!=de&&("function"==typeof t?i(t):!!t)},be=he.normalize=function(e){return String(e).replace(ge,".").toLowerCase()},ye=he.data={},de=he.NATIVE="N",ve=he.POLYFILL="P",me=he,ke=x.f,we=function(e,t){var n,i,a,o,s,c=e.target,u=e.global,l=e.stat;if(n=u?r:l?r[c]||E(c,{}):(r[c]||{}).prototype)for(i in t){if(o=t[i],a=e.noTargetGet?(s=ke(n,i))&&s.value:n[i],!me(u?i:c+(l?".":"#")+i,e.forced)&&void 0!==a){if(typeof o==typeof a)continue;pe(o,a)}(e.sham||a&&a.sham)&&P(o,"sham",!0),Y(n,i,o,e)}},_e=function(e){return function(t,n){var r,i,a=String(g(t)),o=te(n),s=a.length;return o<0||o>=s?e?"":void 0:(r=a.charCodeAt(o))<55296||r>56319||o+1===s||(i=a.charCodeAt(o+1))<56320||i>57343?e?a.charAt(o):r:e?a.slice(o,o+2):i-56320+(r-55296<<10)+65536}},xe={codeAt:_e(!1),charAt:_e(!0)}.codeAt;we({target:"String",proto:!0},{codePointAt:function(e){return xe(this,e)}});var Se,je,Oe=function(e,t,n){if(function(e){if("function"!=typeof e)throw TypeError(String(e)+" is not a function")}(e),void 0===t)return e;switch(n){case 0:return function(){return e.call(t)};case 1:return function(n){return e.call(t,n)};case 2:return function(n,r){return e.call(t,n,r)};case 3:return function(n,r,i){return e.call(t,n,r,i)}}return function(){return e.apply(t,arguments)}},Pe=Function.call,Ee=(Se="codePointAt",Oe(Pe,r["String"].prototype[Se],je),String.fromCharCode),Ne=String.fromCodePoint;we({target:"String",stat:!0,forced:!!Ne&&1!=Ne.length},{fromCodePoint:function(e){for(var t,n=[],r=arguments.length,i=0;r>i;){if(t=+arguments[i++],ae(t,1114111)!==t)throw RangeError(t+" is not a valid code point");n.push(t<65536?Ee(t):Ee(55296+((t-=65536)>>10),t%1024+56320))}return n.join("")}});B.String.fromCodePoint;return t((function(e,t){const n=[];function r(){return n.pop()||{context:0,elements:null,element_array:null}}function i(e){n.push(e)}const a=[];function o(e){a.push(e)}const s=t;s.escape=function(e){let t="";if(!e)return e;for(let n=0;n<e.length;n++){const r=e[n];'"'!=r&&"\\"!=r&&"`"!=r&&"'"!=r||(t+="\\"),t+=r}return t},s.begin=function(e,t){const n={name:null,value_type:0,string:"",contains:null},s={line:1,col:1};let c=0,u=0,l=!0,f=!1,p=null,g=void 0,h=[],b=0,y=0,d=!1,v=!1,m=!1,k=!1,w=!1,_=null,x=!1,S=!1,j=!1,O=!1,P=!1,E=!1,N=!1,A=0,C=0,I=!1;const T={first:null,last:null,saved:null,push(e){let t=this.saved;t?(this.saved=t.next,t.node=e,t.next=null,t.prior=this.last):t={node:e,next:null,prior:this.last},this.last||(this.first=t),this.last=t},pop(){const e=this.last;return(this.last=e.prior)||(this.first=null),e.next=this.saved,this.saved=e,e.node}},$={first:null,last:null,saved:null,push(e){let t=this.saved;t?(this.saved=t.next,t.node=e,t.next=null,t.prior=this.last):t={node:e,next:null,prior:this.last},this.last?this.last.next=t:this.first=t,this.last=t},shift(){const e=this.first;return e?(this.first=e.next,this.first||(this.last=null),e.next=this.saved,this.saved=e,e.node):null},unshift(e){const t=this.saved;this.saved=t.next,t.node=e,t.next=this.first,t.prior=null,this.first||(this.last=t),this.first=t}};function M(e){throw new Error(`${e} at ${c} [${s.line}:${s.col}]`)}return{finalError(){if(0!==y)switch(y){case 1:return M("Comment began at end of document");case 2:console.log("Warning: '//' comment without end of line ended document");break;case 3:return M("Open comment '/*' is missing close at end of document");case 4:return M("Incomplete '/* *' close at end of document")}x&&M("Incomplete string")},value(){this.finalError();const e=p;return p=void 0,e},reset(){u=0,l=!0,$.last&&($.last.next=$.save),$.save=$.first,$.first=$.last=null,T.last&&(T.last.next=T.save),T.save=$.first,T.first=T.last=null,h=null,g=void 0,b=0,n.value_type=0,n.name=null,n.string="",s.line=1,s.col=1,f=!1,y=0,I=!1,x=!1,j=!1,O=!1},write(n){let r;if(void 0!==n&&"string"!=typeof n&&(n=String(n)),!l)throw new Error("Parser is in an error state, please reset.");for(r=this._write(n,!1);r>0&&(this.finalError(),"function"==typeof t&&function e(n,r){const i=n[r];if(i&&"object"==typeof i)for(const t in i)if(Object.prototype.hasOwnProperty.call(i,t)){const n=e(i,t);void 0!==n?i[t]=n:delete i[t]}return t.call(n,r,i)}({"":p},""),e(p),p=void 0,!(r<2));r=this._write());r&&this.finalError()},_write(e,t){let M,F,q=0;function z(e,t){throw new Error(`${e} '${String.fromCodePoint(t)}' unexpected at ${c} (near '${F.substr(c>4?c-4:0,c>4?3:c-1)}[${String.fromCodePoint(t)}]${F.substr(c,10)}') [${s.line}:${s.col}]`)}function L(){n.value_type=0,n.string=""}function J(){switch(n.value_type){case 5:h.push((f?-1:1)*Number(n.string));break;case 4:h.push(n.string);break;case 2:h.push(!0);break;case 3:h.push(!1);break;case 8:case 9:h.push(NaN);break;case 10:h.push(-1/0);break;case 11:h.push(1/0);break;case 1:h.push(null);break;case-1:h.push(void 0);break;case 13:h.push(void 0),delete h[h.length-1];break;case 6:case 7:h.push(n.contains)}}function D(){switch(n.value_type){case 5:g[n.name]=(f?-1:1)*Number(n.string);break;case 4:g[n.name]=n.string;break;case 2:g[n.name]=!0;break;case 3:g[n.name]=!1;break;case 8:case 9:g[n.name]=NaN;break;case 10:g[n.name]=-1/0;break;case 11:g[n.name]=1/0;break;case 1:g[n.name]=null;break;case-1:g[n.name]=void 0;break;case 6:case 7:g[n.name]=n.contains}}function W(e){let t=0;for(;0==t&&c<F.length;){let r=F.charAt(c);const i=F.codePointAt(c++);if(i>=65536&&(r+=F.charAt(c),c++),s.col++,i==e)j?(N?z("Incomplete hexidecimal sequence",i):P?z("Incomplete long unicode sequence",i):E&&z("Incomplete unicode sequence",i),O?(O=!1,t=1):n.string+=r,j=!1):t=1;else if(j){if(P){if(125==i){n.string+=String.fromCodePoint(A),P=!1,E=!1,j=!1;continue}A*=16,i>=48&&i<=57?A+=i-48:i>=65&&i<=70?A+=i-65+10:i>=97&&i<=102?A+=i-97+10:z("(escaped character, parsing hex of \\u)",i);continue}if(N||E){if(0===C&&123===i){P=!0;continue}A*=16,i>=48&&i<=57?A+=i-48:i>=65&&i<=70?A+=i-65+10:i>=97&&i<=102?A+=i-97+10:z(E?"(escaped character, parsing hex of \\u)":"(escaped character, parsing hex of \\x)",i),C++,E?4==C&&(n.string+=String.fromCodePoint(A),E=!1,j=!1):2==C&&(n.string+=String.fromCodePoint(A),N=!1,j=!1);continue}switch(i){case 13:O=!0,s.col=1;continue;case 8232:case 8233:s.col=1;case 10:O?O=!1:s.col=1,s.line++;break;case 116:n.string+="\t";break;case 98:n.string+="\b";break;case 48:n.string+="\0";break;case 110:n.string+="\n";break;case 114:n.string+="\r";break;case 102:n.string+="\f";break;case 118:n.string+="\v";break;case 120:N=!0,C=0,A=0;continue;case 117:E=!0,C=0,A=0;continue;default:n.string+=r}j=!1}else 92===i?j=!0:(O&&(O=!1,s.line++,s.col=2),n.string+=r)}return t}function G(){let e;for(;(e=c)<F.length;){const r=F.charAt(e),i=F.codePointAt(c++);if(i>=65536&&z("fault while parsing number;",i),95!=i)if(s.col++,i>=48&&i<=57)m&&(w=!0),n.string+=r;else if(45==i||43==i)0==n.string.length||m&&!k&&!w?(n.string+=r,k=!0):(l=!1,z("fault while parsing number;",i));else if(46==i)v||d||m?(l=!1,z("fault while parsing number;",i)):(n.string+=r,v=!0);else if(d&&(i>=95&&i<=102||i>=65&&i<=70))n.string+=r;else if(120==i||98==i||111==i||88==i||66==i||79==i)d||"0"!=n.string?(l=!1,z("fault while parsing number;",i)):(d=!0,n.string+=r);else{if(101!=i&&69!=i){if(32==i||160==i||13==i||10==i||9==i||65279==i||44==i||125==i||93==i||58==i)break;t&&(l=!1,z("fault while parsing number;",i));break}m?(l=!1,z("fault while parsing number;",i)):(n.string+=r,m=!0)}}c=e,t||c!=F.length?(S=!1,n.value_type=5,0==b&&(I=!0)):S=!0}if(!l)return-1;if(e&&e.length)M=function(){let e=a.pop();return e?e.n=0:e={buf:null,n:0},e}(),M.buf=e,$.push(M);else if(S){if(S=!1,n.value_type=5,0!=b)throw new Error("context stack is not empty at flush");I=!0,q=1}for(;l&&(M=$.shift());){if(c=M.n,F=M.buf,x){W(_)>0&&(x=!1,n.value_type=4)}for(S&&G();!I&&l&&c<F.length;){let e=F.charAt(c);const t=F.codePointAt(c++);if(t>=65536&&(e+=F.charAt(c),c++),s.col++,y)1==y?42==t?y=3:47!=t?z("fault while parsing;",t):y=2:2==y?10!=t&&13!=t||(y=0):3==y?42==t&&(y=4):y=47==t?0:3;else{switch(t){case 47:y=1;break;case 123:(29==u||30==u||3==b&&0==u)&&z("fault while parsing; getting field name unexpected ",t);{const e=r();n.value_type=6;const t={};0==b&&(p=g=t),e.context=b,e.elements=g,e.element_array=h,e.name=n.name,g=t,T.push(e),L(),b=3}break;case 91:if(3!=b&&29!=u&&30!=u||z("Fault while parsing; while getting field name unexpected",t),0==n.value_type||-1==n.value_type){const e=r();n.value_type=7;const t=[];0==b?p=h=t:4==b&&(g[n.name]=t),e.context=b,e.elements=g,e.element_array=h,e.name=n.name,h=t,T.push(e),L(),b=1}else z("Unexpected array open after previous value",t);break;case 58:3==b?(u=0,n.name=n.string,n.string="",b=4,n.value_type=0):z(1==b?"(in array, got colon out of string):parsing fault;":"(outside any object, got colon out of string):parsing fault;",t);break;case 125:if(31==u&&(u=0),3==b){n.value_type=6,n.contains=g;const e=T.pop();n.name=e.name,b=e.context,g=e.elements,h=e.element_array,i(e),0==b&&(I=!0)}else if(4==b){0!=n.value_type?D():z("Fault while parsing field value, close with no value",t),n.value_type=6,n.contains=g;const e=T.pop();n.name=e.name,b=e.context,g=e.elements,h=e.element_array,i(e),0==b&&(I=!0)}else z("Fault while parsing; unexpected",t);f=!1;break;case 93:if(31==u&&(u=0),1==b){0!=n.value_type&&J(),n.value_type=7,n.contains=h;{const e=T.pop();n.name=e.name,b=e.context,g=e.elements,h=e.element_array,i(e)}0==b&&(I=!0)}else z(`bad context ${b}; fault while parsing`,t);f=!1;break;case 44:31==u&&(u=0),1==b?(0==n.value_type&&(n.value_type=13),J(),L()):4==b?(b=3,0!=n.value_type?(D(),L()):z("Unexpected comma after object field name",t)):(l=!1,z("bad context; excessive commas while parsing;",t)),f=!1;break;default:if(3==b)switch(t){case 96:case 34:case 39:if(0==u){0!=n.value_type&&z("String begin after previous value",t),W(t)?n.value_type=4:(_=t,x=!0)}else z("fault while parsing; quote not at start of field name",t);break;case 10:s.line++,s.col=1;case 13:case 32:case 160:case 9:case 65279:31==u?u=0:29==u&&(u=30);break;default:30==u&&(l=!1,z("fault while parsing; character unexpected",t)),0==u&&(u=29),n.string+=e}else switch(t){case 96:case 34:case 39:if(0===n.value_type){W(t)?(n.value_type=4,u=31):(_=t,x=!0)}else z("String unexpected",t);break;case 10:s.line++,s.col=1;case 32:case 160:case 9:case 13:case 65279:if(31==u){u=0,0==b&&(I=!0);break}0!==u&&(l=!1,z("fault parsing whitespace",t));break;case 116:0==u?u=1:27==u?u=28:(l=!1,z("fault parsing",t));break;case 114:1==u?u=2:(l=!1,z("fault parsing",t));break;case 117:2==u?u=3:9==u?u=10:0==u?u=12:(l=!1,z("fault parsing",t));break;case 101:3==u?(n.value_type=2,u=31):8==u?(n.value_type=3,u=31):14==u?u=15:18==u?u=19:(l=!1,z("fault parsing",t));break;case 110:0==u?u=9:12==u?u=13:17==u?u=18:22==u?u=23:25==u?u=26:(l=!1,z("fault parsing",t));break;case 100:13==u?u=14:19==u?(n.value_type=-1,u=31):(l=!1,z("fault parsing",t));break;case 105:16==u?u=17:24==u?u=25:26==u?u=27:(l=!1,z("fault parsing",t));break;case 108:10==u?u=11:11==u?(n.value_type=1,u=31):6==u?u=7:(l=!1,z("fault parsing",t));break;case 102:0==u?u=5:15==u?u=16:23==u?u=24:(l=!1,z("fault parsing",t));break;case 97:5==u?u=6:20==u?u=21:(l=!1,z("fault parsing",t));break;case 115:7==u?u=8:(l=!1,z("fault parsing",t));break;case 73:0==u?u=22:(l=!1,z("fault parsing",t));break;case 78:0==u?u=20:21==u?(n.value_type=f?8:9,f=!1,u=31):(l=!1,z("fault parsing",t));break;case 121:28==u?(n.value_type=f?10:11,f=!1,u=31):(l=!1,z("fault parsing",t));break;case 45:0==u?f=!f:(l=!1,z("fault parsing",t));break;case 43:0!==u&&(l=!1,z("fault parsing",t));break;default:t>=48&&t<=57||43==t||46==t||45==t?(d=!1,m=!1,k=!1,w=!1,v=!1,n.string=e,M.n=c,G()):(l=!1,z("fault parsing",t))}}if(I){31==u&&(u=0);break}}}if(c==F.length?(o(M),x||S||3==b?q=0:0!=b||0==n.value_type&&!p||(I=!0,q=1)):(M.n=c,$.unshift(M),q=2),I)break}if(I&&0!=n.value_type){switch(n.value_type){case 5:p=(f?-1:1)*Number(n.string);break;case 4:p=n.string;break;case 2:p=!0;break;case 3:p=!1;break;case 1:p=null;break;case-1:p=void 0;break;case 9:case 8:p=NaN;break;case 11:p=1/0;break;case 10:p=-1/0;break;case 6:case 7:p=n.contains}f=!1,n.string="",n.value_type=0}return I=!1,q}}};const c=[Object.freeze(s.begin())];let u=0;s.parse=function(e,t){const n=u++;c.length<=n&&c.push(Object.freeze(s.begin()));const r=c[n];if("string"!=typeof e&&(e=String(e)),r.reset(),r._write(e,!0)>0){const e=r.value();return"function"==typeof t&&function e(n,r){const i=n[r];if(i&&"object"==typeof i)for(const t in i)if(Object.prototype.hasOwnProperty.call(i,t)){const n=e(i,t);void 0!==n?i[t]=n:delete i[t]}return t.call(n,r,i)}({"":e},""),u--,e}r.finalError()},s.stringify=JSON.stringify,s.stringifierActive=null,s.stringifier=function(){const e={true:!0,false:!1,null:null,NaN:NaN,Infinity:1/0,undefined:void 0};let t='"',n=!1;return{stringify(e,t,i,a){return function(e,t,i,a,o){if(void 0===t)return"undefined";if(null===t)return"null";let c,u,l;const f=typeof a,p=typeof i;c="",u="";const g=s.stringifierActive;s.stringifierActive=e,o||(o="");if("number"===f)for(l=0;l<a;l+=1)u+=" ";else"string"===f&&(u=a);const h=i;if(i&&"function"!==p&&("object"!==p||"number"!=typeof i.length))throw new Error("JSON6.stringify unknown replacer type.");const b=function e(t,i){let a,o,s,l;const f=c;let p,g=i[t];"string"==typeof g&&(g=r(g));null!=g&&"object"==typeof g&&"function"==typeof toJSOX&&(c+=u,c=f);"function"==typeof h&&(g=h.call(i,t,g));switch(typeof g){case"string":return g;case"number":return""+g;case"boolean":return String(g);case"object":if(!g)return"null";if(c+=u,p=[],h&&"object"==typeof h)for(l=h.length,a=0;a<l;a+=1)"string"==typeof h[a]&&(o=h[a],s=e(o,g),s&&p.push(r(o)+(c?": ":":")+s));else{const t=[];for(o in g)if((!n||Object.prototype.propertyIsEnumerable.call(g,o))&&Object.prototype.hasOwnProperty.call(g,o)){let e;for(e=0;e<t.length;e++)if(t[e]>o){t.splice(e,0,o);break}e===t.length&&t.push(o)}for(let n=0;n<t.length;n++)o=t[n],Object.prototype.hasOwnProperty.call(g,o)&&(s=e(o,g),s&&p.push(r(o)+(c?": ":":")+s))}return s=0===p.length?"{}":c?"{\n"+c+p.join(",\n"+c)+"\n"+f+"}":"{"+p.join(",")+"}",c=f,s}}(o,{[o]:t});return s.stringifierActive=g,b}(this,e,t,i,a)},setQuote(e){t=e},get ignoreNonEnumerable(){return n},set ignoreNonEnumerable(e){n=e}};function r(n){return"number"!=typeof n||isNaN(n)?n.length?n in e||/([0-9-])/.test(n[0])||/((\n|\r|\t)|[ #{}()<>!+\-*/.:,])/.test(n)?t+s.escape(n)+t:n:t+t:["'",n.toString(),"'"].join()}},s.stringify=function(e,t,n){return s.stringifier().stringify(e,t,n)},s.version="1.1.1"}))}));
|
package/dist/index.min.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var e,t,a=(function(e,t){const a=[];function n(){return a.pop()||{context:0,elements:null,element_array:null}}function s(e){a.push(e)}const r=[];function i(e){r.push(e)}const l=t;l.escape=function(e){let t="";if(!e)return e;for(let a=0;a<e.length;a++)'"'!=e[a]&&"\\"!=e[a]&&"`"!=e[a]&&"'"!=e[a]||(t+="\\"),t+=e[a];return t},l.begin=function(e,t){const a={name:null,value_type:0,string:"",contains:null},l={line:1,col:1};let c=0,o=0,u=!0,f=!1,p=null,h=void 0,g=[],b=0,d=0,m=!1,v=!1,k=!1,y=!1,_=!1,w=null,x=!1,$=!1,P=!1,E=!1,N=!1,S=!1,j=!1,A=0,O=0,q=!1;const C={first:null,last:null,saved:null,push(e){let t=this.saved;t?(this.saved=t.next,t.node=e,t.next=null,t.prior=this.last):t={node:e,next:null,prior:this.last},this.last||(this.first=t),this.last=t},pop(){const e=this.last;return(this.last=e.prior)||(this.first=null),e.next=this.saved,this.saved=e,e.node}},I={first:null,last:null,saved:null,push(e){let t=this.saved;t?(this.saved=t.next,t.node=e,t.next=null,t.prior=this.last):t={node:e,next:null,prior:this.last},this.last?this.last.next=t:this.first=t,this.last=t},shift(){const e=this.first;return e?(this.first=e.next,this.first||(this.last=null),e.next=this.saved,this.saved=e,e.node):null},unshift(e){const t=this.saved;this.saved=t.next,t.node=e,t.next=this.first,t.prior=null,this.first||(this.last=t),this.first=t}};function F(e){throw new Error(`${e} at ${c} [${l.line}:${l.col}]`)}return{finalError(){if(0!==d)switch(d){case 1:return F("Comment began at end of document");case 2:console.log("Warning: '//' comment without end of line ended document");break;case 3:return F("Open comment '/*' is missing close at end of document");case 4:return F("Incomplete '/* *' close at end of document")}x&&F("Incomplete string")},value(){this.finalError();const e=p;return p=void 0,e},reset(){o=0,u=!0,I.last&&(I.last.next=I.save),I.save=I.first,I.first=I.last=null,C.last&&(C.last.next=C.save),C.save=I.first,C.first=C.last=null,g=null,h=void 0,b=0,a.value_type=0,a.name=null,a.string="",l.line=1,l.col=1,f=!1,d=0,q=!1,x=!1,P=!1,E=!1},write(a){let n;if(void 0!==a&&"string"!=typeof a&&(a=String(a)),!u)throw new Error("Parser is in an error state, please reset.");for(n=this._write(a,!1);n>0&&(this.finalError(),"function"==typeof t&&function e(a,n){const s=a[n];if(s&&"object"==typeof s)for(const t in s)if(Object.prototype.hasOwnProperty.call(s,t)){const a=e(s,t);void 0!==a?s[t]=a:delete s[t]}return t.call(a,n,s)}({"":p},""),e(p),p=void 0,!(n<2));n=this._write());n&&this.finalError()},_write(e,t){let F,z,U=0;function D(e,t){throw new Error(`${e} '${String.fromCodePoint(t)}' unexpected at ${c} (near '${z.substr(c>4?c-4:0,c>4?3:c-1)}[${String.fromCodePoint(t)}]${z.substr(c,10)}') [${l.line}:${l.col}]`)}function J(){a.value_type=0,a.string=""}function W(){switch(a.value_type){case 5:g.push((f?-1:1)*Number(a.string));break;case 4:g.push(a.string);break;case 2:g.push(!0);break;case 3:g.push(!1);break;case 8:case 9:g.push(NaN);break;case 10:g.push(-1/0);break;case 11:g.push(1/0);break;case 1:g.push(null);break;case-1:g.push(void 0);break;case 13:g.push(void 0),delete g[g.length-1];break;case 6:case 7:g.push(a.contains)}}function B(){switch(a.value_type){case 5:h[a.name]=(f?-1:1)*Number(a.string);break;case 4:h[a.name]=a.string;break;case 2:h[a.name]=!0;break;case 3:h[a.name]=!1;break;case 8:case 9:h[a.name]=NaN;break;case 10:h[a.name]=-1/0;break;case 11:h[a.name]=1/0;break;case 1:h[a.name]=null;break;case-1:h[a.name]=void 0;break;case 6:case 7:h[a.name]=a.contains}}function G(e){let t=0;for(;0==t&&c<z.length;){let n=z.charAt(c);const s=z.codePointAt(c++);if(s>=65536&&(n+=z.charAt(c),c++),l.col++,s==e)P?(j?D("Incomplete hexidecimal sequence",s):N?D("Incomplete long unicode sequence",s):S&&D("Incomplete unicode sequence",s),E?(E=!1,t=1):a.string+=n,P=!1):t=1;else if(P){if(N){if(125==s){a.string+=String.fromCodePoint(A),N=!1,S=!1,P=!1;continue}A*=16,s>=48&&s<=57?A+=s-48:s>=65&&s<=70?A+=s-65+10:s>=97&&s<=102?A+=s-97+10:D("(escaped character, parsing hex of \\u)",s);continue}if(j||S){if(0===O&&123===s){N=!0;continue}A*=16,s>=48&&s<=57?A+=s-48:s>=65&&s<=70?A+=s-65+10:s>=97&&s<=102?A+=s-97+10:D(S?"(escaped character, parsing hex of \\u)":"(escaped character, parsing hex of \\x)",s),O++,S?4==O&&(a.string+=String.fromCodePoint(A),S=!1,P=!1):2==O&&(a.string+=String.fromCodePoint(A),j=!1,P=!1);continue}switch(s){case 13:E=!0,l.col=1;continue;case 8232:case 8233:l.col=1;case 10:E?E=!1:l.col=1,l.line++;break;case 116:a.string+="\t";break;case 98:a.string+="\b";break;case 48:a.string+="\0";break;case 110:a.string+="\n";break;case 114:a.string+="\r";break;case 102:a.string+="\f";break;case 120:j=!0,O=0,A=0;continue;case 117:S=!0,O=0,A=0;continue;default:a.string+=n}P=!1}else 92===s?P=!0:(E&&(E=!1,l.line++,l.col=2),a.string+=n)}return t}function H(){let e;for(;(e=c)<z.length;){const n=z.charAt(e),s=z.codePointAt(c++);if(s>=65536&&D("fault while parsing number;",s),95!=s)if(l.col++,s>=48&&s<=57)k&&(_=!0),a.string+=n;else if(45==s||43==s)0==a.string.length||k&&!y&&!_?(a.string+=n,y=!0):(u=!1,D("fault while parsing number;",s));else if(46==s)v||m||k?(u=!1,D("fault while parsing number;",s)):(a.string+=n,v=!0);else if(120==s||98==s||111==s||88==s||66==s||79==s)m||"0"!=a.string?(u=!1,D("fault while parsing number;",s)):(m=!0,a.string+=n);else{if(101!=s&&69!=s){if(32==s||160==s||13==s||10==s||9==s||65279==s||44==s||125==s||93==s||58==s)break;t&&(u=!1,D("fault while parsing number;",s));break}k?(u=!1,D("fault while parsing number;",s)):(a.string+=n,k=!0)}}c=e,t||c!=z.length?($=!1,a.value_type=5,0==b&&(q=!0)):$=!0}if(!u)return-1;if(e&&e.length)F=function(){let e=r.pop();return e?e.n=0:e={buf:null,n:0},e}(),F.buf=e,I.push(F);else if($){if($=!1,a.value_type=5,0!=b)throw new Error("context stack is not empty at flush");q=!0,U=1}for(;u&&(F=I.shift());){for(c=F.n,z=F.buf,x&&G(w)>0&&(x=!1,a.value_type=4),$&&H();!q&&u&&c<z.length;){let e=z.charAt(c);const t=z.codePointAt(c++);if(t>=65536&&(e+=z.charAt(c),c++),l.col++,d)1==d?42==t?d=3:47!=t?D("fault while parsing;",t):d=2:2==d?10!=t&&13!=t||(d=0):3==d?42==t&&(d=4):d=47==t?0:3;else{switch(t){case 47:d=1;break;case 123:(29==o||30==o||3==b&&0==o)&&D("fault while parsing; getting field name unexpected ",t);{const e=n();a.value_type=6;const t={};0==b&&(p=h=t),e.context=b,e.elements=h,e.element_array=g,e.name=a.name,h=t,C.push(e),J(),b=3}break;case 91:if(3!=b&&29!=o&&30!=o||D("Fault while parsing; while getting field name unexpected",t),0==a.value_type||-1==a.value_type){const e=n();a.value_type=7;const t=[];0==b?p=g=t:4==b&&(h[a.name]=t),e.context=b,e.elements=h,e.element_array=g,e.name=a.name,g=t,C.push(e),J(),b=1}else D("Unexpected array open after previous value",t);break;case 58:3==b?(o=0,a.name=a.string,a.string="",b=4,a.value_type=0):D(1==b?"(in array, got colon out of string):parsing fault;":"(outside any object, got colon out of string):parsing fault;",t);break;case 125:if(31==o&&(o=0),3==b){a.value_type=6,a.contains=h;const e=C.pop();a.name=e.name,b=e.context,h=e.elements,g=e.element_array,s(e),0==b&&(q=!0)}else if(4==b){0!=a.value_type?B():D("Fault while parsing field value, close with no value",t),a.value_type=6,a.contains=h;const e=C.pop();a.name=e.name,b=e.context,h=e.elements,g=e.element_array,s(e),0==b&&(q=!0)}else D("Fault while parsing; unexpected",t);f=!1;break;case 93:if(31==o&&(o=0),1==b){0!=a.value_type&&W(),a.value_type=7,a.contains=g;{const e=C.pop();a.name=e.name,b=e.context,h=e.elements,g=e.element_array,s(e)}0==b&&(q=!0)}else D(`bad context ${b}; fault while parsing`,t);f=!1;break;case 44:31==o&&(o=0),1==b?(0==a.value_type&&(a.value_type=13),W(),J()):4==b?(b=3,0!=a.value_type?(B(),J()):D("Unexpected comma after object field name",t)):(u=!1,D("bad context; excessive commas while parsing;",t)),f=!1;break;default:if(3==b)switch(t){case 96:case 34:case 39:0==o?(0!=a.value_type&&D("String begin after previous value",t),G(t)?a.value_type=4:(w=t,x=!0)):D("fault while parsing; quote not at start of field name",t);break;case 10:l.line++,l.col=1;case 13:case 32:case 160:case 9:case 65279:31==o?o=0:29==o&&(o=30);break;default:30==o&&(u=!1,D("fault while parsing; character unexpected",t)),0==o&&(o=29),a.string+=e}else switch(t){case 96:case 34:case 39:0===a.value_type?G(t)?(a.value_type=4,o=31):(w=t,x=!0):D("String unexpected",t);break;case 10:l.line++,l.col=1;case 32:case 160:case 9:case 13:case 65279:if(31==o){o=0,0==b&&(q=!0);break}0!==o&&(u=!1,D("fault parsing whitespace",t));break;case 116:0==o?o=1:27==o?o=28:(u=!1,D("fault parsing",t));break;case 114:1==o?o=2:(u=!1,D("fault parsing",t));break;case 117:2==o?o=3:9==o?o=10:0==o?o=12:(u=!1,D("fault parsing",t));break;case 101:3==o?(a.value_type=2,o=31):8==o?(a.value_type=3,o=31):14==o?o=15:18==o?o=19:(u=!1,D("fault parsing",t));break;case 110:0==o?o=9:12==o?o=13:17==o?o=18:22==o?o=23:25==o?o=26:(u=!1,D("fault parsing",t));break;case 100:13==o?o=14:19==o?(a.value_type=-1,o=31):(u=!1,D("fault parsing",t));break;case 105:16==o?o=17:24==o?o=25:26==o?o=27:(u=!1,D("fault parsing",t));break;case 108:10==o?o=11:11==o?(a.value_type=1,o=31):6==o?o=7:(u=!1,D("fault parsing",t));break;case 102:0==o?o=5:15==o?o=16:23==o?o=24:(u=!1,D("fault parsing",t));break;case 97:5==o?o=6:20==o?o=21:(u=!1,D("fault parsing",t));break;case 115:7==o?o=8:(u=!1,D("fault parsing",t));break;case 73:0==o?o=22:(u=!1,D("fault parsing",t));break;case 78:0==o?o=20:21==o?(a.value_type=f?8:9,f=!1,o=31):(u=!1,D("fault parsing",t));break;case 121:28==o?(a.value_type=f?10:11,f=!1,o=31):(u=!1,D("fault parsing",t));break;case 45:0==o?f=!f:(u=!1,D("fault parsing",t));break;default:t>=48&&t<=57||43==t||46==t||45==t?(m=!1,k=!1,y=!1,_=!1,v=!1,a.string=e,F.n=c,H()):(u=!1,D("fault parsing",t))}}if(q){31==o&&(o=0);break}}}if(c==z.length?(i(F),x||$||3==b?U=0:0!=b||0==a.value_type&&!p||(q=!0,U=1)):(F.n=c,I.unshift(F),U=2),q)break}if(q&&0!=a.value_type){switch(a.value_type){case 5:p=(f?-1:1)*Number(a.string);break;case 4:p=a.string;break;case 2:p=!0;break;case 3:p=!1;break;case 1:p=null;break;case-1:p=void 0;break;case 9:case 8:p=NaN;break;case 11:p=1/0;break;case 10:p=-1/0;break;case 6:case 7:p=a.contains}f=!1,a.string="",a.value_type=0}return q=!1,U}}};const c=[Object.freeze(l.begin())];let o=0;l.parse=function(e,t){const a=o++;c.length<=a&&c.push(Object.freeze(l.begin()));const n=c[a];if("string"!=typeof e&&(e=String(e)),n.reset(),n._write(e,!0)>0){const e=n.value();return"function"==typeof t&&function e(a,n){const s=a[n];if(s&&"object"==typeof s)for(const t in s)if(Object.prototype.hasOwnProperty.call(s,t)){const a=e(s,t);void 0!==a?s[t]=a:delete s[t]}return t.call(a,n,s)}({"":e},""),o--,e}n.finalError()},l.stringify=JSON.stringify}(t={path:e,exports:{},require:function(e,a){return function(){throw new Error("Dynamic requires are not currently supported by @rollup/plugin-commonjs")}(null==a&&t.path)}},t.exports),t.exports);export default a;
|
|
1
|
+
var e,t=(function(e,t){const n=[];function a(){return n.pop()||{context:0,elements:null,element_array:null}}function s(e){n.push(e)}const r=[];function i(e){r.push(e)}const l=t;l.escape=function(e){let t="";if(!e)return e;for(let n=0;n<e.length;n++){const a=e[n];'"'!=a&&"\\"!=a&&"`"!=a&&"'"!=a||(t+="\\"),t+=a}return t},l.begin=function(e,t){const n={name:null,value_type:0,string:"",contains:null},l={line:1,col:1};let c=0,o=0,u=!0,f=!1,p=null,g=void 0,h=[],b=0,d=0,m=!1,v=!1,y=!1,k=!1,w=!1,_=null,x=!1,N=!1,j=!1,O=!1,S=!1,E=!1,P=!1,$=0,A=0,I=!1;const C={first:null,last:null,saved:null,push(e){let t=this.saved;t?(this.saved=t.next,t.node=e,t.next=null,t.prior=this.last):t={node:e,next:null,prior:this.last},this.last||(this.first=t),this.last=t},pop(){const e=this.last;return(this.last=e.prior)||(this.first=null),e.next=this.saved,this.saved=e,e.node}},q={first:null,last:null,saved:null,push(e){let t=this.saved;t?(this.saved=t.next,t.node=e,t.next=null,t.prior=this.last):t={node:e,next:null,prior:this.last},this.last?this.last.next=t:this.first=t,this.last=t},shift(){const e=this.first;return e?(this.first=e.next,this.first||(this.last=null),e.next=this.saved,this.saved=e,e.node):null},unshift(e){const t=this.saved;this.saved=t.next,t.node=e,t.next=this.first,t.prior=null,this.first||(this.last=t),this.first=t}};function F(e){throw new Error(`${e} at ${c} [${l.line}:${l.col}]`)}return{finalError(){if(0!==d)switch(d){case 1:return F("Comment began at end of document");case 2:console.log("Warning: '//' comment without end of line ended document");break;case 3:return F("Open comment '/*' is missing close at end of document");case 4:return F("Incomplete '/* *' close at end of document")}x&&F("Incomplete string")},value(){this.finalError();const e=p;return p=void 0,e},reset(){o=0,u=!0,q.last&&(q.last.next=q.save),q.save=q.first,q.first=q.last=null,C.last&&(C.last.next=C.save),C.save=q.first,C.first=C.last=null,h=null,g=void 0,b=0,n.value_type=0,n.name=null,n.string="",l.line=1,l.col=1,f=!1,d=0,I=!1,x=!1,j=!1,O=!1},write(n){let a;if(void 0!==n&&"string"!=typeof n&&(n=String(n)),!u)throw new Error("Parser is in an error state, please reset.");for(a=this._write(n,!1);a>0&&(this.finalError(),"function"==typeof t&&function e(n,a){const s=n[a];if(s&&"object"==typeof s)for(const t in s)if(Object.prototype.hasOwnProperty.call(s,t)){const n=e(s,t);void 0!==n?s[t]=n:delete s[t]}return t.call(n,a,s)}({"":p},""),e(p),p=void 0,!(a<2));a=this._write());a&&this.finalError()},_write(e,t){let F,J,z=0;function U(e,t){throw new Error(`${e} '${String.fromCodePoint(t)}' unexpected at ${c} (near '${J.substr(c>4?c-4:0,c>4?3:c-1)}[${String.fromCodePoint(t)}]${J.substr(c,10)}') [${l.line}:${l.col}]`)}function Q(){n.value_type=0,n.string=""}function W(){switch(n.value_type){case 5:h.push((f?-1:1)*Number(n.string));break;case 4:h.push(n.string);break;case 2:h.push(!0);break;case 3:h.push(!1);break;case 8:case 9:h.push(NaN);break;case 10:h.push(-1/0);break;case 11:h.push(1/0);break;case 1:h.push(null);break;case-1:h.push(void 0);break;case 13:h.push(void 0),delete h[h.length-1];break;case 6:case 7:h.push(n.contains)}}function X(){switch(n.value_type){case 5:g[n.name]=(f?-1:1)*Number(n.string);break;case 4:g[n.name]=n.string;break;case 2:g[n.name]=!0;break;case 3:g[n.name]=!1;break;case 8:case 9:g[n.name]=NaN;break;case 10:g[n.name]=-1/0;break;case 11:g[n.name]=1/0;break;case 1:g[n.name]=null;break;case-1:g[n.name]=void 0;break;case 6:case 7:g[n.name]=n.contains}}function B(e){let t=0;for(;0==t&&c<J.length;){let a=J.charAt(c);const s=J.codePointAt(c++);if(s>=65536&&(a+=J.charAt(c),c++),l.col++,s==e)j?(P?U("Incomplete hexidecimal sequence",s):S?U("Incomplete long unicode sequence",s):E&&U("Incomplete unicode sequence",s),O?(O=!1,t=1):n.string+=a,j=!1):t=1;else if(j){if(S){if(125==s){n.string+=String.fromCodePoint($),S=!1,E=!1,j=!1;continue}$*=16,s>=48&&s<=57?$+=s-48:s>=65&&s<=70?$+=s-65+10:s>=97&&s<=102?$+=s-97+10:U("(escaped character, parsing hex of \\u)",s);continue}if(P||E){if(0===A&&123===s){S=!0;continue}$*=16,s>=48&&s<=57?$+=s-48:s>=65&&s<=70?$+=s-65+10:s>=97&&s<=102?$+=s-97+10:U(E?"(escaped character, parsing hex of \\u)":"(escaped character, parsing hex of \\x)",s),A++,E?4==A&&(n.string+=String.fromCodePoint($),E=!1,j=!1):2==A&&(n.string+=String.fromCodePoint($),P=!1,j=!1);continue}switch(s){case 13:O=!0,l.col=1;continue;case 8232:case 8233:l.col=1;case 10:O?O=!1:l.col=1,l.line++;break;case 116:n.string+="\t";break;case 98:n.string+="\b";break;case 48:n.string+="\0";break;case 110:n.string+="\n";break;case 114:n.string+="\r";break;case 102:n.string+="\f";break;case 118:n.string+="\v";break;case 120:P=!0,A=0,$=0;continue;case 117:E=!0,A=0,$=0;continue;default:n.string+=a}j=!1}else 92===s?j=!0:(O&&(O=!1,l.line++,l.col=2),n.string+=a)}return t}function D(){let e;for(;(e=c)<J.length;){const a=J.charAt(e),s=J.codePointAt(c++);if(s>=65536&&U("fault while parsing number;",s),95!=s)if(l.col++,s>=48&&s<=57)y&&(w=!0),n.string+=a;else if(45==s||43==s)0==n.string.length||y&&!k&&!w?(n.string+=a,k=!0):(u=!1,U("fault while parsing number;",s));else if(46==s)v||m||y?(u=!1,U("fault while parsing number;",s)):(n.string+=a,v=!0);else if(m&&(s>=95&&s<=102||s>=65&&s<=70))n.string+=a;else if(120==s||98==s||111==s||88==s||66==s||79==s)m||"0"!=n.string?(u=!1,U("fault while parsing number;",s)):(m=!0,n.string+=a);else{if(101!=s&&69!=s){if(32==s||160==s||13==s||10==s||9==s||65279==s||44==s||125==s||93==s||58==s)break;t&&(u=!1,U("fault while parsing number;",s));break}y?(u=!1,U("fault while parsing number;",s)):(n.string+=a,y=!0)}}c=e,t||c!=J.length?(N=!1,n.value_type=5,0==b&&(I=!0)):N=!0}if(!u)return-1;if(e&&e.length)F=function(){let e=r.pop();return e?e.n=0:e={buf:null,n:0},e}(),F.buf=e,q.push(F);else if(N){if(N=!1,n.value_type=5,0!=b)throw new Error("context stack is not empty at flush");I=!0,z=1}for(;u&&(F=q.shift());){for(c=F.n,J=F.buf,x&&B(_)>0&&(x=!1,n.value_type=4),N&&D();!I&&u&&c<J.length;){let e=J.charAt(c);const t=J.codePointAt(c++);if(t>=65536&&(e+=J.charAt(c),c++),l.col++,d)1==d?42==t?d=3:47!=t?U("fault while parsing;",t):d=2:2==d?10!=t&&13!=t||(d=0):3==d?42==t&&(d=4):d=47==t?0:3;else{switch(t){case 47:d=1;break;case 123:(29==o||30==o||3==b&&0==o)&&U("fault while parsing; getting field name unexpected ",t);{const e=a();n.value_type=6;const t={};0==b&&(p=g=t),e.context=b,e.elements=g,e.element_array=h,e.name=n.name,g=t,C.push(e),Q(),b=3}break;case 91:if(3!=b&&29!=o&&30!=o||U("Fault while parsing; while getting field name unexpected",t),0==n.value_type||-1==n.value_type){const e=a();n.value_type=7;const t=[];0==b?p=h=t:4==b&&(g[n.name]=t),e.context=b,e.elements=g,e.element_array=h,e.name=n.name,h=t,C.push(e),Q(),b=1}else U("Unexpected array open after previous value",t);break;case 58:3==b?(o=0,n.name=n.string,n.string="",b=4,n.value_type=0):U(1==b?"(in array, got colon out of string):parsing fault;":"(outside any object, got colon out of string):parsing fault;",t);break;case 125:if(31==o&&(o=0),3==b){n.value_type=6,n.contains=g;const e=C.pop();n.name=e.name,b=e.context,g=e.elements,h=e.element_array,s(e),0==b&&(I=!0)}else if(4==b){0!=n.value_type?X():U("Fault while parsing field value, close with no value",t),n.value_type=6,n.contains=g;const e=C.pop();n.name=e.name,b=e.context,g=e.elements,h=e.element_array,s(e),0==b&&(I=!0)}else U("Fault while parsing; unexpected",t);f=!1;break;case 93:if(31==o&&(o=0),1==b){0!=n.value_type&&W(),n.value_type=7,n.contains=h;{const e=C.pop();n.name=e.name,b=e.context,g=e.elements,h=e.element_array,s(e)}0==b&&(I=!0)}else U(`bad context ${b}; fault while parsing`,t);f=!1;break;case 44:31==o&&(o=0),1==b?(0==n.value_type&&(n.value_type=13),W(),Q()):4==b?(b=3,0!=n.value_type?(X(),Q()):U("Unexpected comma after object field name",t)):(u=!1,U("bad context; excessive commas while parsing;",t)),f=!1;break;default:if(3==b)switch(t){case 96:case 34:case 39:0==o?(0!=n.value_type&&U("String begin after previous value",t),B(t)?n.value_type=4:(_=t,x=!0)):U("fault while parsing; quote not at start of field name",t);break;case 10:l.line++,l.col=1;case 13:case 32:case 160:case 9:case 65279:31==o?o=0:29==o&&(o=30);break;default:30==o&&(u=!1,U("fault while parsing; character unexpected",t)),0==o&&(o=29),n.string+=e}else switch(t){case 96:case 34:case 39:0===n.value_type?B(t)?(n.value_type=4,o=31):(_=t,x=!0):U("String unexpected",t);break;case 10:l.line++,l.col=1;case 32:case 160:case 9:case 13:case 65279:if(31==o){o=0,0==b&&(I=!0);break}0!==o&&(u=!1,U("fault parsing whitespace",t));break;case 116:0==o?o=1:27==o?o=28:(u=!1,U("fault parsing",t));break;case 114:1==o?o=2:(u=!1,U("fault parsing",t));break;case 117:2==o?o=3:9==o?o=10:0==o?o=12:(u=!1,U("fault parsing",t));break;case 101:3==o?(n.value_type=2,o=31):8==o?(n.value_type=3,o=31):14==o?o=15:18==o?o=19:(u=!1,U("fault parsing",t));break;case 110:0==o?o=9:12==o?o=13:17==o?o=18:22==o?o=23:25==o?o=26:(u=!1,U("fault parsing",t));break;case 100:13==o?o=14:19==o?(n.value_type=-1,o=31):(u=!1,U("fault parsing",t));break;case 105:16==o?o=17:24==o?o=25:26==o?o=27:(u=!1,U("fault parsing",t));break;case 108:10==o?o=11:11==o?(n.value_type=1,o=31):6==o?o=7:(u=!1,U("fault parsing",t));break;case 102:0==o?o=5:15==o?o=16:23==o?o=24:(u=!1,U("fault parsing",t));break;case 97:5==o?o=6:20==o?o=21:(u=!1,U("fault parsing",t));break;case 115:7==o?o=8:(u=!1,U("fault parsing",t));break;case 73:0==o?o=22:(u=!1,U("fault parsing",t));break;case 78:0==o?o=20:21==o?(n.value_type=f?8:9,f=!1,o=31):(u=!1,U("fault parsing",t));break;case 121:28==o?(n.value_type=f?10:11,f=!1,o=31):(u=!1,U("fault parsing",t));break;case 45:0==o?f=!f:(u=!1,U("fault parsing",t));break;case 43:0!==o&&(u=!1,U("fault parsing",t));break;default:t>=48&&t<=57||43==t||46==t||45==t?(m=!1,y=!1,k=!1,w=!1,v=!1,n.string=e,F.n=c,D()):(u=!1,U("fault parsing",t))}}if(I){31==o&&(o=0);break}}}if(c==J.length?(i(F),x||N||3==b?z=0:0!=b||0==n.value_type&&!p||(I=!0,z=1)):(F.n=c,q.unshift(F),z=2),I)break}if(I&&0!=n.value_type){switch(n.value_type){case 5:p=(f?-1:1)*Number(n.string);break;case 4:p=n.string;break;case 2:p=!0;break;case 3:p=!1;break;case 1:p=null;break;case-1:p=void 0;break;case 9:case 8:p=NaN;break;case 11:p=1/0;break;case 10:p=-1/0;break;case 6:case 7:p=n.contains}f=!1,n.string="",n.value_type=0}return I=!1,z}}};const c=[Object.freeze(l.begin())];let o=0;l.parse=function(e,t){const n=o++;c.length<=n&&c.push(Object.freeze(l.begin()));const a=c[n];if("string"!=typeof e&&(e=String(e)),a.reset(),a._write(e,!0)>0){const e=a.value();return"function"==typeof t&&function e(n,a){const s=n[a];if(s&&"object"==typeof s)for(const t in s)if(Object.prototype.hasOwnProperty.call(s,t)){const n=e(s,t);void 0!==n?s[t]=n:delete s[t]}return t.call(n,a,s)}({"":e},""),o--,e}a.finalError()},l.stringify=JSON.stringify,l.stringifierActive=null,l.stringifier=function(){const e={true:!0,false:!1,null:null,NaN:NaN,Infinity:1/0,undefined:void 0};let t='"',n=!1;return{stringify(e,t,s,r){return function(e,t,s,r,i){if(void 0===t)return"undefined";if(null===t)return"null";let c,o,u;const f=typeof r,p=typeof s;c="",o="";const g=l.stringifierActive;if(l.stringifierActive=e,i||(i=""),"number"===f)for(u=0;u<r;u+=1)o+=" ";else"string"===f&&(o=r);const h=s;if(s&&"function"!==p&&("object"!==p||"number"!=typeof s.length))throw new Error("JSON6.stringify unknown replacer type.");const b=function e(t,s){let r,i,l,u;const f=c;let p,g=s[t];switch("string"==typeof g&&(g=a(g)),null!=g&&"object"==typeof g&&"function"==typeof toJSOX&&(c+=o,c=f),"function"==typeof h&&(g=h.call(s,t,g)),typeof g){case"string":return g;case"number":return""+g;case"boolean":return String(g);case"object":if(!g)return"null";if(c+=o,p=[],h&&"object"==typeof h)for(u=h.length,r=0;r<u;r+=1)"string"==typeof h[r]&&(i=h[r],l=e(i,g),l&&p.push(a(i)+(c?": ":":")+l));else{const t=[];for(i in g)if((!n||Object.prototype.propertyIsEnumerable.call(g,i))&&Object.prototype.hasOwnProperty.call(g,i)){let e;for(e=0;e<t.length;e++)if(t[e]>i){t.splice(e,0,i);break}e===t.length&&t.push(i)}for(let n=0;n<t.length;n++)i=t[n],Object.prototype.hasOwnProperty.call(g,i)&&(l=e(i,g),l&&p.push(a(i)+(c?": ":":")+l))}return l=0===p.length?"{}":c?"{\n"+c+p.join(",\n"+c)+"\n"+f+"}":"{"+p.join(",")+"}",c=f,l}}(i,{[i]:t});return l.stringifierActive=g,b}(this,e,t,s,r)},setQuote(e){t=e},get ignoreNonEnumerable(){return n},set ignoreNonEnumerable(e){n=e}};function a(n){return"number"!=typeof n||isNaN(n)?n.length?n in e||/([0-9-])/.test(n[0])||/((\n|\r|\t)|[ #{}()<>!+\-*/.:,])/.test(n)?t+l.escape(n)+t:n:t+t:["'",n.toString(),"'"].join()}},l.stringify=function(e,t,n){return l.stringifier().stringify(e,t,n)},l.version="1.1.1"}(e={exports:{}},e.exports),e.exports);export default t;
|
package/dist/index.mjs
CHANGED
|
@@ -1,19 +1,10 @@
|
|
|
1
|
-
function createCommonjsModule(fn,
|
|
2
|
-
return module = {
|
|
3
|
-
path: basedir,
|
|
4
|
-
exports: {},
|
|
5
|
-
require: function (path, base) {
|
|
6
|
-
return commonjsRequire(path, (base === undefined || base === null) ? module.path : base);
|
|
7
|
-
}
|
|
8
|
-
}, fn(module, module.exports), module.exports;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
function commonjsRequire () {
|
|
12
|
-
throw new Error('Dynamic requires are not currently supported by @rollup/plugin-commonjs');
|
|
1
|
+
function createCommonjsModule(fn, module) {
|
|
2
|
+
return module = { exports: {} }, fn(module, module.exports), module.exports;
|
|
13
3
|
}
|
|
14
4
|
|
|
15
5
|
var json6 = createCommonjsModule(function (module, exports) {
|
|
16
6
|
|
|
7
|
+
const version = "1.1.1";
|
|
17
8
|
const VALUE_UNDEFINED = -1;
|
|
18
9
|
const VALUE_UNSET = 0;
|
|
19
10
|
const VALUE_NULL = 1;
|
|
@@ -121,11 +112,13 @@ var json6 = createCommonjsModule(function (module, exports) {
|
|
|
121
112
|
if (!string) return string;
|
|
122
113
|
|
|
123
114
|
for (let n = 0; n < string.length; n++) {
|
|
124
|
-
|
|
115
|
+
const ch = string[n];
|
|
116
|
+
|
|
117
|
+
if (ch == '"' || ch == '\\' || ch == '`' || ch == '\'') {
|
|
125
118
|
output += '\\';
|
|
126
119
|
}
|
|
127
120
|
|
|
128
|
-
output +=
|
|
121
|
+
output += ch;
|
|
129
122
|
}
|
|
130
123
|
|
|
131
124
|
return output;
|
|
@@ -648,6 +641,12 @@ var json6 = createCommonjsModule(function (module, exports) {
|
|
|
648
641
|
val.string += '\f';
|
|
649
642
|
break;
|
|
650
643
|
|
|
644
|
+
case 118
|
|
645
|
+
/*'v'*/
|
|
646
|
+
:
|
|
647
|
+
val.string += '\v';
|
|
648
|
+
break;
|
|
649
|
+
|
|
651
650
|
case 120
|
|
652
651
|
/*'x'*/
|
|
653
652
|
:
|
|
@@ -739,7 +738,17 @@ var json6 = createCommonjsModule(function (module, exports) {
|
|
|
739
738
|
status = false;
|
|
740
739
|
throwError("fault while parsing number;", cInt); // break;
|
|
741
740
|
}
|
|
742
|
-
} else if (cInt
|
|
741
|
+
} else if (fromHex && (cInt >= 95
|
|
742
|
+
/*'a'*/
|
|
743
|
+
&& cInt <= 102
|
|
744
|
+
/*'f'*/
|
|
745
|
+
|| cInt >= 65
|
|
746
|
+
/*'A'*/
|
|
747
|
+
&& cInt <= 70
|
|
748
|
+
/*'F'*/
|
|
749
|
+
)) {
|
|
750
|
+
val.string += str;
|
|
751
|
+
} else if (cInt == 120
|
|
743
752
|
/*'x'*/
|
|
744
753
|
|| cInt == 98
|
|
745
754
|
/*'b'*/
|
|
@@ -1375,6 +1384,16 @@ var json6 = createCommonjsModule(function (module, exports) {
|
|
|
1375
1384
|
throwError("fault parsing", cInt);
|
|
1376
1385
|
} // fault
|
|
1377
1386
|
|
|
1387
|
+
break;
|
|
1388
|
+
|
|
1389
|
+
case 43:
|
|
1390
|
+
//'+':
|
|
1391
|
+
if (word !== WORD_POS_RESET) {
|
|
1392
|
+
status = false;
|
|
1393
|
+
throwError("fault parsing", cInt);
|
|
1394
|
+
} // fault
|
|
1395
|
+
|
|
1396
|
+
|
|
1378
1397
|
break;
|
|
1379
1398
|
//
|
|
1380
1399
|
//----------------------------------------------------------
|
|
@@ -1548,7 +1567,215 @@ var json6 = createCommonjsModule(function (module, exports) {
|
|
|
1548
1567
|
return undefined;
|
|
1549
1568
|
};
|
|
1550
1569
|
|
|
1551
|
-
JSON6.stringify = JSON.stringify;
|
|
1570
|
+
JSON6.stringify = JSON.stringify; //---------------------------------------------------------------------------
|
|
1571
|
+
// Stringify
|
|
1572
|
+
//---------------------------------------------------------------------------
|
|
1573
|
+
|
|
1574
|
+
JSON6.stringifierActive = null;
|
|
1575
|
+
|
|
1576
|
+
JSON6.stringifier = function () {
|
|
1577
|
+
const keywords = {
|
|
1578
|
+
["true"]: true,
|
|
1579
|
+
["false"]: false,
|
|
1580
|
+
["null"]: null,
|
|
1581
|
+
["NaN"]: NaN,
|
|
1582
|
+
["Infinity"]: Infinity,
|
|
1583
|
+
["undefined"]: undefined
|
|
1584
|
+
};
|
|
1585
|
+
let useQuote = '"';
|
|
1586
|
+
let ignoreNonEnumerable = false;
|
|
1587
|
+
return {
|
|
1588
|
+
stringify(o, r, s, as) {
|
|
1589
|
+
return stringify(this, o, r, s, as);
|
|
1590
|
+
},
|
|
1591
|
+
|
|
1592
|
+
setQuote(q) {
|
|
1593
|
+
useQuote = q;
|
|
1594
|
+
},
|
|
1595
|
+
|
|
1596
|
+
get ignoreNonEnumerable() {
|
|
1597
|
+
return ignoreNonEnumerable;
|
|
1598
|
+
},
|
|
1599
|
+
|
|
1600
|
+
set ignoreNonEnumerable(val) {
|
|
1601
|
+
ignoreNonEnumerable = val;
|
|
1602
|
+
}
|
|
1603
|
+
|
|
1604
|
+
};
|
|
1605
|
+
|
|
1606
|
+
function getIdentifier(s) {
|
|
1607
|
+
if ("number" === typeof s && !isNaN(s)) {
|
|
1608
|
+
return ["'", s.toString(), "'"].join();
|
|
1609
|
+
}
|
|
1610
|
+
|
|
1611
|
+
if (!s.length) return useQuote + useQuote; // should check also for if any non ident in string...
|
|
1612
|
+
|
|
1613
|
+
return s in keywords
|
|
1614
|
+
/* [ "true","false","null","NaN","Infinity","undefined"].find( keyword=>keyword===s )*/
|
|
1615
|
+
|| /([0-9-])/.test(s[0]) || /((\n|\r|\t)|[ #{}()<>!+\-*/.:,])/.test(s) ? useQuote + JSON6.escape(s) + useQuote : s;
|
|
1616
|
+
}
|
|
1617
|
+
|
|
1618
|
+
function stringify(stringifier, object, replacer, space, asField) {
|
|
1619
|
+
if (object === undefined) return "undefined";
|
|
1620
|
+
if (object === null) return "null";
|
|
1621
|
+
let gap;
|
|
1622
|
+
let indent;
|
|
1623
|
+
let i;
|
|
1624
|
+
const spaceType = typeof space;
|
|
1625
|
+
const repType = typeof replacer;
|
|
1626
|
+
gap = "";
|
|
1627
|
+
indent = "";
|
|
1628
|
+
const stringifier_ = JSON6.stringifierActive;
|
|
1629
|
+
JSON6.stringifierActive = stringifier;
|
|
1630
|
+
|
|
1631
|
+
if (!asField) {
|
|
1632
|
+
asField = "";
|
|
1633
|
+
} // If the space parameter is a number, make an indent string containing that
|
|
1634
|
+
// many spaces.
|
|
1635
|
+
|
|
1636
|
+
|
|
1637
|
+
if (spaceType === "number") {
|
|
1638
|
+
for (i = 0; i < space; i += 1) {
|
|
1639
|
+
indent += " ";
|
|
1640
|
+
} // If the space parameter is a string, it will be used as the indent string.
|
|
1641
|
+
|
|
1642
|
+
} else if (spaceType === "string") {
|
|
1643
|
+
indent = space;
|
|
1644
|
+
} // If there is a replacer, it must be a function or an array.
|
|
1645
|
+
// Otherwise, throw an error.
|
|
1646
|
+
|
|
1647
|
+
|
|
1648
|
+
const rep = replacer;
|
|
1649
|
+
|
|
1650
|
+
if (replacer && repType !== "function" && (repType !== "object" || typeof replacer.length !== "number")) {
|
|
1651
|
+
throw new Error("JSON6.stringify unknown replacer type.");
|
|
1652
|
+
}
|
|
1653
|
+
|
|
1654
|
+
const r = str(asField, {
|
|
1655
|
+
[asField]: object
|
|
1656
|
+
});
|
|
1657
|
+
JSON6.stringifierActive = stringifier_; //DEBUG_STRINGIFY_OUTPUT && console.trace( "Stringify Result:", r );
|
|
1658
|
+
|
|
1659
|
+
return r; // from https://github.com/douglascrockford/JSON-js/blob/master/json2.js#L181
|
|
1660
|
+
|
|
1661
|
+
function str(key, holder) {
|
|
1662
|
+
// Produce a string from holder[key].
|
|
1663
|
+
let i; // The loop counter.
|
|
1664
|
+
|
|
1665
|
+
let k; // The member key.
|
|
1666
|
+
|
|
1667
|
+
let v; // The member value.
|
|
1668
|
+
|
|
1669
|
+
let length;
|
|
1670
|
+
const mind = gap;
|
|
1671
|
+
let partial;
|
|
1672
|
+
let value = holder[key];
|
|
1673
|
+
if ("string" === typeof value) value = getIdentifier(value);
|
|
1674
|
+
|
|
1675
|
+
if (value !== undefined && value !== null && typeof value === "object" && typeof toJSOX === "function") {
|
|
1676
|
+
// is encoding?
|
|
1677
|
+
gap += indent;
|
|
1678
|
+
gap = mind;
|
|
1679
|
+
} // If we were called with a replacer function, then call the replacer to
|
|
1680
|
+
// obtain a replacement value.
|
|
1681
|
+
|
|
1682
|
+
|
|
1683
|
+
if (typeof rep === "function") {
|
|
1684
|
+
value = rep.call(holder, key, value);
|
|
1685
|
+
} // What happens next depends on the value's type.
|
|
1686
|
+
|
|
1687
|
+
|
|
1688
|
+
switch (typeof value) {
|
|
1689
|
+
case "string":
|
|
1690
|
+
return value;
|
|
1691
|
+
|
|
1692
|
+
case "number":
|
|
1693
|
+
return '' + value;
|
|
1694
|
+
//useQuote+JSOX.escape( value )+useQuote;
|
|
1695
|
+
|
|
1696
|
+
case "boolean":
|
|
1697
|
+
return String(value);
|
|
1698
|
+
|
|
1699
|
+
case "object":
|
|
1700
|
+
//_DEBUG_STRINGIFY && console.log( "ENTERING OBJECT EMISSION WITH:", v );
|
|
1701
|
+
//if( v ) return v;
|
|
1702
|
+
// Due to a specification blunder in ECMAScript, typeof null is "object",
|
|
1703
|
+
// so watch out for that case.
|
|
1704
|
+
if (!value) {
|
|
1705
|
+
return "null";
|
|
1706
|
+
} // Make an array to hold the partial results of stringifying this object value.
|
|
1707
|
+
|
|
1708
|
+
|
|
1709
|
+
gap += indent;
|
|
1710
|
+
partial = []; // If the replacer is an array, use it to select the members to be stringified.
|
|
1711
|
+
|
|
1712
|
+
if (rep && typeof rep === "object") {
|
|
1713
|
+
length = rep.length; //_DEBUG_STRINGIFY && console.log( "Working through replacer" );
|
|
1714
|
+
|
|
1715
|
+
for (i = 0; i < length; i += 1) {
|
|
1716
|
+
if (typeof rep[i] === "string") {
|
|
1717
|
+
k = rep[i];
|
|
1718
|
+
v = str(k, value);
|
|
1719
|
+
|
|
1720
|
+
if (v) {
|
|
1721
|
+
partial.push(getIdentifier(k) + (gap ? ": " : ":") + v);
|
|
1722
|
+
}
|
|
1723
|
+
}
|
|
1724
|
+
}
|
|
1725
|
+
} else {
|
|
1726
|
+
// Otherwise, iterate through all of the keys in the object.
|
|
1727
|
+
const keys = []; //_DEBUG_STRINGIFY && console.log( "is something in something?", k, value );
|
|
1728
|
+
|
|
1729
|
+
for (k in value) {
|
|
1730
|
+
if (ignoreNonEnumerable) if (!Object.prototype.propertyIsEnumerable.call(value, k)) {
|
|
1731
|
+
//_DEBUG_STRINGIFY && console.log( "skipping non-enuerable?", k );
|
|
1732
|
+
continue;
|
|
1733
|
+
} // sort properties into keys.
|
|
1734
|
+
|
|
1735
|
+
if (Object.prototype.hasOwnProperty.call(value, k)) {
|
|
1736
|
+
let n;
|
|
1737
|
+
|
|
1738
|
+
for (n = 0; n < keys.length; n++) if (keys[n] > k) {
|
|
1739
|
+
keys.splice(n, 0, k);
|
|
1740
|
+
break;
|
|
1741
|
+
}
|
|
1742
|
+
|
|
1743
|
+
if (n === keys.length) keys.push(k);
|
|
1744
|
+
}
|
|
1745
|
+
} //_DEBUG_STRINGIFY && console.log( "Expanding object keys:", v, keys );
|
|
1746
|
+
|
|
1747
|
+
|
|
1748
|
+
for (let n = 0; n < keys.length; n++) {
|
|
1749
|
+
k = keys[n];
|
|
1750
|
+
|
|
1751
|
+
if (Object.prototype.hasOwnProperty.call(value, k)) {
|
|
1752
|
+
v = str(k, value);
|
|
1753
|
+
|
|
1754
|
+
if (v) {
|
|
1755
|
+
partial.push(getIdentifier(k) + (gap ? ": " : ":") + v);
|
|
1756
|
+
}
|
|
1757
|
+
}
|
|
1758
|
+
}
|
|
1759
|
+
} // Join all of the member texts together, separated with commas,
|
|
1760
|
+
// and wrap them in braces.
|
|
1761
|
+
//_DEBUG_STRINGIFY && console.log( "partial:", partial, protoConverter )
|
|
1762
|
+
|
|
1763
|
+
|
|
1764
|
+
v = '' + (partial.length === 0 ? "{}" : gap ? "{\n" + gap + partial.join(",\n" + gap) + "\n" + mind + "}" : "{" + partial.join(",") + "}");
|
|
1765
|
+
gap = mind; //_DEBUG_STRINGIFY && console.log(" Resulting phrase from this part is:", v );
|
|
1766
|
+
|
|
1767
|
+
return v;
|
|
1768
|
+
}
|
|
1769
|
+
}
|
|
1770
|
+
}
|
|
1771
|
+
};
|
|
1772
|
+
|
|
1773
|
+
JSON6.stringify = function (object, replacer, space) {
|
|
1774
|
+
const stringifier = JSON6.stringifier();
|
|
1775
|
+
return stringifier.stringify(object, replacer, space);
|
|
1776
|
+
};
|
|
1777
|
+
|
|
1778
|
+
JSON6.version = version;
|
|
1552
1779
|
});
|
|
1553
1780
|
|
|
1554
1781
|
var lib = json6;
|
package/lib/cli.js
CHANGED
|
File without changes
|
package/lib/import.mjs
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
// import.mjs
|
|
2
|
+
// Node.js only: adds a import() hook for .json6 files, just like the native
|
|
3
|
+
// hook for .json files.
|
|
4
|
+
//
|
|
5
|
+
// Usage:
|
|
6
|
+
// import {default as config} from "config.json6";
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
import fs from "fs";
|
|
10
|
+
import url from "url";
|
|
11
|
+
import path from "path";
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* @param {string} url
|
|
15
|
+
* @param {Object} context (currently empty)
|
|
16
|
+
* @param {Function} defaultGetFormat
|
|
17
|
+
* @returns {Promise<{ format: string }>}
|
|
18
|
+
*/
|
|
19
|
+
export async function getFormat(url, context, defaultGetFormat) {
|
|
20
|
+
const exten = path.extname( url );
|
|
21
|
+
//if( exten === '' ) return { format:'module' }
|
|
22
|
+
if( exten === ".json6" ){
|
|
23
|
+
return { format: 'module' };
|
|
24
|
+
}
|
|
25
|
+
return defaultGetFormat(url,context );
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* @param {string} url
|
|
30
|
+
* @param {{ format: string }} context
|
|
31
|
+
* @param {Function} defaultGetSource
|
|
32
|
+
* @returns {Promise<{ source: !(string | SharedArrayBuffer | Uint8Array) }>}
|
|
33
|
+
*/
|
|
34
|
+
export async function getSource(urlin, context, defaultGetSource) {
|
|
35
|
+
const exten = path.extname( urlin );
|
|
36
|
+
if( exten === ".json6" ){
|
|
37
|
+
//const { format } = context;
|
|
38
|
+
const file = url.fileURLToPath(urlin);
|
|
39
|
+
return {
|
|
40
|
+
source: fs.readFileSync(file, 'utf8'),
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
// Defer to Node.js for all other URLs.
|
|
44
|
+
return defaultGetSource(urlin, context, defaultGetSource);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* @param {!(string | SharedArrayBuffer | Uint8Array)} source
|
|
49
|
+
* @param {{
|
|
50
|
+
* format: string,
|
|
51
|
+
* url: string,
|
|
52
|
+
* }} context
|
|
53
|
+
* @param {Function} defaultTransformSource
|
|
54
|
+
* @returns {Promise<{ source: !(string | SharedArrayBuffer | Uint8Array) }>}
|
|
55
|
+
*/
|
|
56
|
+
export async function transformSource(source, context, defaultTransformSource) {
|
|
57
|
+
const exten = path.extname( context.url );
|
|
58
|
+
if( exten === ".json6" ){
|
|
59
|
+
return {
|
|
60
|
+
source: "const data = JSON6.parse( '" + escape(source) + "'); export default data;",
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
return defaultTransformSource(source, context, defaultTransformSource);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function escape(string) {
|
|
67
|
+
let output = '';
|
|
68
|
+
if( !string ) return string;
|
|
69
|
+
for( let n = 0; n < string.length; n++ ) {
|
|
70
|
+
const ch = string[n];
|
|
71
|
+
if( ch === '\n' ){
|
|
72
|
+
output += "\\n";
|
|
73
|
+
} else {
|
|
74
|
+
if( ( ch === '"' ) || ( ch === '\\' ) || ( ch === '`' )|| ( ch === '\'' )) {
|
|
75
|
+
output += '\\';
|
|
76
|
+
}
|
|
77
|
+
output += ch;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
return output;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* @returns {string} Code to run before application startup
|
|
85
|
+
*/
|
|
86
|
+
// Preloads JSON6 as a global resource; which is then used in the transformed source above.
|
|
87
|
+
export function getGlobalPreloadCode() {
|
|
88
|
+
return `\
|
|
89
|
+
const { createRequire } = getBuiltin('module');
|
|
90
|
+
const requireJSON6 = createRequire('${escape(url.fileURLToPath( import.meta.url ))}');
|
|
91
|
+
globalThis.JSON6 = requireJSON6( "../lib/index.js" );`;
|
|
92
|
+
}
|
package/lib/json6.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
// This file is based off of https://github.com/d3x0r/sack ./src/netlib/html5.websocket/json6_parser.c
|
|
5
5
|
//
|
|
6
6
|
"use strict";
|
|
7
|
-
|
|
7
|
+
const version = "1.1.1";
|
|
8
8
|
const VALUE_UNDEFINED = -1;
|
|
9
9
|
const VALUE_UNSET = 0;
|
|
10
10
|
const VALUE_NULL = 1;
|
|
@@ -111,10 +111,11 @@ JSON6.escape = function(string) {
|
|
|
111
111
|
let output = '';
|
|
112
112
|
if( !string ) return string;
|
|
113
113
|
for( let n = 0; n < string.length; n++ ) {
|
|
114
|
-
|
|
114
|
+
const ch = string[n];
|
|
115
|
+
if( ( ch == '"' ) || ( ch == '\\' ) || ( ch == '`' )|| ( ch == '\'' )) {
|
|
115
116
|
output += '\\';
|
|
116
117
|
}
|
|
117
|
-
output +=
|
|
118
|
+
output += ch;
|
|
118
119
|
}
|
|
119
120
|
return output;
|
|
120
121
|
};
|
|
@@ -504,6 +505,9 @@ JSON6.begin = function( cb, reviver ) {
|
|
|
504
505
|
case 102/*'f'*/:
|
|
505
506
|
val.string += '\f';
|
|
506
507
|
break;
|
|
508
|
+
case 118/*'v'*/:
|
|
509
|
+
val.string += '\v';
|
|
510
|
+
break;
|
|
507
511
|
case 120/*'x'*/:
|
|
508
512
|
stringHex = true;
|
|
509
513
|
hex_char_len = 0;
|
|
@@ -574,6 +578,9 @@ JSON6.begin = function( cb, reviver ) {
|
|
|
574
578
|
throwError( "fault while parsing number;", cInt );
|
|
575
579
|
// break;
|
|
576
580
|
}
|
|
581
|
+
} else if( fromHex && ( ( ( cInt >= 95/*'a'*/ ) && ( cInt <= 102/*'f'*/ ) ) ||
|
|
582
|
+
( ( cInt >= 65/*'A'*/ ) && ( cInt <= 70/*'F'*/ ) ) ) ) {
|
|
583
|
+
val.string += str;
|
|
577
584
|
} else if( cInt == 120/*'x'*/ || cInt == 98/*'b'*/ || cInt == 111/*'o'*/
|
|
578
585
|
|| cInt == 88/*'X'*/ || cInt == 66/*'B'*/ || cInt == 79/*'O'*/ ) {
|
|
579
586
|
// hex conversion.
|
|
@@ -1047,6 +1054,9 @@ JSON6.begin = function( cb, reviver ) {
|
|
|
1047
1054
|
if( word == WORD_POS_RESET ) negative = !negative;
|
|
1048
1055
|
else { status = false; throwError( "fault parsing", cInt ); }// fault
|
|
1049
1056
|
break;
|
|
1057
|
+
case 43://'+':
|
|
1058
|
+
if( word !== WORD_POS_RESET ) { status = false; throwError( "fault parsing", cInt ); }// fault
|
|
1059
|
+
break;
|
|
1050
1060
|
//
|
|
1051
1061
|
//----------------------------------------------------------
|
|
1052
1062
|
default:
|
|
@@ -1183,3 +1193,212 @@ JSON6.parse = function( msg, reviver ) {
|
|
|
1183
1193
|
return undefined;
|
|
1184
1194
|
};
|
|
1185
1195
|
JSON6.stringify = JSON.stringify;
|
|
1196
|
+
|
|
1197
|
+
//---------------------------------------------------------------------------
|
|
1198
|
+
// Stringify
|
|
1199
|
+
//---------------------------------------------------------------------------
|
|
1200
|
+
|
|
1201
|
+
JSON6.stringifierActive = null;
|
|
1202
|
+
JSON6.stringifier = function() {
|
|
1203
|
+
const keywords = { ["true"]:true,["false"]:false,["null"]:null,["NaN"]:NaN,["Infinity"]:Infinity,["undefined"]:undefined };
|
|
1204
|
+
let useQuote = '"';
|
|
1205
|
+
|
|
1206
|
+
let ignoreNonEnumerable = false;
|
|
1207
|
+
|
|
1208
|
+
return {
|
|
1209
|
+
stringify(o,r,s,as) { return stringify(this, o,r,s,as); },
|
|
1210
|
+
setQuote(q) { useQuote = q; },
|
|
1211
|
+
get ignoreNonEnumerable() { return ignoreNonEnumerable; },
|
|
1212
|
+
set ignoreNonEnumerable(val) { ignoreNonEnumerable = val; },
|
|
1213
|
+
};
|
|
1214
|
+
|
|
1215
|
+
function getIdentifier(s) {
|
|
1216
|
+
if( "number" === typeof s && !isNaN( s ) ) {
|
|
1217
|
+
return ["'",s.toString(),"'"].join();
|
|
1218
|
+
}
|
|
1219
|
+
if( !s.length ) return useQuote+useQuote;
|
|
1220
|
+
// should check also for if any non ident in string...
|
|
1221
|
+
return ( ( s in keywords /* [ "true","false","null","NaN","Infinity","undefined"].find( keyword=>keyword===s )*/
|
|
1222
|
+
|| /([0-9-])/.test(s[0])
|
|
1223
|
+
|| /((\n|\r|\t)|[ #{}()<>!+\-*/.:,])/.test( s ) )?(useQuote + JSON6.escape(s) +useQuote):s );
|
|
1224
|
+
}
|
|
1225
|
+
|
|
1226
|
+
function stringify( stringifier, object, replacer, space, asField ) {
|
|
1227
|
+
if( object === undefined ) return "undefined";
|
|
1228
|
+
if( object === null ) return "null";
|
|
1229
|
+
let gap;
|
|
1230
|
+
let indent;
|
|
1231
|
+
let i;
|
|
1232
|
+
const spaceType = typeof space;
|
|
1233
|
+
const repType = typeof replacer;
|
|
1234
|
+
gap = "";
|
|
1235
|
+
indent = "";
|
|
1236
|
+
const stringifier_ = JSON6.stringifierActive;
|
|
1237
|
+
JSON6.stringifierActive = stringifier;
|
|
1238
|
+
|
|
1239
|
+
if( !asField ) {
|
|
1240
|
+
asField = "";
|
|
1241
|
+
}
|
|
1242
|
+
|
|
1243
|
+
|
|
1244
|
+
// If the space parameter is a number, make an indent string containing that
|
|
1245
|
+
// many spaces.
|
|
1246
|
+
if (spaceType === "number") {
|
|
1247
|
+
for (i = 0; i < space; i += 1) {
|
|
1248
|
+
indent += " ";
|
|
1249
|
+
}
|
|
1250
|
+
|
|
1251
|
+
// If the space parameter is a string, it will be used as the indent string.
|
|
1252
|
+
} else if (spaceType === "string") {
|
|
1253
|
+
indent = space;
|
|
1254
|
+
}
|
|
1255
|
+
|
|
1256
|
+
// If there is a replacer, it must be a function or an array.
|
|
1257
|
+
// Otherwise, throw an error.
|
|
1258
|
+
const rep = replacer;
|
|
1259
|
+
if( replacer && repType !== "function"
|
|
1260
|
+
&& ( repType !== "object"
|
|
1261
|
+
|| typeof replacer.length !== "number"
|
|
1262
|
+
)) {
|
|
1263
|
+
throw new Error("JSON6.stringify unknown replacer type.");
|
|
1264
|
+
}
|
|
1265
|
+
|
|
1266
|
+
const r = str( asField, {[asField]:object} );
|
|
1267
|
+
JSON6.stringifierActive = stringifier_;
|
|
1268
|
+
//DEBUG_STRINGIFY_OUTPUT && console.trace( "Stringify Result:", r );
|
|
1269
|
+
return r;
|
|
1270
|
+
|
|
1271
|
+
|
|
1272
|
+
// from https://github.com/douglascrockford/JSON-js/blob/master/json2.js#L181
|
|
1273
|
+
function str(key, holder) {
|
|
1274
|
+
// Produce a string from holder[key].
|
|
1275
|
+
let i; // The loop counter.
|
|
1276
|
+
let k; // The member key.
|
|
1277
|
+
let v; // The member value.
|
|
1278
|
+
let length;
|
|
1279
|
+
const mind = gap;
|
|
1280
|
+
let partial;
|
|
1281
|
+
let value = holder[key];
|
|
1282
|
+
if( "string" === typeof value ) value = getIdentifier( value );
|
|
1283
|
+
|
|
1284
|
+
if( value !== undefined
|
|
1285
|
+
&& value !== null
|
|
1286
|
+
&& typeof value === "object"
|
|
1287
|
+
&& typeof toJSOX === "function"
|
|
1288
|
+
) {
|
|
1289
|
+
// is encoding?
|
|
1290
|
+
gap += indent;
|
|
1291
|
+
gap = mind;
|
|
1292
|
+
}
|
|
1293
|
+
// If we were called with a replacer function, then call the replacer to
|
|
1294
|
+
// obtain a replacement value.
|
|
1295
|
+
|
|
1296
|
+
if (typeof rep === "function") {
|
|
1297
|
+
value = rep.call(holder, key, value);
|
|
1298
|
+
}
|
|
1299
|
+
|
|
1300
|
+
// What happens next depends on the value's type.
|
|
1301
|
+
switch (typeof value) {
|
|
1302
|
+
case "string":
|
|
1303
|
+
return value;
|
|
1304
|
+
case "number":
|
|
1305
|
+
return '' + value;//useQuote+JSOX.escape( value )+useQuote;
|
|
1306
|
+
case "boolean":
|
|
1307
|
+
return String(value);
|
|
1308
|
+
case "object":
|
|
1309
|
+
|
|
1310
|
+
//_DEBUG_STRINGIFY && console.log( "ENTERING OBJECT EMISSION WITH:", v );
|
|
1311
|
+
//if( v ) return v;
|
|
1312
|
+
|
|
1313
|
+
// Due to a specification blunder in ECMAScript, typeof null is "object",
|
|
1314
|
+
// so watch out for that case.
|
|
1315
|
+
if (!value) {
|
|
1316
|
+
return "null";
|
|
1317
|
+
}
|
|
1318
|
+
|
|
1319
|
+
// Make an array to hold the partial results of stringifying this object value.
|
|
1320
|
+
|
|
1321
|
+
gap += indent;
|
|
1322
|
+
partial = [];
|
|
1323
|
+
|
|
1324
|
+
// If the replacer is an array, use it to select the members to be stringified.
|
|
1325
|
+
if (rep && typeof rep === "object") {
|
|
1326
|
+
length = rep.length;
|
|
1327
|
+
//_DEBUG_STRINGIFY && console.log( "Working through replacer" );
|
|
1328
|
+
for (i = 0; i < length; i += 1) {
|
|
1329
|
+
if (typeof rep[i] === "string") {
|
|
1330
|
+
k = rep[i];
|
|
1331
|
+
v = str(k, value);
|
|
1332
|
+
if (v) {
|
|
1333
|
+
partial.push(getIdentifier(k) + (
|
|
1334
|
+
(gap)
|
|
1335
|
+
? ": "
|
|
1336
|
+
: ":"
|
|
1337
|
+
) + v);
|
|
1338
|
+
}
|
|
1339
|
+
}
|
|
1340
|
+
}
|
|
1341
|
+
} else {
|
|
1342
|
+
|
|
1343
|
+
// Otherwise, iterate through all of the keys in the object.
|
|
1344
|
+
const keys = [];
|
|
1345
|
+
//_DEBUG_STRINGIFY && console.log( "is something in something?", k, value );
|
|
1346
|
+
for (k in value) {
|
|
1347
|
+
if( ignoreNonEnumerable )
|
|
1348
|
+
if( !Object.prototype.propertyIsEnumerable.call( value, k ) ){
|
|
1349
|
+
//_DEBUG_STRINGIFY && console.log( "skipping non-enuerable?", k );
|
|
1350
|
+
continue;
|
|
1351
|
+
}
|
|
1352
|
+
|
|
1353
|
+
// sort properties into keys.
|
|
1354
|
+
if (Object.prototype.hasOwnProperty.call(value, k)) {
|
|
1355
|
+
let n;
|
|
1356
|
+
for( n = 0; n < keys.length; n++ )
|
|
1357
|
+
if( keys[n] > k ) {
|
|
1358
|
+
keys.splice(n,0,k );
|
|
1359
|
+
break;
|
|
1360
|
+
}
|
|
1361
|
+
if( n === keys.length )
|
|
1362
|
+
keys.push(k);
|
|
1363
|
+
}
|
|
1364
|
+
}
|
|
1365
|
+
//_DEBUG_STRINGIFY && console.log( "Expanding object keys:", v, keys );
|
|
1366
|
+
for(let n = 0; n < keys.length; n++) {
|
|
1367
|
+
k = keys[n];
|
|
1368
|
+
if (Object.prototype.hasOwnProperty.call(value, k)) {
|
|
1369
|
+
v = str(k, value);
|
|
1370
|
+
if (v) {
|
|
1371
|
+
partial.push(getIdentifier(k)+ (
|
|
1372
|
+
(gap)
|
|
1373
|
+
? ": "
|
|
1374
|
+
: ":"
|
|
1375
|
+
) + v);
|
|
1376
|
+
}
|
|
1377
|
+
}
|
|
1378
|
+
}
|
|
1379
|
+
}
|
|
1380
|
+
|
|
1381
|
+
// Join all of the member texts together, separated with commas,
|
|
1382
|
+
// and wrap them in braces.
|
|
1383
|
+
//_DEBUG_STRINGIFY && console.log( "partial:", partial, protoConverter )
|
|
1384
|
+
v = '' +
|
|
1385
|
+
( partial.length === 0
|
|
1386
|
+
? "{}"
|
|
1387
|
+
: gap
|
|
1388
|
+
? "{\n" + gap + partial.join(",\n" + gap) + "\n" + mind + "}"
|
|
1389
|
+
: "{" + partial.join(",") + "}"
|
|
1390
|
+
);
|
|
1391
|
+
gap = mind;
|
|
1392
|
+
//_DEBUG_STRINGIFY && console.log(" Resulting phrase from this part is:", v );
|
|
1393
|
+
return v;
|
|
1394
|
+
}
|
|
1395
|
+
}
|
|
1396
|
+
}
|
|
1397
|
+
};
|
|
1398
|
+
|
|
1399
|
+
JSON6.stringify = function( object, replacer, space ) {
|
|
1400
|
+
const stringifier = JSON6.stringifier();
|
|
1401
|
+
return stringifier.stringify( object, replacer, space );
|
|
1402
|
+
};
|
|
1403
|
+
|
|
1404
|
+
JSON6.version = version;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "json-6",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.4",
|
|
4
4
|
"description": "JSON for the ES6 era.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"json",
|
|
@@ -51,8 +51,8 @@
|
|
|
51
51
|
"prepack": "npm run test-lite",
|
|
52
52
|
"lint": "eslint --cache .",
|
|
53
53
|
"build": "node ./lib/cli.js -c package.json6 && rollup -c",
|
|
54
|
-
"mocha-lite": "mocha --require chai/register-expect",
|
|
55
|
-
"mocha": "mocha --require chai/register-expect --recursive",
|
|
54
|
+
"mocha-lite": "mocha --require chai/register-expect --experimental-loader=./lib/import.mjs --require ./lib/require.js ",
|
|
55
|
+
"mocha": "mocha --require chai/register-expect --require ./lib/require.js --experimental-loader=./lib/import.mjs --recursive",
|
|
56
56
|
"nyc-lite": "nyc npm run mocha-lite",
|
|
57
57
|
"nyc": "nyc npm run mocha",
|
|
58
58
|
"test-lite": "npm run lint && npm run build && npm run nyc-lite",
|