arktype 2.0.0-rc.2 → 2.0.0-rc.21
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/out/attributes.d.ts +274 -0
- package/out/attributes.js +2 -0
- package/out/config.d.ts +1 -1
- package/out/generic.d.ts +45 -48
- package/out/generic.js +6 -8
- package/out/index.d.ts +4 -4
- package/out/index.js +2 -2
- package/out/keywords/builtins.js +2 -2
- package/out/keywords/constructors/Array.d.ts +2 -2
- package/out/keywords/constructors/Array.js +7 -7
- package/out/keywords/constructors/Date.d.ts +37 -0
- package/out/keywords/constructors/FormData.d.ts +2 -2
- package/out/keywords/constructors/FormData.js +8 -8
- package/out/keywords/constructors/TypedArray.js +2 -2
- package/out/keywords/constructors/constructors.d.ts +0 -1
- package/out/keywords/constructors/constructors.js +2 -2
- package/out/keywords/keywords.d.ts +64 -0
- package/out/keywords/{ark.js → keywords.js} +14 -9
- package/out/keywords/number/epoch.d.ts +1 -1
- package/out/keywords/number/epoch.js +2 -2
- package/out/keywords/number/integer.js +2 -2
- package/out/keywords/number/number.d.ts +44 -14
- package/out/keywords/number/number.js +17 -5
- package/out/keywords/string/alpha.d.ts +2 -2
- package/out/keywords/string/alphanumeric.d.ts +2 -2
- package/out/keywords/string/base64.d.ts +21 -0
- package/out/keywords/string/base64.js +6 -0
- package/out/keywords/string/capitalize.d.ts +3 -3
- package/out/keywords/string/capitalize.js +4 -4
- package/out/keywords/string/creditCard.d.ts +2 -2
- package/out/keywords/string/creditCard.js +2 -2
- package/out/keywords/string/date.d.ts +7 -11
- package/out/keywords/string/date.js +16 -16
- package/out/keywords/string/digits.d.ts +2 -2
- package/out/keywords/string/email.d.ts +2 -2
- package/out/keywords/string/integer.d.ts +3 -3
- package/out/keywords/string/integer.js +7 -7
- package/out/keywords/string/ip.d.ts +5 -5
- package/out/keywords/string/ip.js +5 -5
- package/out/keywords/string/json.d.ts +4 -3
- package/out/keywords/string/json.js +39 -30
- package/out/keywords/string/lower.d.ts +3 -3
- package/out/keywords/string/lower.js +4 -4
- package/out/keywords/string/normalize.d.ts +27 -31
- package/out/keywords/string/normalize.js +14 -14
- package/out/keywords/string/numeric.d.ts +3 -3
- package/out/keywords/string/numeric.js +7 -7
- package/out/keywords/string/semver.d.ts +2 -2
- package/out/keywords/string/string.d.ts +74 -51
- package/out/keywords/string/string.js +5 -3
- package/out/keywords/string/trim.d.ts +3 -3
- package/out/keywords/string/trim.js +4 -4
- package/out/keywords/string/upper.d.ts +3 -3
- package/out/keywords/string/upper.js +4 -4
- package/out/keywords/string/url.d.ts +3 -3
- package/out/keywords/string/url.js +8 -8
- package/out/keywords/string/uuid.d.ts +20 -20
- package/out/keywords/string/uuid.js +3 -3
- package/out/keywords/ts.d.ts +38 -1
- package/out/keywords/ts.js +20 -4
- package/out/keywords/utils.d.ts +1 -1
- package/out/keywords/utils.js +1 -1
- package/out/{subtypes → methods}/array.d.ts +6 -6
- package/out/methods/base.d.ts +183 -0
- package/out/{subtypes → methods}/date.d.ts +5 -5
- package/out/methods/instantiate.d.ts +17 -0
- package/out/methods/morph.d.ts +12 -0
- package/out/methods/number.d.ts +12 -0
- package/out/methods/object.d.ts +106 -0
- package/out/methods/string.d.ts +13 -0
- package/out/module.d.ts +2 -2
- package/out/parser/{semantic → ast}/bounds.d.ts +3 -3
- package/out/parser/ast/default.d.ts +8 -0
- package/out/parser/ast/infer.d.ts +39 -0
- package/out/parser/{semantic → ast}/utils.d.ts +1 -1
- package/out/parser/{semantic → ast}/validate.d.ts +10 -10
- package/out/parser/ast/validate.js +1 -0
- package/out/parser/definition.d.ts +8 -9
- package/out/parser/objectLiteral.d.ts +11 -37
- package/out/parser/objectLiteral.js +6 -24
- package/out/parser/{string/reduce → reduce}/dynamic.d.ts +5 -8
- package/out/parser/{string/reduce → reduce}/dynamic.js +5 -6
- package/out/parser/{string/reduce → reduce}/shared.d.ts +1 -1
- package/out/parser/{string/reduce → reduce}/static.d.ts +1 -1
- package/out/parser/{string/shift → shift}/operand/date.d.ts +3 -1
- package/out/parser/{string/shift → shift}/operand/enclosed.d.ts +4 -3
- package/out/parser/{string/shift → shift}/operand/enclosed.js +7 -3
- package/out/parser/{string/shift → shift}/operand/unenclosed.d.ts +8 -4
- package/out/parser/{string/shift → shift}/operand/unenclosed.js +12 -7
- package/out/parser/{string/shift → shift}/operator/bounds.d.ts +3 -3
- package/out/parser/shift/operator/brand.d.ts +6 -0
- package/out/parser/shift/operator/brand.js +5 -0
- package/out/parser/{string/shift → shift}/operator/default.d.ts +3 -6
- package/out/parser/{string/shift → shift}/operator/default.js +4 -6
- package/out/parser/{string/shift → shift}/operator/operator.d.ts +2 -1
- package/out/parser/{string/shift → shift}/operator/operator.js +4 -2
- package/out/parser/{string/shift → shift}/scanner.d.ts +6 -3
- package/out/parser/{string/shift → shift}/scanner.js +6 -3
- package/out/parser/{string/string.d.ts → string.d.ts} +6 -7
- package/out/parser/{string/string.js → string.js} +2 -0
- package/out/parser/tuple.d.ts +56 -44
- package/out/parser/tuple.js +36 -30
- package/out/scope.d.ts +38 -39
- package/out/scope.js +47 -36
- package/out/type.d.ts +45 -21
- package/out/type.js +14 -10
- package/package.json +3 -3
- package/out/intersect.d.ts +0 -28
- package/out/keys.d.ts +0 -16
- package/out/keywords/ark.d.ts +0 -39
- package/out/keywords/ast.d.ts +0 -193
- package/out/keywords/ast.js +0 -2
- package/out/parser/semantic/default.d.ts +0 -9
- package/out/parser/semantic/default.js +0 -1
- package/out/parser/semantic/infer.d.ts +0 -39
- package/out/parser/semantic/validate.js +0 -1
- package/out/subtypes/base.d.ts +0 -85
- package/out/subtypes/instantiate.d.ts +0 -16
- package/out/subtypes/morph.d.ts +0 -13
- package/out/subtypes/number.d.ts +0 -12
- package/out/subtypes/object.d.ts +0 -33
- package/out/subtypes/string.d.ts +0 -13
- package/out/subtypes/validator.d.ts +0 -11
- package/out/subtypes/validator.js +0 -1
- /package/out/{intersect.js → keywords/constructors/Date.js} +0 -0
- /package/out/{subtypes → methods}/array.js +0 -0
- /package/out/{subtypes → methods}/base.js +0 -0
- /package/out/{subtypes → methods}/date.js +0 -0
- /package/out/{subtypes → methods}/instantiate.js +0 -0
- /package/out/{subtypes → methods}/morph.js +0 -0
- /package/out/{subtypes → methods}/number.js +0 -0
- /package/out/{subtypes → methods}/object.js +0 -0
- /package/out/{subtypes → methods}/string.js +0 -0
- /package/out/parser/{semantic → ast}/bounds.js +0 -0
- /package/out/{keys.js → parser/ast/default.js} +0 -0
- /package/out/parser/{semantic → ast}/divisor.d.ts +0 -0
- /package/out/parser/{semantic → ast}/divisor.js +0 -0
- /package/out/parser/{semantic → ast}/infer.js +0 -0
- /package/out/parser/{semantic → ast}/keyof.d.ts +0 -0
- /package/out/parser/{semantic → ast}/keyof.js +0 -0
- /package/out/parser/{semantic → ast}/utils.js +0 -0
- /package/out/parser/{string/reduce → reduce}/shared.js +0 -0
- /package/out/parser/{string/reduce → reduce}/static.js +0 -0
- /package/out/parser/{string/shift → shift}/operand/date.js +0 -0
- /package/out/parser/{string/shift → shift}/operand/genericArgs.d.ts +0 -0
- /package/out/parser/{string/shift → shift}/operand/genericArgs.js +0 -0
- /package/out/parser/{string/shift → shift}/operand/operand.d.ts +0 -0
- /package/out/parser/{string/shift → shift}/operand/operand.js +0 -0
- /package/out/parser/{string/shift → shift}/operator/bounds.js +0 -0
- /package/out/parser/{string/shift → shift}/operator/divisor.d.ts +0 -0
- /package/out/parser/{string/shift → shift}/operator/divisor.js +0 -0
|
@@ -1,14 +1,15 @@
|
|
|
1
|
+
import type { Nominal, To, of } from "../../attributes.ts";
|
|
1
2
|
import type { Module, Submodule } from "../../module.ts";
|
|
2
|
-
import type { Branded, To, constrain } from "../ast.ts";
|
|
3
3
|
declare namespace string {
|
|
4
|
-
type json =
|
|
4
|
+
type json = of<string, Nominal<"json">>;
|
|
5
5
|
}
|
|
6
|
+
export declare const writeJsonSyntaxErrorProblem: (error: unknown) => string;
|
|
6
7
|
export declare const json: stringJson.module;
|
|
7
8
|
export declare namespace stringJson {
|
|
8
9
|
type module = Module<submodule>;
|
|
9
10
|
type submodule = Submodule<$>;
|
|
10
11
|
type $ = {
|
|
11
|
-
|
|
12
|
+
root: string.json;
|
|
12
13
|
parse: (In: string.json) => To<object>;
|
|
13
14
|
};
|
|
14
15
|
}
|
|
@@ -1,45 +1,54 @@
|
|
|
1
|
-
import { intrinsic,
|
|
2
|
-
import {
|
|
1
|
+
import { intrinsic, rootSchema } from "@ark/schema";
|
|
2
|
+
import { arkModule } from "../utils.js";
|
|
3
3
|
const jsonStringDescription = "a JSON string";
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
}
|
|
9
|
-
catch {
|
|
10
|
-
return false;
|
|
11
|
-
}
|
|
4
|
+
export const writeJsonSyntaxErrorProblem = (error) => {
|
|
5
|
+
if (!(error instanceof SyntaxError))
|
|
6
|
+
throw error;
|
|
7
|
+
return `must be ${jsonStringDescription} (${error})`;
|
|
12
8
|
};
|
|
13
|
-
const
|
|
9
|
+
const root = rootSchema({
|
|
14
10
|
domain: "string",
|
|
15
11
|
predicate: {
|
|
16
12
|
meta: jsonStringDescription,
|
|
17
|
-
predicate:
|
|
18
|
-
}
|
|
19
|
-
});
|
|
20
|
-
export const json = submodule({
|
|
21
|
-
$root,
|
|
22
|
-
parse: rootNode({
|
|
23
|
-
in: "string",
|
|
24
|
-
morphs: (s, ctx) => {
|
|
25
|
-
if (s.length === 0) {
|
|
26
|
-
return ctx.error({
|
|
27
|
-
code: "predicate",
|
|
28
|
-
expected: jsonStringDescription,
|
|
29
|
-
actual: "empty"
|
|
30
|
-
});
|
|
31
|
-
}
|
|
13
|
+
predicate: (s, ctx) => {
|
|
32
14
|
try {
|
|
33
|
-
|
|
15
|
+
JSON.parse(s);
|
|
16
|
+
return true;
|
|
34
17
|
}
|
|
35
18
|
catch (e) {
|
|
36
|
-
return ctx.
|
|
19
|
+
return ctx.reject({
|
|
37
20
|
code: "predicate",
|
|
38
21
|
expected: jsonStringDescription,
|
|
39
|
-
problem:
|
|
22
|
+
problem: writeJsonSyntaxErrorProblem(e)
|
|
40
23
|
});
|
|
41
24
|
}
|
|
42
|
-
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
const parseJson = (s, ctx) => {
|
|
29
|
+
if (s.length === 0) {
|
|
30
|
+
return ctx.error({
|
|
31
|
+
code: "predicate",
|
|
32
|
+
expected: jsonStringDescription,
|
|
33
|
+
actual: "empty"
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
try {
|
|
37
|
+
return JSON.parse(s);
|
|
38
|
+
}
|
|
39
|
+
catch (e) {
|
|
40
|
+
return ctx.error({
|
|
41
|
+
code: "predicate",
|
|
42
|
+
expected: jsonStringDescription,
|
|
43
|
+
problem: writeJsonSyntaxErrorProblem(e)
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
export const json = arkModule({
|
|
48
|
+
root,
|
|
49
|
+
parse: rootSchema({
|
|
50
|
+
in: "string",
|
|
51
|
+
morphs: parseJson,
|
|
43
52
|
declaredOut: intrinsic.json
|
|
44
53
|
})
|
|
45
54
|
});
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
+
import type { Nominal, of, To } from "../../attributes.ts";
|
|
1
2
|
import type { Module, Submodule } from "../../module.ts";
|
|
2
|
-
import type { Branded, constrain, To } from "../ast.ts";
|
|
3
3
|
declare namespace string {
|
|
4
|
-
type lowercase =
|
|
4
|
+
type lowercase = of<string, Nominal<"lowercase">>;
|
|
5
5
|
}
|
|
6
6
|
export declare const lower: lower.module;
|
|
7
7
|
export declare namespace lower {
|
|
8
8
|
type module = Module<submodule>;
|
|
9
9
|
type submodule = Submodule<$>;
|
|
10
10
|
type $ = {
|
|
11
|
-
|
|
11
|
+
root: (In: string) => To<string.lowercase>;
|
|
12
12
|
preformatted: string.lowercase;
|
|
13
13
|
};
|
|
14
14
|
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { rootSchema } from "@ark/schema";
|
|
2
|
+
import { arkModule } from "../utils.js";
|
|
3
3
|
import { regexStringNode } from "./utils.js";
|
|
4
4
|
const preformatted = regexStringNode(/^[a-z]*$/, "only lowercase letters");
|
|
5
|
-
export const lower =
|
|
6
|
-
|
|
5
|
+
export const lower = arkModule({
|
|
6
|
+
root: rootSchema({
|
|
7
7
|
in: "string",
|
|
8
8
|
morphs: (s) => s.toLowerCase(),
|
|
9
9
|
declaredOut: preformatted
|
|
@@ -1,90 +1,86 @@
|
|
|
1
|
+
import type { Nominal, of, To } from "../../attributes.ts";
|
|
1
2
|
import type { Module, Submodule } from "../../module.ts";
|
|
2
|
-
import type { type } from "../ark.ts";
|
|
3
|
-
import type { Branded, constrain, To } from "../ast.ts";
|
|
4
3
|
declare namespace string {
|
|
5
4
|
type normalized = normalized.NFC;
|
|
6
5
|
namespace normalized {
|
|
7
|
-
type NFC =
|
|
8
|
-
type NFD =
|
|
9
|
-
type NFKC =
|
|
10
|
-
type NFKD =
|
|
6
|
+
type NFC = of<string, Nominal<"normalized.NFC">>;
|
|
7
|
+
type NFD = of<string, Nominal<"normalized.NFD">>;
|
|
8
|
+
type NFKC = of<string, Nominal<"normalized.NFKC">>;
|
|
9
|
+
type NFKD = of<string, Nominal<"normalized.NFKD">>;
|
|
11
10
|
}
|
|
12
11
|
}
|
|
13
12
|
export declare const normalizedForms: readonly ["NFC", "NFD", "NFKC", "NFKD"];
|
|
14
13
|
export type NormalizedForm = (typeof normalizedForms)[number];
|
|
15
14
|
export declare const NFC: Module<{
|
|
16
|
-
|
|
17
|
-
preformatted:
|
|
15
|
+
root: unknown;
|
|
16
|
+
preformatted: unknown;
|
|
18
17
|
}>;
|
|
19
18
|
export declare const NFD: Module<{
|
|
20
|
-
|
|
21
|
-
preformatted:
|
|
19
|
+
root: unknown;
|
|
20
|
+
preformatted: unknown;
|
|
22
21
|
}>;
|
|
23
22
|
export declare const NFKC: Module<{
|
|
24
|
-
|
|
25
|
-
preformatted:
|
|
23
|
+
root: unknown;
|
|
24
|
+
preformatted: unknown;
|
|
26
25
|
}>;
|
|
27
26
|
export declare const NFKD: Module<{
|
|
28
|
-
|
|
29
|
-
preformatted:
|
|
27
|
+
root: unknown;
|
|
28
|
+
preformatted: unknown;
|
|
30
29
|
}>;
|
|
31
30
|
export declare const normalize: Module<{
|
|
32
|
-
|
|
31
|
+
root: unknown;
|
|
33
32
|
NFC: Submodule<{
|
|
34
|
-
|
|
35
|
-
preformatted:
|
|
33
|
+
root: unknown;
|
|
34
|
+
preformatted: unknown;
|
|
36
35
|
}>;
|
|
37
36
|
NFD: Submodule<{
|
|
38
|
-
|
|
39
|
-
preformatted:
|
|
37
|
+
root: unknown;
|
|
38
|
+
preformatted: unknown;
|
|
40
39
|
}>;
|
|
41
40
|
NFKC: Submodule<{
|
|
42
|
-
|
|
43
|
-
preformatted:
|
|
41
|
+
root: unknown;
|
|
42
|
+
preformatted: unknown;
|
|
44
43
|
}>;
|
|
45
44
|
NFKD: Submodule<{
|
|
46
|
-
|
|
47
|
-
preformatted:
|
|
45
|
+
root: unknown;
|
|
46
|
+
preformatted: unknown;
|
|
48
47
|
}>;
|
|
49
48
|
}>;
|
|
50
49
|
export declare namespace normalize {
|
|
51
50
|
type module = Module<submodule>;
|
|
52
51
|
type submodule = Submodule<$>;
|
|
53
52
|
type $ = {
|
|
54
|
-
|
|
53
|
+
root: (In: string) => To<string.normalized.NFC>;
|
|
55
54
|
NFC: NFC.submodule;
|
|
56
55
|
NFD: NFD.submodule;
|
|
57
56
|
NFKC: NFKC.submodule;
|
|
58
57
|
NFKD: NFKD.submodule;
|
|
59
58
|
};
|
|
60
|
-
type shallowResolutions = {
|
|
61
|
-
[k in keyof $ as `string.normalize.${k}`]: $[k] extends type.cast<infer t> ? t : $[k];
|
|
62
|
-
};
|
|
63
59
|
namespace NFC {
|
|
64
60
|
type submodule = Submodule<$>;
|
|
65
61
|
type $ = {
|
|
66
|
-
|
|
62
|
+
root: (In: string) => To<string.normalized.NFC>;
|
|
67
63
|
preformatted: string.normalized.NFC;
|
|
68
64
|
};
|
|
69
65
|
}
|
|
70
66
|
namespace NFD {
|
|
71
67
|
type submodule = Submodule<$>;
|
|
72
68
|
type $ = {
|
|
73
|
-
|
|
69
|
+
root: (In: string) => To<string.normalized.NFD>;
|
|
74
70
|
preformatted: string.normalized.NFD;
|
|
75
71
|
};
|
|
76
72
|
}
|
|
77
73
|
namespace NFKC {
|
|
78
74
|
type submodule = Submodule<$>;
|
|
79
75
|
type $ = {
|
|
80
|
-
|
|
76
|
+
root: (In: string) => To<string.normalized.NFKC>;
|
|
81
77
|
preformatted: string.normalized.NFKC;
|
|
82
78
|
};
|
|
83
79
|
}
|
|
84
80
|
namespace NFKD {
|
|
85
81
|
type submodule = Submodule<$>;
|
|
86
82
|
type $ = {
|
|
87
|
-
|
|
83
|
+
root: (In: string) => To<string.normalized.NFKD>;
|
|
88
84
|
preformatted: string.normalized.NFKD;
|
|
89
85
|
};
|
|
90
86
|
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { rootSchema } from "@ark/schema";
|
|
2
2
|
import { flatMorph } from "@ark/util";
|
|
3
|
-
import {
|
|
3
|
+
import { arkModule } from "../utils.js";
|
|
4
4
|
export const normalizedForms = ["NFC", "NFD", "NFKC", "NFKD"];
|
|
5
5
|
const preformattedNodes = flatMorph(normalizedForms, (i, form) => [
|
|
6
6
|
form,
|
|
7
|
-
|
|
7
|
+
rootSchema({
|
|
8
8
|
domain: "string",
|
|
9
9
|
predicate: (s) => s.normalize(form) === s,
|
|
10
10
|
meta: `${form}-normalized unicode`
|
|
@@ -12,30 +12,30 @@ const preformattedNodes = flatMorph(normalizedForms, (i, form) => [
|
|
|
12
12
|
]);
|
|
13
13
|
const normalizeNodes = flatMorph(normalizedForms, (i, form) => [
|
|
14
14
|
form,
|
|
15
|
-
|
|
15
|
+
rootSchema({
|
|
16
16
|
in: "string",
|
|
17
17
|
morphs: (s) => s.normalize(form),
|
|
18
18
|
declaredOut: preformattedNodes[form]
|
|
19
19
|
})
|
|
20
20
|
]);
|
|
21
|
-
export const NFC =
|
|
22
|
-
|
|
21
|
+
export const NFC = arkModule({
|
|
22
|
+
root: normalizeNodes.NFC,
|
|
23
23
|
preformatted: preformattedNodes.NFC
|
|
24
24
|
});
|
|
25
|
-
export const NFD =
|
|
26
|
-
|
|
25
|
+
export const NFD = arkModule({
|
|
26
|
+
root: normalizeNodes.NFD,
|
|
27
27
|
preformatted: preformattedNodes.NFD
|
|
28
28
|
});
|
|
29
|
-
export const NFKC =
|
|
30
|
-
|
|
29
|
+
export const NFKC = arkModule({
|
|
30
|
+
root: normalizeNodes.NFKC,
|
|
31
31
|
preformatted: preformattedNodes.NFKC
|
|
32
32
|
});
|
|
33
|
-
export const NFKD =
|
|
34
|
-
|
|
33
|
+
export const NFKD = arkModule({
|
|
34
|
+
root: normalizeNodes.NFKD,
|
|
35
35
|
preformatted: preformattedNodes.NFKD
|
|
36
36
|
});
|
|
37
|
-
export const normalize =
|
|
38
|
-
|
|
37
|
+
export const normalize = arkModule({
|
|
38
|
+
root: "NFC",
|
|
39
39
|
NFC,
|
|
40
40
|
NFD,
|
|
41
41
|
NFKC,
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
+
import type { Nominal, of, To } from "../../attributes.ts";
|
|
1
2
|
import type { Module, Submodule } from "../../module.ts";
|
|
2
|
-
import type { Branded, constrain, To } from "../ast.ts";
|
|
3
3
|
declare namespace string {
|
|
4
|
-
type numeric =
|
|
4
|
+
type numeric = of<string, Nominal<"numeric">>;
|
|
5
5
|
}
|
|
6
6
|
export declare const numeric: stringNumeric.module;
|
|
7
7
|
export declare namespace stringNumeric {
|
|
8
8
|
type module = Module<submodule>;
|
|
9
9
|
type submodule = Submodule<$>;
|
|
10
10
|
type $ = {
|
|
11
|
-
|
|
11
|
+
root: string.numeric;
|
|
12
12
|
parse: (In: string.numeric) => To<number>;
|
|
13
13
|
};
|
|
14
14
|
}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { intrinsic,
|
|
1
|
+
import { intrinsic, rootSchema } from "@ark/schema";
|
|
2
2
|
import { wellFormedNumberMatcher } from "@ark/util";
|
|
3
|
-
import {
|
|
3
|
+
import { arkModule } from "../utils.js";
|
|
4
4
|
import { regexStringNode } from "./utils.js";
|
|
5
|
-
const
|
|
6
|
-
export const numeric =
|
|
7
|
-
|
|
8
|
-
parse:
|
|
9
|
-
in:
|
|
5
|
+
const root = regexStringNode(wellFormedNumberMatcher, "a well-formed numeric string");
|
|
6
|
+
export const numeric = arkModule({
|
|
7
|
+
root,
|
|
8
|
+
parse: rootSchema({
|
|
9
|
+
in: root,
|
|
10
10
|
morphs: (s) => Number.parseFloat(s),
|
|
11
11
|
declaredOut: intrinsic.number
|
|
12
12
|
})
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Nominal, of } from "../../attributes.ts";
|
|
2
2
|
declare namespace string {
|
|
3
|
-
type semver =
|
|
3
|
+
type semver = of<string, Nominal<"semver">>;
|
|
4
4
|
}
|
|
5
5
|
export declare const semver: import("@ark/schema").IntersectionNode;
|
|
6
6
|
export type semver = string.semver;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import
|
|
1
|
+
import type { satisfy } from "@ark/util";
|
|
2
|
+
import type { Anonymous, AtLeastLength, AtMostLength, AttributeKind, Attributes, Default, ExactlyLength, LengthAttributeKind, LessThanLength, MoreThanLength, Nominal, Optional, brand, constraint, of } from "../../attributes.ts";
|
|
2
3
|
import type { Module, Submodule } from "../../module.ts";
|
|
3
|
-
import type { type } from "../ark.ts";
|
|
4
|
-
import type { AtLeastLength, AtMostLength, Branded, Constraints, ExactlyLength, LessThanLength, Matching, MoreThanLength, Narrowed, constrain, normalizePrimitiveConstraintRoot } from "../ast.ts";
|
|
5
4
|
import { alpha } from "./alpha.ts";
|
|
6
5
|
import { alphanumeric } from "./alphanumeric.ts";
|
|
6
|
+
import { base64 } from "./base64.ts";
|
|
7
7
|
import { capitalize } from "./capitalize.ts";
|
|
8
8
|
import { creditCard } from "./creditCard.ts";
|
|
9
9
|
import { stringDate } from "./date.ts";
|
|
@@ -23,73 +23,83 @@ import { uuid } from "./uuid.ts";
|
|
|
23
23
|
export declare const string: Module<{
|
|
24
24
|
trim: Submodule<trim.submodule>;
|
|
25
25
|
normalize: Submodule<{
|
|
26
|
-
|
|
26
|
+
root: unknown;
|
|
27
27
|
NFC: Submodule<{
|
|
28
|
-
|
|
29
|
-
preformatted:
|
|
28
|
+
root: unknown;
|
|
29
|
+
preformatted: unknown;
|
|
30
30
|
}>;
|
|
31
31
|
NFD: Submodule<{
|
|
32
|
-
|
|
33
|
-
preformatted:
|
|
32
|
+
root: unknown;
|
|
33
|
+
preformatted: unknown;
|
|
34
34
|
}>;
|
|
35
35
|
NFKC: Submodule<{
|
|
36
|
-
|
|
37
|
-
preformatted:
|
|
36
|
+
root: unknown;
|
|
37
|
+
preformatted: unknown;
|
|
38
38
|
}>;
|
|
39
39
|
NFKD: Submodule<{
|
|
40
|
-
|
|
41
|
-
preformatted:
|
|
40
|
+
root: unknown;
|
|
41
|
+
preformatted: unknown;
|
|
42
42
|
}>;
|
|
43
43
|
}>;
|
|
44
|
+
alpha: unknown;
|
|
45
|
+
alphanumeric: unknown;
|
|
46
|
+
root: unknown;
|
|
47
|
+
url: Submodule<url.submodule>;
|
|
44
48
|
json: Submodule<stringJson.submodule>;
|
|
45
|
-
|
|
49
|
+
base64: Submodule<{
|
|
50
|
+
root: unknown;
|
|
51
|
+
url: unknown;
|
|
52
|
+
}>;
|
|
53
|
+
creditCard: unknown;
|
|
46
54
|
integer: Submodule<stringInteger.submodule>;
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
55
|
+
date: Submodule<stringDate.submodule>;
|
|
56
|
+
digits: unknown;
|
|
57
|
+
email: unknown;
|
|
58
|
+
ip: Submodule<ip.submodule>;
|
|
50
59
|
numeric: Submodule<stringNumeric.submodule>;
|
|
51
|
-
|
|
52
|
-
email: object;
|
|
60
|
+
semver: unknown;
|
|
53
61
|
uuid: Submodule<{
|
|
54
|
-
|
|
55
|
-
v4:
|
|
56
|
-
v6:
|
|
57
|
-
v1:
|
|
58
|
-
v2:
|
|
59
|
-
v3:
|
|
60
|
-
v5:
|
|
61
|
-
v7:
|
|
62
|
-
v8:
|
|
62
|
+
root: string.matching<string> | "00000000-0000-0000-0000-000000000000" | "ffffffff-ffff-ffff-ffff-ffffffffffff";
|
|
63
|
+
v4: unknown;
|
|
64
|
+
v6: unknown;
|
|
65
|
+
v1: unknown;
|
|
66
|
+
v2: unknown;
|
|
67
|
+
v3: unknown;
|
|
68
|
+
v5: unknown;
|
|
69
|
+
v7: unknown;
|
|
70
|
+
v8: unknown;
|
|
63
71
|
}>;
|
|
64
|
-
semver: object;
|
|
65
|
-
ip: Submodule<ip.submodule>;
|
|
66
|
-
date: Submodule<stringDate.submodule>;
|
|
67
|
-
capitalize: Submodule<capitalize.submodule>;
|
|
68
|
-
lower: Submodule<lower.submodule>;
|
|
69
72
|
upper: Submodule<upper.submodule>;
|
|
70
|
-
|
|
73
|
+
lower: Submodule<lower.submodule>;
|
|
74
|
+
capitalize: Submodule<capitalize.submodule>;
|
|
71
75
|
}>;
|
|
76
|
+
export type Matching<rule> = {
|
|
77
|
+
matching: constraint<rule>;
|
|
78
|
+
};
|
|
72
79
|
export declare namespace string {
|
|
73
|
-
type atLeastLength<rule> =
|
|
74
|
-
type moreThanLength<rule> =
|
|
75
|
-
type atMostLength<rule> =
|
|
76
|
-
type lessThanLength<rule> =
|
|
77
|
-
type exactlyLength<rule> =
|
|
78
|
-
type matching<rule> =
|
|
79
|
-
type
|
|
80
|
-
type
|
|
81
|
-
type
|
|
82
|
-
type
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
80
|
+
type atLeastLength<rule> = of<string, AtLeastLength<rule>>;
|
|
81
|
+
type moreThanLength<rule> = of<string, MoreThanLength<rule>>;
|
|
82
|
+
type atMostLength<rule> = of<string, AtMostLength<rule>>;
|
|
83
|
+
type lessThanLength<rule> = of<string, LessThanLength<rule>>;
|
|
84
|
+
type exactlyLength<rule> = of<string, ExactlyLength<rule>>;
|
|
85
|
+
type matching<rule> = of<string, Matching<rule>>;
|
|
86
|
+
type anonymous = of<string, Anonymous>;
|
|
87
|
+
type optional = of<string, Optional>;
|
|
88
|
+
type defaultsTo<rule> = of<string, Default<rule>>;
|
|
89
|
+
type nominal<rule> = of<string, Nominal<rule>>;
|
|
90
|
+
type is<attributes extends Attributes> = of<string, attributes>;
|
|
91
|
+
type AttributableKind = satisfy<AttributeKind, "matching" | LengthAttributeKind>;
|
|
92
|
+
type withSingleAttribute<kind extends AttributableKind, value extends Attributes[kind]> = raw.withSingleAttribute<kind, value>;
|
|
93
|
+
namespace raw {
|
|
94
|
+
type withSingleAttribute<kind, value> = kind extends "nominal" ? nominal<value> : kind extends "matching" ? matching<value> : kind extends "atLeastLength" ? atLeastLength<value> : kind extends "atMostLength" ? atMostLength<value> : kind extends "moreThanLength" ? moreThanLength<value> : kind extends "lessThanLength" ? lessThanLength<value> : kind extends "optional" ? optional : kind extends "defaultsTo" ? defaultsTo<value> : never;
|
|
95
|
+
}
|
|
87
96
|
type module = Module<string.submodule>;
|
|
88
97
|
type submodule = Submodule<$>;
|
|
89
98
|
type $ = {
|
|
90
|
-
|
|
99
|
+
root: string;
|
|
91
100
|
alpha: alpha;
|
|
92
101
|
alphanumeric: alphanumeric;
|
|
102
|
+
base64: base64.submodule;
|
|
93
103
|
digits: digits;
|
|
94
104
|
numeric: stringNumeric.submodule;
|
|
95
105
|
integer: stringInteger.submodule;
|
|
@@ -100,13 +110,26 @@ export declare namespace string {
|
|
|
100
110
|
ip: ip.submodule;
|
|
101
111
|
json: stringJson.submodule;
|
|
102
112
|
date: stringDate.submodule;
|
|
113
|
+
url: url.submodule;
|
|
103
114
|
trim: trim.submodule;
|
|
104
115
|
normalize: normalize.submodule;
|
|
105
116
|
capitalize: capitalize.submodule;
|
|
106
117
|
lower: lower.submodule;
|
|
107
118
|
upper: upper.submodule;
|
|
108
119
|
};
|
|
109
|
-
type
|
|
110
|
-
|
|
111
|
-
|
|
120
|
+
type branded<rule> = brand<string, Nominal<rule>>;
|
|
121
|
+
namespace branded {
|
|
122
|
+
type atLeastLength<rule> = brand<string, AtLeastLength<rule>>;
|
|
123
|
+
type moreThanLength<rule> = brand<string, MoreThanLength<rule>>;
|
|
124
|
+
type atMostLength<rule> = brand<string, AtMostLength<rule>>;
|
|
125
|
+
type lessThanLength<rule> = brand<string, LessThanLength<rule>>;
|
|
126
|
+
type exactlyLength<rule> = brand<string, ExactlyLength<rule>>;
|
|
127
|
+
type matching<rule> = brand<string, Matching<rule>>;
|
|
128
|
+
type anonymous = brand<string, Anonymous>;
|
|
129
|
+
type is<attributes extends Attributes> = brand<string, attributes>;
|
|
130
|
+
type withSingleAttribute<kind extends AttributableKind, value extends Attributes[kind]> = raw.withSingleAttribute<kind, value>;
|
|
131
|
+
namespace raw {
|
|
132
|
+
type withSingleAttribute<kind, value> = kind extends "nominal" ? branded<value> : kind extends "matching" ? matching<value> : kind extends "atLeastLength" ? atLeastLength<value> : kind extends "atMostLength" ? atMostLength<value> : kind extends "moreThanLength" ? moreThanLength<value> : kind extends "lessThanLength" ? lessThanLength<value> : never;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
112
135
|
}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { intrinsic } from "@ark/schema";
|
|
2
|
-
import {
|
|
2
|
+
import { arkModule } from "../utils.js";
|
|
3
3
|
import { alpha } from "./alpha.js";
|
|
4
4
|
import { alphanumeric } from "./alphanumeric.js";
|
|
5
|
+
import { base64 } from "./base64.js";
|
|
5
6
|
import { capitalize } from "./capitalize.js";
|
|
6
7
|
import { creditCard } from "./creditCard.js";
|
|
7
8
|
import { stringDate } from "./date.js";
|
|
@@ -18,12 +19,13 @@ import { trim } from "./trim.js";
|
|
|
18
19
|
import { upper } from "./upper.js";
|
|
19
20
|
import { url } from "./url.js";
|
|
20
21
|
import { uuid } from "./uuid.js";
|
|
21
|
-
export const string =
|
|
22
|
-
|
|
22
|
+
export const string = arkModule({
|
|
23
|
+
root: intrinsic.string,
|
|
23
24
|
numeric,
|
|
24
25
|
integer,
|
|
25
26
|
alpha,
|
|
26
27
|
alphanumeric,
|
|
28
|
+
base64,
|
|
27
29
|
digits,
|
|
28
30
|
semver,
|
|
29
31
|
ip,
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
+
import type { Nominal, of, To } from "../../attributes.ts";
|
|
1
2
|
import type { Module, Submodule } from "../../module.ts";
|
|
2
|
-
import type { Branded, constrain, To } from "../ast.ts";
|
|
3
3
|
declare namespace string {
|
|
4
|
-
type trimmed =
|
|
4
|
+
type trimmed = of<string, Nominal<"trimmed">>;
|
|
5
5
|
}
|
|
6
6
|
export declare const trim: trim.module;
|
|
7
7
|
export declare namespace trim {
|
|
8
8
|
type module = Module<submodule>;
|
|
9
9
|
type submodule = Submodule<$>;
|
|
10
10
|
type $ = {
|
|
11
|
-
|
|
11
|
+
root: (In: string) => To<string.trimmed>;
|
|
12
12
|
preformatted: string.trimmed;
|
|
13
13
|
};
|
|
14
14
|
}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { rootSchema } from "@ark/schema";
|
|
2
|
+
import { arkModule } from "../utils.js";
|
|
3
3
|
import { regexStringNode } from "./utils.js";
|
|
4
4
|
const preformatted = regexStringNode(
|
|
5
5
|
// no leading or trailing whitespace
|
|
6
6
|
/^\S.*\S$|^\S?$/, "trimmed");
|
|
7
|
-
export const trim =
|
|
8
|
-
|
|
7
|
+
export const trim = arkModule({
|
|
8
|
+
root: rootSchema({
|
|
9
9
|
in: "string",
|
|
10
10
|
morphs: (s) => s.trim(),
|
|
11
11
|
declaredOut: preformatted
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
+
import type { Nominal, of, To } from "../../attributes.ts";
|
|
1
2
|
import type { Module, Submodule } from "../../module.ts";
|
|
2
|
-
import type { Branded, constrain, To } from "../ast.ts";
|
|
3
3
|
declare namespace string {
|
|
4
|
-
type uppercase =
|
|
4
|
+
type uppercase = of<string, Nominal<"uppercase">>;
|
|
5
5
|
}
|
|
6
6
|
export declare const upper: upper.module;
|
|
7
7
|
export declare namespace upper {
|
|
8
8
|
type module = Module<submodule>;
|
|
9
9
|
type submodule = Submodule<$>;
|
|
10
10
|
type $ = {
|
|
11
|
-
|
|
11
|
+
root: (In: string) => To<string.uppercase>;
|
|
12
12
|
preformatted: string.uppercase;
|
|
13
13
|
};
|
|
14
14
|
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { rootSchema } from "@ark/schema";
|
|
2
|
+
import { arkModule } from "../utils.js";
|
|
3
3
|
import { regexStringNode } from "./utils.js";
|
|
4
4
|
const preformatted = regexStringNode(/^[A-Z]*$/, "only uppercase letters");
|
|
5
|
-
export const upper =
|
|
6
|
-
|
|
5
|
+
export const upper = arkModule({
|
|
6
|
+
root: rootSchema({
|
|
7
7
|
in: "string",
|
|
8
8
|
morphs: (s) => s.toUpperCase(),
|
|
9
9
|
declaredOut: preformatted
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
+
import type { Nominal, of, To } from "../../attributes.ts";
|
|
1
2
|
import type { Module, Submodule } from "../../module.ts";
|
|
2
|
-
import type { Branded, constrain, To } from "../ast.ts";
|
|
3
3
|
declare namespace string {
|
|
4
|
-
type url =
|
|
4
|
+
type url = of<string, Nominal<"url">>;
|
|
5
5
|
}
|
|
6
6
|
export declare const url: url.module;
|
|
7
7
|
export declare namespace url {
|
|
8
8
|
type module = Module<submodule>;
|
|
9
9
|
type submodule = Submodule<$>;
|
|
10
10
|
type $ = {
|
|
11
|
-
|
|
11
|
+
root: string.url;
|
|
12
12
|
parse: (In: string.url) => To<URL>;
|
|
13
13
|
};
|
|
14
14
|
}
|