type-plus 3.15.0 → 4.0.0
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 +1 -55
- package/cjs/index.d.ts +0 -4
- package/cjs/index.js +5 -18
- package/cjs/index.js.map +1 -1
- package/esm/index.js +4 -4
- package/esm/index.js.map +1 -1
- package/package.json +1 -1
- package/ts/index.ts +4 -4
- package/ts/type-checker/typeChecker.spec.ts +2 -1
- package/ts/types/check.spec.ts +1 -1
- package/ts/types/conform.spec.ts +1 -1
- package/ts/types/satisfy.accept.ts +39 -38
- package/ts/types/satisfy.spec.ts +2 -1
- package/cjs/types/AllType.d.ts +0 -18
- package/cjs/types/AllType.js +0 -3
- package/cjs/types/AllType.js.map +0 -1
- package/cjs/types/Any.d.ts +0 -6
- package/cjs/types/Any.js +0 -5
- package/cjs/types/Any.js.map +0 -1
- package/cjs/types/Array.d.ts +0 -28
- package/cjs/types/Array.js +0 -30
- package/cjs/types/Array.js.map +0 -1
- package/cjs/types/Boolean.d.ts +0 -29
- package/cjs/types/Boolean.js +0 -28
- package/cjs/types/Boolean.js.map +0 -1
- package/cjs/types/Generate.d.ts +0 -32
- package/cjs/types/Generate.js +0 -3
- package/cjs/types/Generate.js.map +0 -1
- package/cjs/types/Null.d.ts +0 -8
- package/cjs/types/Null.js +0 -10
- package/cjs/types/Null.js.map +0 -1
- package/cjs/types/Number.d.ts +0 -36
- package/cjs/types/Number.js +0 -50
- package/cjs/types/Number.js.map +0 -1
- package/cjs/types/Object.d.ts +0 -313
- package/cjs/types/Object.js +0 -35
- package/cjs/types/Object.js.map +0 -1
- package/cjs/types/Record.d.ts +0 -16
- package/cjs/types/Record.js +0 -17
- package/cjs/types/Record.js.map +0 -1
- package/cjs/types/String.d.ts +0 -36
- package/cjs/types/String.js +0 -51
- package/cjs/types/String.js.map +0 -1
- package/cjs/types/Symbol.d.ts +0 -8
- package/cjs/types/Symbol.js +0 -13
- package/cjs/types/Symbol.js.map +0 -1
- package/cjs/types/Tuple.d.ts +0 -35
- package/cjs/types/Tuple.js +0 -43
- package/cjs/types/Tuple.js.map +0 -1
- package/cjs/types/Undefined.d.ts +0 -6
- package/cjs/types/Undefined.js +0 -5
- package/cjs/types/Undefined.js.map +0 -1
- package/cjs/types/Union.d.ts +0 -20
- package/cjs/types/Union.js +0 -52
- package/cjs/types/Union.js.map +0 -1
- package/cjs/types/Unknown.d.ts +0 -6
- package/cjs/types/Unknown.js +0 -5
- package/cjs/types/Unknown.js.map +0 -1
- package/cjs/types/analyze.d.ts +0 -13
- package/cjs/types/analyze.js +0 -159
- package/cjs/types/analyze.js.map +0 -1
- package/cjs/types/check.d.ts +0 -14
- package/cjs/types/check.js +0 -25
- package/cjs/types/check.js.map +0 -1
- package/cjs/types/conform.d.ts +0 -15
- package/cjs/types/conform.js +0 -26
- package/cjs/types/conform.js.map +0 -1
- package/cjs/types/getPlainAnalysisReport.d.ts +0 -2
- package/cjs/types/getPlainAnalysisReport.js +0 -120
- package/cjs/types/getPlainAnalysisReport.js.map +0 -1
- package/cjs/types/index.d.ts +0 -26
- package/cjs/types/index.js +0 -45
- package/cjs/types/index.js.map +0 -1
- package/cjs/types/optional.d.ts +0 -328
- package/cjs/types/optional.js +0 -33
- package/cjs/types/optional.js.map +0 -1
- package/cjs/types/required.d.ts +0 -664
- package/cjs/types/required.js +0 -33
- package/cjs/types/required.js.map +0 -1
- package/cjs/types/satisfy.d.ts +0 -15
- package/cjs/types/satisfy.js +0 -26
- package/cjs/types/satisfy.js.map +0 -1
- package/cjs/types/types.d.ts +0 -9
- package/cjs/types/types.js +0 -3
- package/cjs/types/types.js.map +0 -1
- package/esm/types/AllType.js +0 -2
- package/esm/types/AllType.js.map +0 -1
- package/esm/types/Any.js +0 -2
- package/esm/types/Any.js.map +0 -1
- package/esm/types/Array.js +0 -27
- package/esm/types/Array.js.map +0 -1
- package/esm/types/Boolean.js +0 -25
- package/esm/types/Boolean.js.map +0 -1
- package/esm/types/Generate.js +0 -2
- package/esm/types/Generate.js.map +0 -1
- package/esm/types/Null.js +0 -7
- package/esm/types/Null.js.map +0 -1
- package/esm/types/Number.js +0 -30
- package/esm/types/Number.js.map +0 -1
- package/esm/types/Object.js +0 -31
- package/esm/types/Object.js.map +0 -1
- package/esm/types/Record.js +0 -14
- package/esm/types/Record.js.map +0 -1
- package/esm/types/String.js +0 -31
- package/esm/types/String.js.map +0 -1
- package/esm/types/Symbol.js +0 -10
- package/esm/types/Symbol.js.map +0 -1
- package/esm/types/Tuple.js +0 -23
- package/esm/types/Tuple.js.map +0 -1
- package/esm/types/Undefined.js +0 -2
- package/esm/types/Undefined.js.map +0 -1
- package/esm/types/Union.js +0 -32
- package/esm/types/Union.js.map +0 -1
- package/esm/types/Unknown.js +0 -2
- package/esm/types/Unknown.js.map +0 -1
- package/esm/types/analyze.js +0 -142
- package/esm/types/analyze.js.map +0 -1
- package/esm/types/check.js +0 -21
- package/esm/types/check.js.map +0 -1
- package/esm/types/conform.js +0 -22
- package/esm/types/conform.js.map +0 -1
- package/esm/types/getPlainAnalysisReport.js +0 -106
- package/esm/types/getPlainAnalysisReport.js.map +0 -1
- package/esm/types/index.js +0 -28
- package/esm/types/index.js.map +0 -1
- package/esm/types/optional.js +0 -30
- package/esm/types/optional.js.map +0 -1
- package/esm/types/required.js +0 -30
- package/esm/types/required.js.map +0 -1
- package/esm/types/satisfy.js +0 -22
- package/esm/types/satisfy.js.map +0 -1
- package/esm/types/types.js +0 -2
- package/esm/types/types.js.map +0 -1
package/cjs/types/required.js
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.R = exports.required = void 0;
|
|
4
|
-
var Object_1 = require("./Object");
|
|
5
|
-
var Any_1 = require("./Any");
|
|
6
|
-
var Array_1 = require("./Array");
|
|
7
|
-
var Boolean_1 = require("./Boolean");
|
|
8
|
-
var Null_1 = require("./Null");
|
|
9
|
-
var Number_1 = require("./Number");
|
|
10
|
-
var String_1 = require("./String");
|
|
11
|
-
var Symbol_1 = require("./Symbol");
|
|
12
|
-
var Tuple_1 = require("./Tuple");
|
|
13
|
-
var Undefined_1 = require("./Undefined");
|
|
14
|
-
var Unknown_1 = require("./Unknown");
|
|
15
|
-
var Record_1 = require("./Record");
|
|
16
|
-
// import { bigint } from './types/BigInt'
|
|
17
|
-
exports.required = {
|
|
18
|
-
any: Any_1.any,
|
|
19
|
-
array: Array_1.array,
|
|
20
|
-
// bigint: bigint,
|
|
21
|
-
boolean: Boolean_1.boolean,
|
|
22
|
-
null: Null_1.nil,
|
|
23
|
-
number: Number_1.number,
|
|
24
|
-
object: Object_1.object,
|
|
25
|
-
record: Record_1.record,
|
|
26
|
-
string: String_1.string,
|
|
27
|
-
symbol: Symbol_1.symbol,
|
|
28
|
-
tuple: Tuple_1.tuple,
|
|
29
|
-
undefined: Undefined_1.undef,
|
|
30
|
-
unknown: Unknown_1.unknown
|
|
31
|
-
};
|
|
32
|
-
exports.R = exports.required;
|
|
33
|
-
//# sourceMappingURL=required.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"required.js","sourceRoot":"","sources":["../../ts/types/required.ts"],"names":[],"mappings":";;;AAAA,mCAAiC;AACjC,6BAA2B;AAC3B,iCAA+B;AAC/B,qCAAmC;AACnC,+BAA4B;AAC5B,mCAAiC;AACjC,mCAAiC;AACjC,mCAAiC;AACjC,iCAA+B;AAC/B,yCAAmC;AACnC,qCAAmC;AACnC,mCAAiC;AACjC,0CAA0C;AAE7B,QAAA,QAAQ,GAAG;IACtB,GAAG,WAAA;IACH,KAAK,EAAE,aAAK;IACZ,kBAAkB;IAClB,OAAO,EAAE,iBAAO;IAChB,IAAI,EAAE,UAAG;IACT,MAAM,EAAE,eAAM;IACd,MAAM,EAAE,eAAM;IACd,MAAM,EAAE,eAAM;IACd,MAAM,EAAE,eAAM;IACd,MAAM,EAAE,eAAM;IACd,KAAK,EAAE,aAAK;IACZ,SAAS,EAAE,iBAAK;IAChB,OAAO,mBAAA;CACR,CAAA;AACY,QAAA,CAAC,GAAG,gBAAQ,CAAA"}
|
package/cjs/types/satisfy.d.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { AllType } from './AllType';
|
|
2
|
-
import { analyze } from './analyze';
|
|
3
|
-
import { Generate } from './Generate';
|
|
4
|
-
/**
|
|
5
|
-
* Checks if the specified `subject` satisfies the `type`.
|
|
6
|
-
* `satisfy()` is the shortcut of `check({ strict: false }, ...)`.
|
|
7
|
-
* @return type guard (boolean). If the subject does not satisfies the type,
|
|
8
|
-
* the detail report is available in `satisfy.result`,
|
|
9
|
-
* and you can get a string report using `satisfy.getReport()`
|
|
10
|
-
*/
|
|
11
|
-
export declare function satisfy<T extends AllType>(type: T, subject: unknown): subject is Generate<T>;
|
|
12
|
-
export declare namespace satisfy {
|
|
13
|
-
var result: analyze.Result;
|
|
14
|
-
var getReport: () => string;
|
|
15
|
-
}
|
package/cjs/types/satisfy.js
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.satisfy = void 0;
|
|
4
|
-
var analyze_1 = require("./analyze");
|
|
5
|
-
var getPlainAnalysisReport_1 = require("./getPlainAnalysisReport");
|
|
6
|
-
/**
|
|
7
|
-
* Checks if the specified `subject` satisfies the `type`.
|
|
8
|
-
* `satisfy()` is the shortcut of `check({ strict: false }, ...)`.
|
|
9
|
-
* @return type guard (boolean). If the subject does not satisfies the type,
|
|
10
|
-
* the detail report is available in `satisfy.result`,
|
|
11
|
-
* and you can get a string report using `satisfy.getReport()`
|
|
12
|
-
*/
|
|
13
|
-
function satisfy(type, subject) {
|
|
14
|
-
var result = satisfy.result = (0, analyze_1.analyze)({ strict: false }, type, subject);
|
|
15
|
-
return !result.analysis.fail;
|
|
16
|
-
}
|
|
17
|
-
exports.satisfy = satisfy;
|
|
18
|
-
/**
|
|
19
|
-
* Analysis report.
|
|
20
|
-
*/
|
|
21
|
-
satisfy.result = { analysis: {} };
|
|
22
|
-
/**
|
|
23
|
-
* Gets a simple report of the analysis.
|
|
24
|
-
*/
|
|
25
|
-
satisfy.getReport = function () { return (0, getPlainAnalysisReport_1.getPlainAnalysisReport)(satisfy.result); };
|
|
26
|
-
//# sourceMappingURL=satisfy.js.map
|
package/cjs/types/satisfy.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"satisfy.js","sourceRoot":"","sources":["../../ts/types/satisfy.ts"],"names":[],"mappings":";;;AACA,qCAAmC;AAEnC,mEAAiE;AAEjE;;;;;;GAMG;AACH,SAAgB,OAAO,CAAoB,IAAO,EAAE,OAAgB;IAClE,IAAM,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAA,iBAAO,EAAC,EAAE,MAAM,EAAE,KAAK,EAAE,EAAE,IAAI,EAAE,OAAO,CAAC,CAAA;IACzE,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAA;AAC9B,CAAC;AAHD,0BAGC;AAED;;GAEG;AACH,OAAO,CAAC,MAAM,GAAG,EAAE,QAAQ,EAAE,EAAE,EAAoB,CAAA;AAEnD;;GAEG;AACH,OAAO,CAAC,SAAS,GAAG,cAAM,OAAA,IAAA,+CAAsB,EAAC,OAAO,CAAC,MAAM,CAAC,EAAtC,CAAsC,CAAA"}
|
package/cjs/types/types.d.ts
DELETED
package/cjs/types/types.js
DELETED
package/cjs/types/types.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../ts/types/types.ts"],"names":[],"mappings":""}
|
package/esm/types/AllType.js
DELETED
package/esm/types/AllType.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"AllType.js","sourceRoot":"","sources":["../../ts/types/AllType.ts"],"names":[],"mappings":""}
|
package/esm/types/Any.js
DELETED
package/esm/types/Any.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Any.js","sourceRoot":"","sources":["../../ts/types/Any.ts"],"names":[],"mappings":"AAMA,MAAM,CAAC,MAAM,GAAG,GAAQ,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,SAAS,EAAE,CAAA"}
|
package/esm/types/Array.js
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { undef } from './Undefined';
|
|
2
|
-
import { union } from './Union';
|
|
3
|
-
import { unknown } from './Unknown';
|
|
4
|
-
/**
|
|
5
|
-
* Creates an array type.
|
|
6
|
-
*/
|
|
7
|
-
function create(value) {
|
|
8
|
-
return {
|
|
9
|
-
type: 'array',
|
|
10
|
-
value
|
|
11
|
-
};
|
|
12
|
-
}
|
|
13
|
-
const any = create(undefined);
|
|
14
|
-
export const array = Object.assign({}, any, {
|
|
15
|
-
any,
|
|
16
|
-
create,
|
|
17
|
-
optional: Object.assign(union.create(any, undef), {
|
|
18
|
-
/**
|
|
19
|
-
* Creates an optional array type.
|
|
20
|
-
*/
|
|
21
|
-
create(value) {
|
|
22
|
-
return union.create(create(value), undef);
|
|
23
|
-
}
|
|
24
|
-
}),
|
|
25
|
-
unknown: create(unknown)
|
|
26
|
-
});
|
|
27
|
-
//# sourceMappingURL=Array.js.map
|
package/esm/types/Array.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Array.js","sourceRoot":"","sources":["../../ts/types/Array.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,KAAK,EAAa,MAAM,aAAa,CAAA;AAC9C,OAAO,EAAE,KAAK,EAAS,MAAM,SAAS,CAAA;AACtC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAanC;;GAEG;AACH,SAAS,MAAM,CAAwB,KAAY;IACjD,OAAO;QACL,IAAI,EAAE,OAAO;QACb,KAAK;KACN,CAAA;AACH,CAAC;AAED,MAAM,GAAG,GAAG,MAAM,CAAC,SAA2B,CAAC,CAAA;AAE/C,MAAM,CAAC,MAAM,KAAK,GAAG,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,GAAG,EAAE;IAC1C,GAAG;IACH,MAAM;IACN,QAAQ,EAAE,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE;QAChD;;WAEG;QACH,MAAM,CAAwB,KAAY;YACxC,OAAO,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,KAAK,CAAC,CAAA;QAC3C,CAAC;KACF,CAAC;IACF,OAAO,EAAE,MAAM,CAAC,OAAO,CAAC;CACzB,CAAC,CAAA"}
|
package/esm/types/Boolean.js
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { undef } from './Undefined';
|
|
2
|
-
import { union } from './Union';
|
|
3
|
-
function create(value) {
|
|
4
|
-
return { type: 'boolean', value };
|
|
5
|
-
}
|
|
6
|
-
const any = create(undefined);
|
|
7
|
-
const t = create(true);
|
|
8
|
-
const f = create(false);
|
|
9
|
-
export const boolean = Object.assign(any, {
|
|
10
|
-
any,
|
|
11
|
-
true: t,
|
|
12
|
-
false: f,
|
|
13
|
-
create,
|
|
14
|
-
optional: Object.assign(union.create(any, undef), {
|
|
15
|
-
/**
|
|
16
|
-
* Creates an optional boolean type.
|
|
17
|
-
*/
|
|
18
|
-
create(value) {
|
|
19
|
-
return union.create(create(value), undef);
|
|
20
|
-
},
|
|
21
|
-
true: union.create(t, undef),
|
|
22
|
-
false: union.create(f, undef),
|
|
23
|
-
})
|
|
24
|
-
});
|
|
25
|
-
//# sourceMappingURL=Boolean.js.map
|
package/esm/types/Boolean.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Boolean.js","sourceRoot":"","sources":["../../ts/types/Boolean.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAa,MAAM,aAAa,CAAA;AAC9C,OAAO,EAAS,KAAK,EAAE,MAAM,SAAS,CAAA;AAUtC,SAAS,MAAM,CAAwB,KAAY;IACjD,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,CAAA;AACnC,CAAC;AAED,MAAM,GAAG,GAAG,MAAM,CAAC,SAA+B,CAAC,CAAA;AACnD,MAAM,CAAC,GAAG,MAAM,CAAC,IAAI,CAAC,CAAA;AACtB,MAAM,CAAC,GAAG,MAAM,CAAC,KAAK,CAAC,CAAA;AAEvB,MAAM,CAAC,MAAM,OAAO,GAAG,MAAM,CAAC,MAAM,CAAC,GAAG,EAAE;IACxC,GAAG;IACH,IAAI,EAAE,CAAC;IACP,KAAK,EAAE,CAAC;IACR,MAAM;IACN,QAAQ,EAAE,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE;QAChD;;WAEG;QACH,MAAM,CAAwB,KAAY;YACxC,OAAO,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,KAAK,CAAC,CAAA;QAC3C,CAAC;QACD,IAAI,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC,EAAE,KAAK,CAAC;QAC5B,KAAK,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC,EAAE,KAAK,CAAC;KAC9B,CAAC;CACH,CAAC,CAAA"}
|
package/esm/types/Generate.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Generate.js","sourceRoot":"","sources":["../../ts/types/Generate.ts"],"names":[],"mappings":""}
|
package/esm/types/Null.js
DELETED
package/esm/types/Null.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Null.js","sourceRoot":"","sources":["../../ts/types/Null.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAA;AACnC,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;AAO/B,MAAM,GAAG,GAAS,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,SAAS,EAAE,CAAA;AAEpD,MAAM,CAAC,MAAM,GAAG,GAAG,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,GAAG,EAAE;IACxC,QAAQ,EAAE,KAAK,CAAC,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC;CACnC,CAAC,CAAA"}
|
package/esm/types/Number.js
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { undef } from './Undefined';
|
|
2
|
-
import { union } from './Union';
|
|
3
|
-
/**
|
|
4
|
-
* Creates a single number type.
|
|
5
|
-
*/
|
|
6
|
-
function create(value) {
|
|
7
|
-
return { type: 'number', value };
|
|
8
|
-
}
|
|
9
|
-
const any = create(undefined);
|
|
10
|
-
export const number = Object.assign(any, {
|
|
11
|
-
any,
|
|
12
|
-
create,
|
|
13
|
-
// @ts-ignore we know that this can be infinite
|
|
14
|
-
list(value, ...values) {
|
|
15
|
-
return union.create(create(value), ...values.map(create));
|
|
16
|
-
},
|
|
17
|
-
optional: Object.assign(union.create(any, undef), {
|
|
18
|
-
/**
|
|
19
|
-
* Creates an optional number constant type.
|
|
20
|
-
*/
|
|
21
|
-
create(value) {
|
|
22
|
-
return union.create(create(value), undef);
|
|
23
|
-
},
|
|
24
|
-
// @ts-ignore we know that this can be infinite
|
|
25
|
-
list(value, ...values) {
|
|
26
|
-
return union.create(create(value), ...values.map(create), undef);
|
|
27
|
-
}
|
|
28
|
-
})
|
|
29
|
-
});
|
|
30
|
-
//# sourceMappingURL=Number.js.map
|
package/esm/types/Number.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Number.js","sourceRoot":"","sources":["../../ts/types/Number.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,EAAa,MAAM,aAAa,CAAA;AAC9C,OAAO,EAAS,KAAK,EAAE,MAAM,SAAS,CAAA;AAiBtC;;GAEG;AACH,SAAS,MAAM,CAAuB,KAAY;IAChD,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,KAAK,EAAE,CAAA;AAClC,CAAC;AAED,MAAM,GAAG,GAAG,MAAM,CAAC,SAA8B,CAAC,CAAA;AAElD,MAAM,CAAC,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,GAAG,EAAE;IACvC,GAAG;IACH,MAAM;IACN,+CAA+C;IAC/C,IAAI,CAAgD,KAAY,EAAE,GAAG,MAAc;QAKjF,OAAO,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,GAAG,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,CAAQ,CAAA;IAClE,CAAC;IACD,QAAQ,EAAE,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE;QAChD;;WAEG;QACH,MAAM,CAAuB,KAAY;YACvC,OAAO,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,KAAK,CAAC,CAAA;QAC3C,CAAC;QACD,+CAA+C;QAC/C,IAAI,CAAgD,KAAY,EAAE,GAAG,MAAc;YAIjF,OAAO,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,GAAG,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,KAAK,CAAQ,CAAA;QACzE,CAAC;KACF,CAAC;CACH,CAAC,CAAA"}
|
package/esm/types/Object.js
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { reduceByKey } from '../object';
|
|
2
|
-
import { number } from './Number';
|
|
3
|
-
import { string as str } from './String';
|
|
4
|
-
import { symbol as sym } from './Symbol';
|
|
5
|
-
import { undef } from './Undefined';
|
|
6
|
-
import { union } from './Union';
|
|
7
|
-
/**
|
|
8
|
-
* create specific object type.
|
|
9
|
-
*/
|
|
10
|
-
function create(props) {
|
|
11
|
-
return { type: 'object', value: props };
|
|
12
|
-
}
|
|
13
|
-
const any = create(undefined);
|
|
14
|
-
export function map(callback, subject) {
|
|
15
|
-
return reduceByKey(subject, (p, k) => (p[k] = callback(subject[k], k, p), p), {});
|
|
16
|
-
}
|
|
17
|
-
export const object = Object.assign(any, {
|
|
18
|
-
any,
|
|
19
|
-
create,
|
|
20
|
-
map,
|
|
21
|
-
optional: Object.assign(union.create(any, undef), {
|
|
22
|
-
/**
|
|
23
|
-
* Creates an optional object type.
|
|
24
|
-
*/
|
|
25
|
-
create(props) {
|
|
26
|
-
return union.create(create(props), undef);
|
|
27
|
-
}
|
|
28
|
-
})
|
|
29
|
-
});
|
|
30
|
-
export const keys = union.create(str, number, sym);
|
|
31
|
-
//# sourceMappingURL=Object.js.map
|
package/esm/types/Object.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Object.js","sourceRoot":"","sources":["../../ts/types/Object.ts"],"names":[],"mappings":"AAAA,OAAO,EAAY,WAAW,EAAE,MAAM,WAAW,CAAA;AAEjD,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAA;AACjC,OAAO,EAAE,MAAM,IAAI,GAAG,EAAE,MAAM,UAAU,CAAA;AACxC,OAAO,EAAE,MAAM,IAAI,GAAG,EAAE,MAAM,UAAU,CAAA;AAExC,OAAO,EAAE,KAAK,EAAa,MAAM,aAAa,CAAA;AAC9C,OAAO,EAAE,KAAK,EAAS,MAAM,SAAS,CAAA;AAgBtC;;GAEG;AACH,SAAS,MAAM,CAAwC,KAAY;IACjE,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,KAAK,EAAE,KAAK,EAAE,CAAA;AACzC,CAAC;AAED,MAAM,GAAG,GAAG,MAAM,CAAC,SAAgB,CAAC,CAAA;AAEpC,MAAM,UAAU,GAAG,CAEjB,QAAuE,EAAE,OAAU;IACnF,OAAO,WAAW,CAAC,OAAO,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,EAAsB,CAAC,CAAA;AACvG,CAAC;AAED,MAAM,CAAC,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,GAAG,EAAE;IACvC,GAAG;IACH,MAAM;IACN,GAAG;IACH,QAAQ,EAAE,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE;QAChD;;WAEG;QACH,MAAM,CAAwC,KAAY;YACxD,OAAO,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,KAAK,CAAC,CAAA;QAC3C,CAAC;KACF,CAAC;CACH,CAAC,CAAA;AAEF,MAAM,CAAC,MAAM,IAAI,GAAG,KAAK,CAAC,MAAM,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,CAAC,CAAA"}
|
package/esm/types/Record.js
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { undef } from './Undefined';
|
|
2
|
-
import { union } from './Union';
|
|
3
|
-
function create(value) {
|
|
4
|
-
return { type: 'record', value };
|
|
5
|
-
}
|
|
6
|
-
export const record = {
|
|
7
|
-
create,
|
|
8
|
-
optional: {
|
|
9
|
-
create(value) {
|
|
10
|
-
return union.create(create(value), undef);
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
};
|
|
14
|
-
//# sourceMappingURL=Record.js.map
|
package/esm/types/Record.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Record.js","sourceRoot":"","sources":["../../ts/types/Record.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,EAAa,MAAM,aAAa,CAAA;AAC9C,OAAO,EAAE,KAAK,EAAS,MAAM,SAAS,CAAA;AAUtC,SAAS,MAAM,CAAwB,KAAY;IACjD,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,KAAK,EAAE,CAAA;AAClC,CAAC;AAED,MAAM,CAAC,MAAM,MAAM,GAAG;IACpB,MAAM;IACN,QAAQ,EAAE;QACR,MAAM,CAAwB,KAAY;YACxC,OAAO,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,KAAK,CAAQ,CAAA;QAClD,CAAC;KACF;CACF,CAAA"}
|
package/esm/types/String.js
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { undef } from './Undefined';
|
|
2
|
-
import { union } from './Union';
|
|
3
|
-
/**
|
|
4
|
-
* Creates a constant string type.
|
|
5
|
-
*/
|
|
6
|
-
function create(value) {
|
|
7
|
-
// Cannot name this function as `const` because it is a reserved keyword.
|
|
8
|
-
return { type: 'string', value: value };
|
|
9
|
-
}
|
|
10
|
-
const any = create(undefined);
|
|
11
|
-
export const string = Object.assign(any, {
|
|
12
|
-
any,
|
|
13
|
-
create,
|
|
14
|
-
// @ts-ignore we know that this can be infinite
|
|
15
|
-
list(value, ...values) {
|
|
16
|
-
return union.create(create(value), ...values.map(create));
|
|
17
|
-
},
|
|
18
|
-
optional: Object.assign(union.create(any, undef), {
|
|
19
|
-
/**
|
|
20
|
-
* Creates an optional constant string type.
|
|
21
|
-
*/
|
|
22
|
-
create(value) {
|
|
23
|
-
return union.create(create(value), undef);
|
|
24
|
-
},
|
|
25
|
-
// @ts-ignore we know that this can be infinite
|
|
26
|
-
list(value, ...values) {
|
|
27
|
-
return union.create(create(value), ...values.map(create), undef);
|
|
28
|
-
}
|
|
29
|
-
})
|
|
30
|
-
});
|
|
31
|
-
//# sourceMappingURL=String.js.map
|
package/esm/types/String.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"String.js","sourceRoot":"","sources":["../../ts/types/String.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,EAAa,MAAM,aAAa,CAAA;AAC9C,OAAO,EAAS,KAAK,EAAE,MAAM,SAAS,CAAA;AAiBtC;;EAEE;AACF,SAAS,MAAM,CAAuB,KAAY;IAChD,yEAAyE;IACzE,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,KAAK,EAAE,KAAK,EAAE,CAAA;AACzC,CAAC;AACD,MAAM,GAAG,GAAG,MAAM,CAAC,SAA8B,CAAC,CAAA;AAElD,MAAM,CAAC,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,GAAG,EAAE;IACvC,GAAG;IACH,MAAM;IACN,+CAA+C;IAC/C,IAAI,CAAgD,KAAY,EAAE,GAAG,MAAc;QAKjF,OAAO,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,GAAG,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,CAAQ,CAAA;IAClE,CAAC;IACD,QAAQ,EAAE,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE;QAChD;;WAEG;QACH,MAAM,CAAuB,KAAY;YACvC,OAAO,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,KAAK,CAAC,CAAA;QAC3C,CAAC;QACD,+CAA+C;QAC/C,IAAI,CAAgD,KAAY,EAAE,GAAG,MAAc;YAIjF,OAAO,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,GAAG,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,KAAK,CAAQ,CAAA;QACzE,CAAC;KACF,CAAC;CACH,CAAC,CAAA"}
|
package/esm/types/Symbol.js
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { undef } from './Undefined';
|
|
2
|
-
import { union } from './Union';
|
|
3
|
-
function create(value) {
|
|
4
|
-
return { type: 'symbol', value };
|
|
5
|
-
}
|
|
6
|
-
const any = create(undefined);
|
|
7
|
-
export const symbol = Object.assign(any, {
|
|
8
|
-
optional: union.create(any, undef)
|
|
9
|
-
});
|
|
10
|
-
//# sourceMappingURL=Symbol.js.map
|
package/esm/types/Symbol.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Symbol.js","sourceRoot":"","sources":["../../ts/types/Symbol.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAA;AACnC,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;AAQ/B,SAAS,MAAM,CAAuB,KAAY;IAChD,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,KAAK,EAAE,CAAA;AAClC,CAAC;AAED,MAAM,GAAG,GAAG,MAAM,CAAC,SAA8B,CAAC,CAAA;AAElD,MAAM,CAAC,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,GAAG,EAAE;IACvC,QAAQ,EAAE,KAAK,CAAC,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC;CACnC,CAAC,CAAA"}
|
package/esm/types/Tuple.js
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { undef } from './Undefined';
|
|
2
|
-
import { union } from './Union';
|
|
3
|
-
/**
|
|
4
|
-
* Creates a tuple type.
|
|
5
|
-
*/
|
|
6
|
-
function create(value, ...values) {
|
|
7
|
-
return {
|
|
8
|
-
type: 'tuple',
|
|
9
|
-
value: [value, ...values]
|
|
10
|
-
};
|
|
11
|
-
}
|
|
12
|
-
export const tuple = {
|
|
13
|
-
create,
|
|
14
|
-
optional: {
|
|
15
|
-
/**
|
|
16
|
-
* Creates an optional tuple type.
|
|
17
|
-
*/
|
|
18
|
-
create(value, ...values) {
|
|
19
|
-
return union.create(create(value, ...values), undef);
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
};
|
|
23
|
-
//# sourceMappingURL=Tuple.js.map
|
package/esm/types/Tuple.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Tuple.js","sourceRoot":"","sources":["../../ts/types/Tuple.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,EAAa,MAAM,aAAa,CAAA;AAC9C,OAAO,EAAE,KAAK,EAAS,MAAM,SAAS,CAAA;AAqBtC;;GAEG;AACH,SAAS,MAAM,CACb,KAAY,EACZ,GAAG,MAAc;IAEjB,OAAO;QACL,IAAI,EAAE,OAAO;QACb,KAAK,EAAE,CAAC,KAAK,EAAE,GAAG,MAAM,CAAC;KAC1B,CAAA;AACH,CAAC;AACD,MAAM,CAAC,MAAM,KAAK,GAAG;IACnB,MAAM;IACN,QAAQ,EAAE;QACR;;WAEG;QACH,MAAM,CACJ,KAAY,EACZ,GAAG,MAAc;YAEjB,OAAO,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,EAAE,GAAG,MAAM,CAAC,EAAE,KAAK,CAAC,CAAA;QACtD,CAAC;KACF;CACF,CAAA"}
|
package/esm/types/Undefined.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Undefined.js","sourceRoot":"","sources":["../../ts/types/Undefined.ts"],"names":[],"mappings":"AAOA,MAAM,CAAC,MAAM,KAAK,GAAc,EAAE,IAAI,EAAE,WAAW,EAAE,KAAK,EAAE,SAAS,EAAE,CAAA"}
|
package/esm/types/Union.js
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { undef } from './Undefined';
|
|
2
|
-
/**
|
|
3
|
-
* Create union type.
|
|
4
|
-
*/
|
|
5
|
-
function create(value, ...values) {
|
|
6
|
-
values.unshift(value);
|
|
7
|
-
if (values.length === 1)
|
|
8
|
-
return values[0];
|
|
9
|
-
const v = values.reduce((p, v) => {
|
|
10
|
-
if (v.type === 'union') {
|
|
11
|
-
p.push(...v.value);
|
|
12
|
-
}
|
|
13
|
-
else {
|
|
14
|
-
p.push(v);
|
|
15
|
-
}
|
|
16
|
-
return p;
|
|
17
|
-
}, []);
|
|
18
|
-
return { type: 'union', value: v };
|
|
19
|
-
}
|
|
20
|
-
export const union = {
|
|
21
|
-
create,
|
|
22
|
-
optional: {
|
|
23
|
-
/**
|
|
24
|
-
* Creates an optional unional type.
|
|
25
|
-
*/
|
|
26
|
-
create(value, ...values) {
|
|
27
|
-
values.push(undef);
|
|
28
|
-
return create(value, ...values);
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
};
|
|
32
|
-
//# sourceMappingURL=Union.js.map
|
package/esm/types/Union.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Union.js","sourceRoot":"","sources":["../../ts/types/Union.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAA;AAWnC;;GAEG;AACH,SAAS,MAAM,CAEb,KAAY,EAAE,GAAG,MAAc;IAE/B,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAA;IACrB,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,MAAM,CAAC,CAAC,CAAQ,CAAA;IAChD,MAAM,CAAC,GAAG,MAAM,CAAC,MAAM,CAAY,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE;QAC1C,IAAI,CAAC,CAAC,IAAI,KAAK,OAAO,EAAE;YACtB,CAAC,CAAC,IAAI,CAAC,GAAI,CAAS,CAAC,KAAK,CAAC,CAAA;SAC5B;aACI;YACH,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;SACV;QACD,OAAO,CAAC,CAAA;IACV,CAAC,EAAE,EAAE,CAAC,CAAA;IACN,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC,EAAS,CAAA;AAC3C,CAAC;AAED,MAAM,CAAC,MAAM,KAAK,GAAG;IACnB,MAAM;IACN,QAAQ,EAAE;QACR;;WAEG;QACH,MAAM,CAAkD,KAAY,EAAE,GAAG,MAAc;YACrF,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;YAClB,OAAO,MAAM,CAAC,KAAK,EAAE,GAAG,MAAM,CAAC,CAAA;QACjC,CAAC;KACF;CACF,CAAA"}
|
package/esm/types/Unknown.js
DELETED
package/esm/types/Unknown.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Unknown.js","sourceRoot":"","sources":["../../ts/types/Unknown.ts"],"names":[],"mappings":"AAQA,MAAM,CAAC,MAAM,OAAO,GAAY,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,SAAS,EAAE,CAAA"}
|
package/esm/types/analyze.js
DELETED
|
@@ -1,142 +0,0 @@
|
|
|
1
|
-
import { reduceByKey } from '../object';
|
|
2
|
-
import { number } from './Number';
|
|
3
|
-
import { object } from './Object';
|
|
4
|
-
import { string } from './String';
|
|
5
|
-
export function analyze(options, type, actual) {
|
|
6
|
-
return {
|
|
7
|
-
options,
|
|
8
|
-
analysis: analyzeInternal(options, type, actual),
|
|
9
|
-
actual
|
|
10
|
-
};
|
|
11
|
-
}
|
|
12
|
-
export function analyzeInternal(options, type, actual) {
|
|
13
|
-
const t = type['type'];
|
|
14
|
-
switch (t) {
|
|
15
|
-
case 'unknown':
|
|
16
|
-
case 'any':
|
|
17
|
-
return ok(type);
|
|
18
|
-
case 'undefined':
|
|
19
|
-
case 'symbol':
|
|
20
|
-
return typeof actual === t ? ok(type) : fail(t);
|
|
21
|
-
case 'null':
|
|
22
|
-
return actual === null ? ok(type) : fail(t);
|
|
23
|
-
case 'boolean': return analyzeBoolean(type, actual);
|
|
24
|
-
case 'number': return analyzeType(number, type, actual);
|
|
25
|
-
case 'string': return analyzeType(string, type, actual);
|
|
26
|
-
// case 'bigint': return analyzeType(bigint, type as BigInt, actual)
|
|
27
|
-
case 'object': return analyzeObject(options, type, actual);
|
|
28
|
-
case 'record': return analyzeRecord(options, type, actual);
|
|
29
|
-
case 'array': return analyzeArray(options, type, actual);
|
|
30
|
-
case 'tuple': return analyzeTuple(options, type, actual);
|
|
31
|
-
case 'union': return analyzeUnion(options, type, actual);
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
function analyzeBoolean(type, actual) {
|
|
35
|
-
const value = type['value'];
|
|
36
|
-
if (value === undefined) {
|
|
37
|
-
return typeof actual === 'boolean' ? ok(type) : fail('boolean', value);
|
|
38
|
-
}
|
|
39
|
-
else {
|
|
40
|
-
return value === actual ? ok(type) : fail('boolean', value);
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
function analyzeType(baseType, // | BigInt,
|
|
44
|
-
type, actual) {
|
|
45
|
-
const value = type['value'];
|
|
46
|
-
return typeof actual === baseType['type'] && (type === baseType || actual === value)
|
|
47
|
-
? ok(type)
|
|
48
|
-
: fail(type['type'], type['value']);
|
|
49
|
-
}
|
|
50
|
-
function analyzeUnion(options, type, actual) {
|
|
51
|
-
const subTypes = type['value'];
|
|
52
|
-
const r = subTypes.map(t => analyzeInternal(options, t, actual));
|
|
53
|
-
return r.some(r => !r.fail) ? ok(type) : fail('union', r);
|
|
54
|
-
}
|
|
55
|
-
function analyzeArray(options, type, actual) {
|
|
56
|
-
const subType = type['value'];
|
|
57
|
-
if (!Array.isArray(actual))
|
|
58
|
-
return fail('array', subType ? ok(subType) : undefined);
|
|
59
|
-
if (subType === undefined)
|
|
60
|
-
return ok(type);
|
|
61
|
-
const r = actual.reduce((p, a, i) => {
|
|
62
|
-
const r = analyzeInternal(options, subType, a);
|
|
63
|
-
if (r.fail) {
|
|
64
|
-
p.value = r.value;
|
|
65
|
-
p.keys.push(i);
|
|
66
|
-
p.actual.push(a);
|
|
67
|
-
}
|
|
68
|
-
return p;
|
|
69
|
-
}, { keys: [], actual: [] });
|
|
70
|
-
return r.keys.length === 0 ?
|
|
71
|
-
ok(type) :
|
|
72
|
-
fail('array', { ...fail(subType['type'], r.value) });
|
|
73
|
-
}
|
|
74
|
-
function analyzeTuple(options, type, actual) {
|
|
75
|
-
const value = type['value'];
|
|
76
|
-
if (!Array.isArray(actual))
|
|
77
|
-
return fail('tuple', value.map(ok));
|
|
78
|
-
const results = value.map((v, i) => analyzeInternal(options, v, actual[i]));
|
|
79
|
-
if (options.strict && results.length < actual.length) {
|
|
80
|
-
return fail('tuple', results);
|
|
81
|
-
}
|
|
82
|
-
return results.every(r => !r.fail) ? ok(type) : fail('tuple', results);
|
|
83
|
-
}
|
|
84
|
-
function analyzeObject(options, type, actual) {
|
|
85
|
-
const typeMap = type['value'];
|
|
86
|
-
if (!isOnlyObject(actual))
|
|
87
|
-
return fail('object', typeMap ? object.map(v => ok(v), typeMap) : undefined);
|
|
88
|
-
if (type === object)
|
|
89
|
-
return ok(type);
|
|
90
|
-
const typeKeys = Object.keys(typeMap);
|
|
91
|
-
const s = { ...actual };
|
|
92
|
-
const results = typeKeys.reduce((p, k) => {
|
|
93
|
-
const r = p.value[k] = analyzeInternal(options, typeMap[k], actual[k]);
|
|
94
|
-
p.fail || (p.fail = !!r.fail);
|
|
95
|
-
s[k] = undefined;
|
|
96
|
-
return p;
|
|
97
|
-
}, { fail: false, value: {} });
|
|
98
|
-
const skeys = Object.keys(s);
|
|
99
|
-
if (options.strict && skeys.length > typeKeys.length) {
|
|
100
|
-
return fail('object', results.value);
|
|
101
|
-
}
|
|
102
|
-
return !results.fail ? ok(type) : fail('object', results.value);
|
|
103
|
-
}
|
|
104
|
-
function analyzeRecord(options, type, actual) {
|
|
105
|
-
const subType = type['value'];
|
|
106
|
-
if (!isOnlyObject(actual))
|
|
107
|
-
return fail('record', ok(subType));
|
|
108
|
-
const r = reduceByKey(actual, (p, k) => {
|
|
109
|
-
const r = analyzeInternal(options, subType, actual[k]);
|
|
110
|
-
if (r.fail) {
|
|
111
|
-
p.value = r.value;
|
|
112
|
-
p.keys.push(k);
|
|
113
|
-
p.actual.push(actual[k]);
|
|
114
|
-
}
|
|
115
|
-
return p;
|
|
116
|
-
}, { keys: [], actual: [], value: undefined });
|
|
117
|
-
return r.keys.length === 0 ?
|
|
118
|
-
ok(type) :
|
|
119
|
-
fail('record', { ...fail(subType['type'], r.value) });
|
|
120
|
-
}
|
|
121
|
-
function ok(t) {
|
|
122
|
-
const type = t['type'];
|
|
123
|
-
const value = t['value'];
|
|
124
|
-
if (value === undefined)
|
|
125
|
-
return { type, value };
|
|
126
|
-
if (typeof value !== 'object' || value === null)
|
|
127
|
-
return { type, value };
|
|
128
|
-
if (Array.isArray(value))
|
|
129
|
-
return { type, value: value.map(ok) };
|
|
130
|
-
if (value['type'])
|
|
131
|
-
return { type, value: ok(value) };
|
|
132
|
-
return {
|
|
133
|
-
type, value: reduceByKey(value, (p, k) => (p[k] = ok(value[k]), p), {})
|
|
134
|
-
};
|
|
135
|
-
}
|
|
136
|
-
function fail(type, value) {
|
|
137
|
-
return value === undefined ? { type, fail: true } : { type, value, fail: true };
|
|
138
|
-
}
|
|
139
|
-
function isOnlyObject(actual) {
|
|
140
|
-
return typeof actual === 'object' && actual !== null && !Array.isArray(actual);
|
|
141
|
-
}
|
|
142
|
-
//# sourceMappingURL=analyze.js.map
|
package/esm/types/analyze.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"analyze.js","sourceRoot":"","sources":["../../ts/types/analyze.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAA;AAIvC,OAAO,EAAE,MAAM,EAAU,MAAM,UAAU,CAAA;AACzC,OAAO,EAAE,MAAM,EAAc,MAAM,UAAU,CAAA;AAE7C,OAAO,EAAE,MAAM,EAAU,MAAM,UAAU,CAAA;AAazC,MAAM,UAAU,OAAO,CAAC,OAAwB,EAAE,IAAa,EAAE,MAAe;IAC9E,OAAO;QACL,OAAO;QACP,QAAQ,EAAE,eAAe,CAAC,OAAO,EAAE,IAAI,EAAE,MAAM,CAAC;QAChD,MAAM;KACP,CAAA;AACH,CAAC;AACD,MAAM,UAAU,eAAe,CAAC,OAAwB,EAAE,IAAa,EAAE,MAAe;IACtF,MAAM,CAAC,GAAG,IAAI,CAAC,MAAM,CAAC,CAAA;IACtB,QAAQ,CAAC,EAAE;QACT,KAAK,SAAS,CAAC;QACf,KAAK,KAAK;YACR,OAAO,EAAE,CAAC,IAAI,CAAC,C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CAAC,CAAC,EAAE,CAAC,CAAC,EAClC,EAAyB,CAAC;KACtB,CAAA;AACV,CAAC;AAED,SAAS,IAAI,CAAC,IAA8B,EAAE,KAAiC;IAC7E,OAAO,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE,CAAA;AACjF,CAAC;AAED,SAAS,YAAY,CAAC,MAAe;IACnC,OAAO,OAAO,MAAM,KAAK,QAAQ,IAAI,MAAM,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,CAAA;AAChF,CAAC"}
|
package/esm/types/check.js
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { analyze } from './analyze';
|
|
2
|
-
import { getPlainAnalysisReport } from './getPlainAnalysisReport';
|
|
3
|
-
/**
|
|
4
|
-
* Checks if the specified `subject` against the `type`.
|
|
5
|
-
* @return type guard (boolean). If the subject does not check to the type,
|
|
6
|
-
* the detail report is available in `check.result`,
|
|
7
|
-
* and you can get a string report using `check.getReport()`
|
|
8
|
-
*/
|
|
9
|
-
export function check(options, type, subject) {
|
|
10
|
-
const result = check.result = analyze(options, type, subject);
|
|
11
|
-
return !result.analysis.fail;
|
|
12
|
-
}
|
|
13
|
-
/**
|
|
14
|
-
* Analysis report.
|
|
15
|
-
*/
|
|
16
|
-
check.result = { analysis: {}, actual: undefined };
|
|
17
|
-
/**
|
|
18
|
-
* Gets a simple report of the analysis.
|
|
19
|
-
*/
|
|
20
|
-
check.getReport = () => getPlainAnalysisReport(check.result);
|
|
21
|
-
//# sourceMappingURL=check.js.map
|
package/esm/types/check.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"check.js","sourceRoot":"","sources":["../../ts/types/check.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAEnC,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAA;AAEjE;;;;;GAKG;AACH,MAAM,UAAU,KAAK,CAAoB,OAAwB,EAAE,IAAO,EAAE,OAAgB;IAC1F,MAAM,MAAM,GAAG,KAAK,CAAC,MAAM,GAAG,OAAO,CAAC,OAAO,EAAE,IAAI,EAAE,OAAO,CAAC,CAAA;IAC7D,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAA;AAC9B,CAAC;AAED;;GAEG;AACH,KAAK,CAAC,MAAM,GAAG,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,SAAS,EAAoB,CAAA;AAEpE;;GAEG;AACH,KAAK,CAAC,SAAS,GAAG,GAAG,EAAE,CAAC,sBAAsB,CAAC,KAAK,CAAC,MAAM,CAAC,CAAA"}
|
package/esm/types/conform.js
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { analyze } from './analyze';
|
|
2
|
-
import { getPlainAnalysisReport } from './getPlainAnalysisReport';
|
|
3
|
-
/**
|
|
4
|
-
* Checks if the specified `subject` conforms to the `type`.
|
|
5
|
-
* `conform()` is the shortcut of `check({ strict: true }, ...)`.
|
|
6
|
-
* @return type guard (boolean). If the subject does not conform to the type,
|
|
7
|
-
* the detail report is available in `conform.result`,
|
|
8
|
-
* and you can get a string report using `conform.getReport()`
|
|
9
|
-
*/
|
|
10
|
-
export function conform(type, subject) {
|
|
11
|
-
const result = conform.result = analyze({ strict: true }, type, subject);
|
|
12
|
-
return !result.analysis.fail;
|
|
13
|
-
}
|
|
14
|
-
/**
|
|
15
|
-
* Analysis report.
|
|
16
|
-
*/
|
|
17
|
-
conform.result = { analysis: {}, actual: undefined };
|
|
18
|
-
/**
|
|
19
|
-
* Gets a simple report of the analysis.
|
|
20
|
-
*/
|
|
21
|
-
conform.getReport = () => getPlainAnalysisReport(conform.result);
|
|
22
|
-
//# sourceMappingURL=conform.js.map
|