arktype 1.0.13-alpha → 1.0.15-alpha
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 +68 -11
- package/dist/main.js +29 -0
- package/dist/nodes/branch.js +135 -0
- package/dist/nodes/compose.js +99 -0
- package/dist/{cjs/nodes → nodes}/discriminate.js +100 -92
- package/dist/nodes/node.js +134 -0
- package/dist/nodes/predicate.js +88 -0
- package/dist/nodes/rules/class.js +23 -0
- package/dist/nodes/rules/collapsibleSet.js +34 -0
- package/dist/nodes/rules/divisor.js +19 -0
- package/dist/nodes/rules/props.js +130 -0
- package/dist/nodes/rules/range.js +108 -0
- package/dist/nodes/rules/regex.js +17 -0
- package/dist/nodes/rules/rules.js +102 -0
- package/dist/parse/ast/ast.js +2 -0
- package/dist/{types/parse → parse}/ast/bound.d.ts +4 -1
- package/dist/parse/ast/bound.js +7 -0
- package/dist/parse/ast/config.js +14 -0
- package/dist/parse/ast/distributableFunction.js +40 -0
- package/dist/parse/ast/divisor.js +5 -0
- package/dist/parse/ast/intersection.js +21 -0
- package/dist/parse/ast/keyof.js +107 -0
- package/dist/parse/ast/morph.js +50 -0
- package/dist/parse/ast/narrow.js +17 -0
- package/dist/{types/parse → parse}/ast/node.d.ts +3 -1
- package/dist/parse/ast/node.js +2 -0
- package/dist/parse/ast/tuple.js +72 -0
- package/dist/parse/ast/union.js +5 -0
- package/dist/parse/ast/utils.js +2 -0
- package/dist/parse/definition.js +47 -0
- package/dist/parse/record.js +31 -0
- package/dist/parse/string/reduce/dynamic.js +159 -0
- package/dist/parse/string/reduce/shared.js +13 -0
- package/dist/parse/string/reduce/static.js +2 -0
- package/dist/parse/string/shift/operand/enclosed.js +37 -0
- package/dist/parse/string/shift/operand/operand.js +15 -0
- package/dist/parse/string/shift/operand/unenclosed.js +45 -0
- package/dist/parse/string/shift/operator/bounds.js +83 -0
- package/dist/parse/string/shift/operator/divisor.js +23 -0
- package/dist/parse/string/shift/operator/operator.js +34 -0
- package/dist/parse/string/shift/scanner.js +97 -0
- package/dist/parse/string/string.js +35 -0
- package/dist/scopes/ark.js +27 -0
- package/dist/scopes/cache.js +28 -0
- package/dist/{mjs/scopes → scopes}/expressions.js +20 -9
- package/dist/scopes/jsObjects.js +20 -0
- package/dist/scopes/scope.js +184 -0
- package/dist/scopes/tsKeywords.js +49 -0
- package/dist/scopes/type.js +40 -0
- package/dist/{mjs/scopes → scopes}/validation/creditCard.js +15 -11
- package/dist/{mjs/scopes → scopes}/validation/date.js +21 -16
- package/dist/scopes/validation/validation.js +74 -0
- package/dist/traverse/problems.js +234 -0
- package/dist/traverse/traverse.js +330 -0
- package/dist/tsconfig.temp.tsbuildinfo +1 -1
- package/dist/{mjs/utils → utils}/chainableNoOpProxy.js +6 -2
- package/dist/utils/data.js +39 -0
- package/dist/utils/domains.js +27 -0
- package/dist/utils/errors.js +17 -0
- package/dist/utils/freeze.js +16 -0
- package/dist/utils/generics.js +53 -0
- package/dist/utils/numericLiterals.js +88 -0
- package/dist/utils/objectKinds.js +69 -0
- package/dist/{mjs/utils → utils}/paths.js +8 -3
- package/dist/utils/serialize.js +71 -0
- package/dist/utils/unionToTuple.js +2 -0
- package/package.json +25 -39
- package/dist/cjs/main.js +0 -38
- package/dist/cjs/nodes/branch.js +0 -140
- package/dist/cjs/nodes/compose.js +0 -157
- package/dist/cjs/nodes/node.js +0 -139
- package/dist/cjs/nodes/predicate.js +0 -86
- package/dist/cjs/nodes/rules/class.js +0 -25
- package/dist/cjs/nodes/rules/collapsibleSet.js +0 -48
- package/dist/cjs/nodes/rules/divisor.js +0 -29
- package/dist/cjs/nodes/rules/props.js +0 -160
- package/dist/cjs/nodes/rules/range.js +0 -105
- package/dist/cjs/nodes/rules/regex.js +0 -26
- package/dist/cjs/nodes/rules/rules.js +0 -123
- package/dist/cjs/package.json +0 -3
- package/dist/cjs/parse/ast/ast.js +0 -4
- package/dist/cjs/parse/ast/bound.js +0 -9
- package/dist/cjs/parse/ast/config.js +0 -13
- package/dist/cjs/parse/ast/distributableFunction.js +0 -48
- package/dist/cjs/parse/ast/divisor.js +0 -9
- package/dist/cjs/parse/ast/intersection.js +0 -30
- package/dist/cjs/parse/ast/keyof.js +0 -111
- package/dist/cjs/parse/ast/morph.js +0 -58
- package/dist/cjs/parse/ast/narrow.js +0 -22
- package/dist/cjs/parse/ast/node.js +0 -4
- package/dist/cjs/parse/ast/tuple.js +0 -94
- package/dist/cjs/parse/ast/union.js +0 -9
- package/dist/cjs/parse/ast/utils.js +0 -4
- package/dist/cjs/parse/definition.js +0 -61
- package/dist/cjs/parse/record.js +0 -37
- package/dist/cjs/parse/string/reduce/dynamic.js +0 -167
- package/dist/cjs/parse/string/reduce/shared.js +0 -23
- package/dist/cjs/parse/string/reduce/static.js +0 -4
- package/dist/cjs/parse/string/shift/operand/enclosed.js +0 -54
- package/dist/cjs/parse/string/shift/operand/operand.js +0 -11
- package/dist/cjs/parse/string/shift/operand/unenclosed.js +0 -53
- package/dist/cjs/parse/string/shift/operator/bounds.js +0 -87
- package/dist/cjs/parse/string/shift/operator/divisor.js +0 -35
- package/dist/cjs/parse/string/shift/operator/operator.js +0 -26
- package/dist/cjs/parse/string/shift/scanner.js +0 -114
- package/dist/cjs/parse/string/string.js +0 -43
- package/dist/cjs/scopes/ark.js +0 -45
- package/dist/cjs/scopes/cache.js +0 -52
- package/dist/cjs/scopes/expressions.js +0 -29
- package/dist/cjs/scopes/jsObjects.js +0 -93
- package/dist/cjs/scopes/scope.js +0 -323
- package/dist/cjs/scopes/tsKeywords.js +0 -113
- package/dist/cjs/scopes/type.js +0 -50
- package/dist/cjs/scopes/validation/creditCard.js +0 -47
- package/dist/cjs/scopes/validation/date.js +0 -62
- package/dist/cjs/scopes/validation/validation.js +0 -104
- package/dist/cjs/traverse/problems.js +0 -281
- package/dist/cjs/traverse/traverse.js +0 -387
- package/dist/cjs/utils/chainableNoOpProxy.js +0 -23
- package/dist/cjs/utils/data.js +0 -53
- package/dist/cjs/utils/domains.js +0 -30
- package/dist/cjs/utils/errors.js +0 -26
- package/dist/cjs/utils/freeze.js +0 -15
- package/dist/cjs/utils/generics.js +0 -63
- package/dist/cjs/utils/numericLiterals.js +0 -75
- package/dist/cjs/utils/objectKinds.js +0 -69
- package/dist/cjs/utils/paths.js +0 -32
- package/dist/cjs/utils/serialize.js +0 -74
- package/dist/cjs/utils/unionToTuple.js +0 -4
- package/dist/mjs/main.js +0 -8
- package/dist/mjs/nodes/branch.js +0 -123
- package/dist/mjs/nodes/compose.js +0 -135
- package/dist/mjs/nodes/discriminate.js +0 -247
- package/dist/mjs/nodes/node.js +0 -117
- package/dist/mjs/nodes/predicate.js +0 -69
- package/dist/mjs/nodes/rules/class.js +0 -11
- package/dist/mjs/nodes/rules/collapsibleSet.js +0 -34
- package/dist/mjs/nodes/rules/divisor.js +0 -15
- package/dist/mjs/nodes/rules/props.js +0 -142
- package/dist/mjs/nodes/rules/range.js +0 -86
- package/dist/mjs/nodes/rules/regex.js +0 -11
- package/dist/mjs/nodes/rules/rules.js +0 -106
- package/dist/mjs/package.json +0 -3
- package/dist/mjs/parse/ast/ast.js +0 -1
- package/dist/mjs/parse/ast/bound.js +0 -1
- package/dist/mjs/parse/ast/config.js +0 -9
- package/dist/mjs/parse/ast/distributableFunction.js +0 -34
- package/dist/mjs/parse/ast/divisor.js +0 -1
- package/dist/mjs/parse/ast/intersection.js +0 -16
- package/dist/mjs/parse/ast/keyof.js +0 -103
- package/dist/mjs/parse/ast/morph.js +0 -44
- package/dist/mjs/parse/ast/narrow.js +0 -14
- package/dist/mjs/parse/ast/node.js +0 -1
- package/dist/mjs/parse/ast/tuple.js +0 -80
- package/dist/mjs/parse/ast/union.js +0 -1
- package/dist/mjs/parse/ast/utils.js +0 -1
- package/dist/mjs/parse/definition.js +0 -46
- package/dist/mjs/parse/record.js +0 -29
- package/dist/mjs/parse/string/reduce/dynamic.js +0 -159
- package/dist/mjs/parse/string/reduce/shared.js +0 -6
- package/dist/mjs/parse/string/reduce/static.js +0 -1
- package/dist/mjs/parse/string/shift/operand/enclosed.js +0 -39
- package/dist/mjs/parse/string/shift/operand/operand.js +0 -3
- package/dist/mjs/parse/string/shift/operand/unenclosed.js +0 -36
- package/dist/mjs/parse/string/shift/operator/bounds.js +0 -70
- package/dist/mjs/parse/string/shift/operator/divisor.js +0 -21
- package/dist/mjs/parse/string/shift/operator/operator.js +0 -13
- package/dist/mjs/parse/string/shift/scanner.js +0 -106
- package/dist/mjs/parse/string/string.js +0 -28
- package/dist/mjs/scopes/ark.js +0 -28
- package/dist/mjs/scopes/cache.js +0 -38
- package/dist/mjs/scopes/jsObjects.js +0 -82
- package/dist/mjs/scopes/scope.js +0 -303
- package/dist/mjs/scopes/tsKeywords.js +0 -116
- package/dist/mjs/scopes/type.js +0 -35
- package/dist/mjs/scopes/validation/validation.js +0 -108
- package/dist/mjs/traverse/problems.js +0 -260
- package/dist/mjs/traverse/traverse.js +0 -370
- package/dist/mjs/utils/data.js +0 -38
- package/dist/mjs/utils/domains.js +0 -15
- package/dist/mjs/utils/errors.js +0 -10
- package/dist/mjs/utils/freeze.js +0 -7
- package/dist/mjs/utils/generics.js +0 -38
- package/dist/mjs/utils/numericLiterals.js +0 -72
- package/dist/mjs/utils/objectKinds.js +0 -55
- package/dist/mjs/utils/serialize.js +0 -58
- package/dist/mjs/utils/unionToTuple.js +0 -1
- /package/dist/{types/main.d.ts → main.d.ts} +0 -0
- /package/dist/{types/nodes → nodes}/branch.d.ts +0 -0
- /package/dist/{types/nodes → nodes}/compose.d.ts +0 -0
- /package/dist/{types/nodes → nodes}/discriminate.d.ts +0 -0
- /package/dist/{types/nodes → nodes}/node.d.ts +0 -0
- /package/dist/{types/nodes → nodes}/predicate.d.ts +0 -0
- /package/dist/{types/nodes → nodes}/rules/class.d.ts +0 -0
- /package/dist/{types/nodes → nodes}/rules/collapsibleSet.d.ts +0 -0
- /package/dist/{types/nodes → nodes}/rules/divisor.d.ts +0 -0
- /package/dist/{types/nodes → nodes}/rules/props.d.ts +0 -0
- /package/dist/{types/nodes → nodes}/rules/range.d.ts +0 -0
- /package/dist/{types/nodes → nodes}/rules/regex.d.ts +0 -0
- /package/dist/{types/nodes → nodes}/rules/rules.d.ts +0 -0
- /package/dist/{types/parse → parse}/ast/ast.d.ts +0 -0
- /package/dist/{types/parse → parse}/ast/config.d.ts +0 -0
- /package/dist/{types/parse → parse}/ast/distributableFunction.d.ts +0 -0
- /package/dist/{types/parse → parse}/ast/divisor.d.ts +0 -0
- /package/dist/{types/parse → parse}/ast/intersection.d.ts +0 -0
- /package/dist/{types/parse → parse}/ast/keyof.d.ts +0 -0
- /package/dist/{types/parse → parse}/ast/morph.d.ts +0 -0
- /package/dist/{types/parse → parse}/ast/narrow.d.ts +0 -0
- /package/dist/{types/parse → parse}/ast/tuple.d.ts +0 -0
- /package/dist/{types/parse → parse}/ast/union.d.ts +0 -0
- /package/dist/{types/parse → parse}/ast/utils.d.ts +0 -0
- /package/dist/{types/parse → parse}/definition.d.ts +0 -0
- /package/dist/{types/parse → parse}/record.d.ts +0 -0
- /package/dist/{types/parse → parse}/string/reduce/dynamic.d.ts +0 -0
- /package/dist/{types/parse → parse}/string/reduce/shared.d.ts +0 -0
- /package/dist/{types/parse → parse}/string/reduce/static.d.ts +0 -0
- /package/dist/{types/parse → parse}/string/shift/operand/enclosed.d.ts +0 -0
- /package/dist/{types/parse → parse}/string/shift/operand/operand.d.ts +0 -0
- /package/dist/{types/parse → parse}/string/shift/operand/unenclosed.d.ts +0 -0
- /package/dist/{types/parse → parse}/string/shift/operator/bounds.d.ts +0 -0
- /package/dist/{types/parse → parse}/string/shift/operator/divisor.d.ts +0 -0
- /package/dist/{types/parse → parse}/string/shift/operator/operator.d.ts +0 -0
- /package/dist/{types/parse → parse}/string/shift/scanner.d.ts +0 -0
- /package/dist/{types/parse → parse}/string/string.d.ts +0 -0
- /package/dist/{types/scopes → scopes}/ark.d.ts +0 -0
- /package/dist/{types/scopes → scopes}/cache.d.ts +0 -0
- /package/dist/{types/scopes → scopes}/expressions.d.ts +0 -0
- /package/dist/{types/scopes → scopes}/jsObjects.d.ts +0 -0
- /package/dist/{types/scopes → scopes}/scope.d.ts +0 -0
- /package/dist/{types/scopes → scopes}/tsKeywords.d.ts +0 -0
- /package/dist/{types/scopes → scopes}/type.d.ts +0 -0
- /package/dist/{types/scopes → scopes}/validation/creditCard.d.ts +0 -0
- /package/dist/{types/scopes → scopes}/validation/date.d.ts +0 -0
- /package/dist/{types/scopes → scopes}/validation/validation.d.ts +0 -0
- /package/dist/{types/traverse → traverse}/problems.d.ts +0 -0
- /package/dist/{types/traverse → traverse}/traverse.d.ts +0 -0
- /package/dist/{types/utils → utils}/chainableNoOpProxy.d.ts +0 -0
- /package/dist/{types/utils → utils}/data.d.ts +0 -0
- /package/dist/{types/utils → utils}/domains.d.ts +0 -0
- /package/dist/{types/utils → utils}/errors.d.ts +0 -0
- /package/dist/{types/utils → utils}/freeze.d.ts +0 -0
- /package/dist/{types/utils → utils}/generics.d.ts +0 -0
- /package/dist/{types/utils → utils}/numericLiterals.d.ts +0 -0
- /package/dist/{types/utils → utils}/objectKinds.d.ts +0 -0
- /package/dist/{types/utils → utils}/paths.d.ts +0 -0
- /package/dist/{types/utils → utils}/serialize.d.ts +0 -0
- /package/dist/{types/utils → utils}/unionToTuple.d.ts +0 -0
package/dist/mjs/utils/freeze.js
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
export const deepFreeze = (value)=>Object.isFrozen(value) ? value : Array.isArray(value) ? Object.freeze(value.map(deepFreeze)) : deepFreezeDictionary(value);
|
|
2
|
-
const deepFreezeDictionary = (value)=>{
|
|
3
|
-
for(const k in value){
|
|
4
|
-
deepFreeze(value[k]);
|
|
5
|
-
}
|
|
6
|
-
return value;
|
|
7
|
-
};
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import { hasDomain } from "./domains.js";
|
|
2
|
-
export const asConst = (t)=>t;
|
|
3
|
-
export const isKeyOf = (k, obj)=>k in obj;
|
|
4
|
-
export const entriesOf = (o)=>Object.entries(o);
|
|
5
|
-
export const objectKeysOf = (o)=>Object.keys(o);
|
|
6
|
-
/** Mimics output of TS's keyof operator at runtime */ export const prototypeKeysOf = (value)=>{
|
|
7
|
-
const result = [];
|
|
8
|
-
while(value !== Object.prototype && value !== null && value !== undefined){
|
|
9
|
-
for (const k of Object.getOwnPropertyNames(value)){
|
|
10
|
-
if (!result.includes(k)) {
|
|
11
|
-
result.push(k);
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
for (const symbol of Object.getOwnPropertySymbols(value)){
|
|
15
|
-
if (!result.includes(symbol)) {
|
|
16
|
-
result.push(symbol);
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
value = Object.getPrototypeOf(value);
|
|
20
|
-
}
|
|
21
|
-
return result;
|
|
22
|
-
};
|
|
23
|
-
export const hasKey = (o, k)=>{
|
|
24
|
-
const valueAtKey = o?.[k];
|
|
25
|
-
return valueAtKey !== undefined && valueAtKey !== null;
|
|
26
|
-
};
|
|
27
|
-
export const hasSingleKey = (o, k)=>k in o && Object.keys(o).length === 1;
|
|
28
|
-
export const keyCount = (o)=>Object.keys(o).length;
|
|
29
|
-
export const hasKeys = (value)=>hasDomain(value, "object") ? Object.keys(value).length !== 0 : false;
|
|
30
|
-
const id = Symbol("id");
|
|
31
|
-
export const nominal = (o, name)=>Object.assign(o, {
|
|
32
|
-
[id]: name
|
|
33
|
-
});
|
|
34
|
-
export const getNominalId = (data)=>hasDomain(data, "object") && id in data ? data[id] : undefined;
|
|
35
|
-
export const hasNominalId = (data, name)=>getNominalId(data) === name;
|
|
36
|
-
export const listFrom = (data)=>Array.isArray(data) ? data : [
|
|
37
|
-
data
|
|
38
|
-
];
|
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
import { throwParseError } from "./errors.js";
|
|
2
|
-
/**
|
|
3
|
-
* The goal of the number literal and bigint literal regular expressions is to:
|
|
4
|
-
*
|
|
5
|
-
* 1. Ensure definitions form a bijection with the values they represent.
|
|
6
|
-
* 2. Attempt to mirror TypeScript's own format for stringification of numeric
|
|
7
|
-
* values such that the regex should match a given definition if any only if
|
|
8
|
-
* a precise literal type will be inferred (in TS4.8+).
|
|
9
|
-
*/ /**
|
|
10
|
-
* Matches a well-formatted numeric expression according to the following rules:
|
|
11
|
-
* 1. Must include an integer portion (i.e. '.321' must be written as '0.321')
|
|
12
|
-
* 2. The first digit of the value must not be 0, unless the entire integer portion is 0
|
|
13
|
-
* 3. If the value includes a decimal, its last digit may not be 0
|
|
14
|
-
* 4. The value may not be "-0"
|
|
15
|
-
*/ export const wellFormedNumberMatcher = /^(?!^-0$)-?(?:0|[1-9]\d*)(?:\.\d*[1-9])?$/;
|
|
16
|
-
const isWellFormedNumber = (s)=>wellFormedNumberMatcher.test(s);
|
|
17
|
-
const numberLikeMatcher = /^-?\d*\.?\d*$/;
|
|
18
|
-
const isNumberLike = (s)=>s.length !== 0 && numberLikeMatcher.test(s);
|
|
19
|
-
/**
|
|
20
|
-
* Matches a well-formatted integer according to the following rules:
|
|
21
|
-
* 1. Must begin with an integer, the first digit of which cannot be 0 unless the entire value is 0
|
|
22
|
-
* 2. The value may not be "-0"
|
|
23
|
-
*/ export const wellFormedIntegerMatcher = /^(?:0|(?:-?[1-9]\d*))$/;
|
|
24
|
-
export const isWellFormedInteger = (s)=>wellFormedIntegerMatcher.test(s);
|
|
25
|
-
export const wellFormedNonNegativeIntegerMatcher = /^(?:0|(?:[1-9]\d*))$/;
|
|
26
|
-
const integerLikeMatcher = /^-?\d+$/;
|
|
27
|
-
const isIntegerLike = (s)=>integerLikeMatcher.test(s);
|
|
28
|
-
const numericLiteralDescriptions = {
|
|
29
|
-
number: "a number",
|
|
30
|
-
bigint: "a bigint",
|
|
31
|
-
integer: "an integer"
|
|
32
|
-
};
|
|
33
|
-
export const writeMalformedNumericLiteralMessage = (def, kind)=>`'${def}' was parsed as ${numericLiteralDescriptions[kind]} but could not be narrowed to a literal value. Avoid unnecessary leading or trailing zeros and other abnormal notation`;
|
|
34
|
-
const isWellFormed = (def, kind)=>kind === "number" ? isWellFormedNumber(def) : isWellFormedInteger(def);
|
|
35
|
-
const parseKind = (def, kind)=>kind === "number" ? Number(def) : Number.parseInt(def);
|
|
36
|
-
const isKindLike = (def, kind)=>kind === "number" ? isNumberLike(def) : isIntegerLike(def);
|
|
37
|
-
export const tryParseWellFormedNumber = (token, errorOnFail)=>parseWellFormed(token, "number", errorOnFail);
|
|
38
|
-
export const tryParseWellFormedInteger = (token, errorOnFail)=>parseWellFormed(token, "integer", errorOnFail);
|
|
39
|
-
const parseWellFormed = (token, kind, errorOnFail)=>{
|
|
40
|
-
const value = parseKind(token, kind);
|
|
41
|
-
if (!Number.isNaN(value)) {
|
|
42
|
-
if (isWellFormed(token, kind)) {
|
|
43
|
-
return value;
|
|
44
|
-
}
|
|
45
|
-
if (isKindLike(token, kind)) {
|
|
46
|
-
// If the definition looks like the correct numeric kind but is
|
|
47
|
-
// not well-formed, always throw.
|
|
48
|
-
return throwParseError(writeMalformedNumericLiteralMessage(token, kind));
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
return errorOnFail ? throwParseError(errorOnFail === true ? `Failed to parse ${numericLiteralDescriptions[kind]} from '${token}'` : errorOnFail) : undefined;
|
|
52
|
-
};
|
|
53
|
-
export const tryParseWellFormedBigint = (def)=>{
|
|
54
|
-
if (def[def.length - 1] !== "n") {
|
|
55
|
-
return;
|
|
56
|
-
}
|
|
57
|
-
const maybeIntegerLiteral = def.slice(0, -1);
|
|
58
|
-
let value;
|
|
59
|
-
try {
|
|
60
|
-
value = BigInt(maybeIntegerLiteral);
|
|
61
|
-
} catch {
|
|
62
|
-
return;
|
|
63
|
-
}
|
|
64
|
-
if (wellFormedIntegerMatcher.test(maybeIntegerLiteral)) {
|
|
65
|
-
return value;
|
|
66
|
-
}
|
|
67
|
-
if (integerLikeMatcher.test(maybeIntegerLiteral)) {
|
|
68
|
-
// If the definition looks like a bigint but is
|
|
69
|
-
// not well-formed, throw.
|
|
70
|
-
return throwParseError(writeMalformedNumericLiteralMessage(def, "bigint"));
|
|
71
|
-
}
|
|
72
|
-
};
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import { domainOf } from "./domains.js";
|
|
2
|
-
import { isKeyOf } from "./generics.js";
|
|
3
|
-
// Built-in object constructors based on a subset of:
|
|
4
|
-
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects
|
|
5
|
-
export const defaultObjectKinds = {
|
|
6
|
-
Array,
|
|
7
|
-
Date,
|
|
8
|
-
Error,
|
|
9
|
-
Function,
|
|
10
|
-
Map,
|
|
11
|
-
RegExp,
|
|
12
|
-
Set,
|
|
13
|
-
Object,
|
|
14
|
-
String,
|
|
15
|
-
Number,
|
|
16
|
-
Boolean,
|
|
17
|
-
WeakMap,
|
|
18
|
-
WeakSet,
|
|
19
|
-
Promise
|
|
20
|
-
};
|
|
21
|
-
export const objectKindOf = (data, kinds)=>{
|
|
22
|
-
if (domainOf(data) !== "object") {
|
|
23
|
-
return undefined;
|
|
24
|
-
}
|
|
25
|
-
const kindSet = kinds ?? defaultObjectKinds;
|
|
26
|
-
let prototype = Object.getPrototypeOf(data);
|
|
27
|
-
while(prototype?.constructor && (!kindSet[prototype.constructor.name] || !(data instanceof kindSet[prototype.constructor.name]))){
|
|
28
|
-
prototype = Object.getPrototypeOf(prototype);
|
|
29
|
-
}
|
|
30
|
-
return prototype?.constructor?.name;
|
|
31
|
-
};
|
|
32
|
-
export const hasObjectKind = (data, kind, kinds)=>objectKindOf(data, kinds) === kind;
|
|
33
|
-
export const isArray = (data)=>Array.isArray(data);
|
|
34
|
-
/** Each defaultObjectKind's completion for the phrase "Must be _____" */ export const objectKindDescriptions = {
|
|
35
|
-
Object: "an object",
|
|
36
|
-
Array: "an array",
|
|
37
|
-
Function: "a function",
|
|
38
|
-
Date: "a Date",
|
|
39
|
-
RegExp: "a RegExp",
|
|
40
|
-
Error: "an Error",
|
|
41
|
-
Map: "a Map",
|
|
42
|
-
Set: "a Set",
|
|
43
|
-
String: "a String object",
|
|
44
|
-
Number: "a Number object",
|
|
45
|
-
Boolean: "a Boolean object",
|
|
46
|
-
Promise: "a Promise",
|
|
47
|
-
WeakMap: "a WeakMap",
|
|
48
|
-
WeakSet: "a WeakSet"
|
|
49
|
-
};
|
|
50
|
-
// this will only return an object kind if it's the root constructor
|
|
51
|
-
// example TypeError would return undefined not 'Error'
|
|
52
|
-
export const getExactConstructorObjectKind = (constructor)=>{
|
|
53
|
-
const constructorName = Object(constructor).name;
|
|
54
|
-
return constructorName && isKeyOf(constructorName, defaultObjectKinds) && defaultObjectKinds[constructorName] === constructor ? constructorName : undefined;
|
|
55
|
-
};
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import { domainOf } from "./domains.js";
|
|
2
|
-
import { isKeyOf } from "./generics.js";
|
|
3
|
-
import { tryParseWellFormedBigint, tryParseWellFormedNumber } from "./numericLiterals.js";
|
|
4
|
-
export const snapshot = (data, opts = {})=>serializeRecurse(data, opts, []);
|
|
5
|
-
export const stringify = (data, indent)=>{
|
|
6
|
-
switch(domainOf(data)){
|
|
7
|
-
case "object":
|
|
8
|
-
return JSON.stringify(serializeRecurse(data, stringifyOpts, []), null, indent);
|
|
9
|
-
case "symbol":
|
|
10
|
-
return stringifyOpts.onSymbol(data);
|
|
11
|
-
default:
|
|
12
|
-
return serializePrimitive(data);
|
|
13
|
-
}
|
|
14
|
-
};
|
|
15
|
-
const stringifyOpts = {
|
|
16
|
-
onCycle: ()=>"(cycle)",
|
|
17
|
-
onSymbol: (v)=>`(symbol${v.description && ` ${v.description}`})`,
|
|
18
|
-
onFunction: (v)=>`(function${v.name && ` ${v.name}`})`
|
|
19
|
-
};
|
|
20
|
-
const serializeRecurse = (data, context, seen)=>{
|
|
21
|
-
switch(domainOf(data)){
|
|
22
|
-
case "object":
|
|
23
|
-
if (typeof data === "function") {
|
|
24
|
-
return stringifyOpts.onFunction(data);
|
|
25
|
-
}
|
|
26
|
-
if (seen.includes(data)) {
|
|
27
|
-
return "(cycle)";
|
|
28
|
-
}
|
|
29
|
-
const nextSeen = [
|
|
30
|
-
...seen,
|
|
31
|
-
data
|
|
32
|
-
];
|
|
33
|
-
if (Array.isArray(data)) {
|
|
34
|
-
return data.map((item)=>serializeRecurse(item, context, nextSeen));
|
|
35
|
-
}
|
|
36
|
-
const result = {};
|
|
37
|
-
for(const k in data){
|
|
38
|
-
result[k] = serializeRecurse(data[k], context, nextSeen);
|
|
39
|
-
}
|
|
40
|
-
return result;
|
|
41
|
-
case "symbol":
|
|
42
|
-
return stringifyOpts.onSymbol(data);
|
|
43
|
-
case "bigint":
|
|
44
|
-
return `${data}n`;
|
|
45
|
-
case "undefined":
|
|
46
|
-
return "undefined";
|
|
47
|
-
default:
|
|
48
|
-
return data;
|
|
49
|
-
}
|
|
50
|
-
};
|
|
51
|
-
export const serializePrimitive = (value)=>typeof value === "string" ? `'${value}'` : typeof value === "bigint" ? `${value}n` : `${value}`;
|
|
52
|
-
export const deserializePrimitive = (serialized)=>isKeyOf(serialized, serializedKeywords) ? serializedKeywords[serialized] : serialized[0] === "'" ? serialized.slice(1, -1) : tryParseWellFormedBigint(serialized) ?? tryParseWellFormedNumber(serialized, true);
|
|
53
|
-
const serializedKeywords = {
|
|
54
|
-
true: true,
|
|
55
|
-
false: false,
|
|
56
|
-
undefined,
|
|
57
|
-
null: null
|
|
58
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { };
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|