arktype 2.0.0-rc.25 → 2.0.0-rc.27
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 +61 -241
- package/out/attributes.js +1 -2
- package/out/generic.d.ts +4 -4
- package/out/keywords/{constructors/Array.d.ts → Array.d.ts} +2 -2
- package/out/keywords/{constructors/Array.js → Array.js} +1 -1
- package/out/keywords/{constructors/FormData.d.ts → FormData.d.ts} +2 -2
- package/out/keywords/{constructors/FormData.js → FormData.js} +1 -1
- package/out/keywords/{constructors/TypedArray.d.ts → TypedArray.d.ts} +1 -1
- package/out/keywords/{constructors/TypedArray.js → TypedArray.js} +1 -1
- package/out/keywords/{constructors/constructors.d.ts → constructors.d.ts} +1 -1
- package/out/keywords/{constructors/constructors.js → constructors.js} +1 -1
- package/out/keywords/keywords.d.ts +6 -9
- package/out/keywords/keywords.js +3 -3
- package/out/keywords/number.d.ts +23 -0
- package/out/keywords/{number/epoch.js → number.js} +23 -1
- package/out/keywords/string.d.ts +327 -0
- package/out/keywords/string.js +398 -0
- package/out/methods/array.d.ts +6 -7
- package/out/methods/base.d.ts +10 -14
- package/out/methods/date.d.ts +5 -6
- package/out/methods/number.d.ts +6 -7
- package/out/methods/object.d.ts +5 -5
- package/out/methods/string.d.ts +7 -8
- package/out/parser/ast/generic.d.ts +17 -0
- package/out/parser/ast/infer.d.ts +4 -18
- package/out/parser/ast/validate.d.ts +10 -6
- package/out/parser/ast/validate.js +2 -0
- package/out/parser/definition.d.ts +17 -8
- package/out/parser/definition.js +20 -2
- package/out/parser/objectLiteral.d.ts +39 -39
- package/out/parser/objectLiteral.js +75 -49
- package/out/parser/property.d.ts +37 -0
- package/out/parser/property.js +16 -0
- package/out/parser/reduce/dynamic.d.ts +1 -1
- package/out/parser/shift/operand/enclosed.d.ts +1 -3
- package/out/parser/shift/operand/unenclosed.d.ts +2 -1
- package/out/parser/shift/operator/bounds.js +5 -4
- package/out/parser/shift/operator/default.d.ts +2 -1
- package/out/parser/shift/operator/default.js +1 -1
- package/out/parser/string.d.ts +5 -4
- package/out/parser/string.js +18 -1
- package/out/parser/tupleExpressions.d.ts +47 -0
- package/out/parser/tupleExpressions.js +67 -0
- package/out/parser/tupleLiteral.d.ts +80 -0
- package/out/parser/tupleLiteral.js +119 -0
- package/out/scope.d.ts +8 -7
- package/out/scope.js +12 -32
- package/out/type.d.ts +5 -5
- package/package.json +3 -3
- package/out/keywords/constructors/Date.d.ts +0 -37
- package/out/keywords/number/epoch.d.ts +0 -10
- package/out/keywords/number/integer.d.ts +0 -3
- package/out/keywords/number/integer.js +0 -5
- package/out/keywords/number/number.d.ts +0 -58
- package/out/keywords/number/number.js +0 -21
- package/out/keywords/string/alpha.d.ts +0 -7
- package/out/keywords/string/alpha.js +0 -2
- package/out/keywords/string/alphanumeric.d.ts +0 -7
- package/out/keywords/string/alphanumeric.js +0 -2
- package/out/keywords/string/base64.d.ts +0 -21
- package/out/keywords/string/base64.js +0 -6
- package/out/keywords/string/capitalize.d.ts +0 -15
- package/out/keywords/string/capitalize.js +0 -12
- package/out/keywords/string/creditCard.d.ts +0 -8
- package/out/keywords/string/creditCard.js +0 -37
- package/out/keywords/string/date.d.ts +0 -55
- package/out/keywords/string/date.js +0 -98
- package/out/keywords/string/digits.d.ts +0 -7
- package/out/keywords/string/digits.js +0 -2
- package/out/keywords/string/email.d.ts +0 -7
- package/out/keywords/string/email.js +0 -4
- package/out/keywords/string/integer.d.ts +0 -16
- package/out/keywords/string/integer.js +0 -16
- package/out/keywords/string/ip.d.ts +0 -20
- package/out/keywords/string/ip.js +0 -23
- package/out/keywords/string/json.d.ts +0 -16
- package/out/keywords/string/json.js +0 -54
- package/out/keywords/string/lower.d.ts +0 -15
- package/out/keywords/string/lower.js +0 -12
- package/out/keywords/string/normalize.d.ts +0 -88
- package/out/keywords/string/normalize.js +0 -43
- package/out/keywords/string/numeric.d.ts +0 -15
- package/out/keywords/string/numeric.js +0 -13
- package/out/keywords/string/semver.d.ts +0 -7
- package/out/keywords/string/semver.js +0 -4
- package/out/keywords/string/string.d.ts +0 -135
- package/out/keywords/string/string.js +0 -43
- package/out/keywords/string/trim.d.ts +0 -15
- package/out/keywords/string/trim.js +0 -14
- package/out/keywords/string/upper.d.ts +0 -15
- package/out/keywords/string/upper.js +0 -12
- package/out/keywords/string/url.d.ts +0 -15
- package/out/keywords/string/url.js +0 -37
- package/out/keywords/string/utils.d.ts +0 -2
- package/out/keywords/string/utils.js +0 -10
- package/out/keywords/string/uuid.d.ts +0 -42
- package/out/keywords/string/uuid.js +0 -19
- package/out/parser/tuple.d.ts +0 -148
- package/out/parser/tuple.js +0 -164
- /package/out/{keywords/constructors/Date.js → parser/ast/generic.js} +0 -0
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
import type { Nominal, of, To } from "../../attributes.ts";
|
|
2
|
-
import type { Module, Submodule } from "../../module.ts";
|
|
3
|
-
declare namespace string {
|
|
4
|
-
type normalized = normalized.NFC;
|
|
5
|
-
namespace normalized {
|
|
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">>;
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
export declare const normalizedForms: readonly ["NFC", "NFD", "NFKC", "NFKD"];
|
|
13
|
-
export type NormalizedForm = (typeof normalizedForms)[number];
|
|
14
|
-
export declare const NFC: Module<{
|
|
15
|
-
root: unknown;
|
|
16
|
-
preformatted: unknown;
|
|
17
|
-
}>;
|
|
18
|
-
export declare const NFD: Module<{
|
|
19
|
-
root: unknown;
|
|
20
|
-
preformatted: unknown;
|
|
21
|
-
}>;
|
|
22
|
-
export declare const NFKC: Module<{
|
|
23
|
-
root: unknown;
|
|
24
|
-
preformatted: unknown;
|
|
25
|
-
}>;
|
|
26
|
-
export declare const NFKD: Module<{
|
|
27
|
-
root: unknown;
|
|
28
|
-
preformatted: unknown;
|
|
29
|
-
}>;
|
|
30
|
-
export declare const normalize: Module<{
|
|
31
|
-
root: unknown;
|
|
32
|
-
NFC: Submodule<{
|
|
33
|
-
root: unknown;
|
|
34
|
-
preformatted: unknown;
|
|
35
|
-
}>;
|
|
36
|
-
NFD: Submodule<{
|
|
37
|
-
root: unknown;
|
|
38
|
-
preformatted: unknown;
|
|
39
|
-
}>;
|
|
40
|
-
NFKC: Submodule<{
|
|
41
|
-
root: unknown;
|
|
42
|
-
preformatted: unknown;
|
|
43
|
-
}>;
|
|
44
|
-
NFKD: Submodule<{
|
|
45
|
-
root: unknown;
|
|
46
|
-
preformatted: unknown;
|
|
47
|
-
}>;
|
|
48
|
-
}>;
|
|
49
|
-
export declare namespace normalize {
|
|
50
|
-
type module = Module<submodule>;
|
|
51
|
-
type submodule = Submodule<$>;
|
|
52
|
-
type $ = {
|
|
53
|
-
root: (In: string) => To<string.normalized.NFC>;
|
|
54
|
-
NFC: NFC.submodule;
|
|
55
|
-
NFD: NFD.submodule;
|
|
56
|
-
NFKC: NFKC.submodule;
|
|
57
|
-
NFKD: NFKD.submodule;
|
|
58
|
-
};
|
|
59
|
-
namespace NFC {
|
|
60
|
-
type submodule = Submodule<$>;
|
|
61
|
-
type $ = {
|
|
62
|
-
root: (In: string) => To<string.normalized.NFC>;
|
|
63
|
-
preformatted: string.normalized.NFC;
|
|
64
|
-
};
|
|
65
|
-
}
|
|
66
|
-
namespace NFD {
|
|
67
|
-
type submodule = Submodule<$>;
|
|
68
|
-
type $ = {
|
|
69
|
-
root: (In: string) => To<string.normalized.NFD>;
|
|
70
|
-
preformatted: string.normalized.NFD;
|
|
71
|
-
};
|
|
72
|
-
}
|
|
73
|
-
namespace NFKC {
|
|
74
|
-
type submodule = Submodule<$>;
|
|
75
|
-
type $ = {
|
|
76
|
-
root: (In: string) => To<string.normalized.NFKC>;
|
|
77
|
-
preformatted: string.normalized.NFKC;
|
|
78
|
-
};
|
|
79
|
-
}
|
|
80
|
-
namespace NFKD {
|
|
81
|
-
type submodule = Submodule<$>;
|
|
82
|
-
type $ = {
|
|
83
|
-
root: (In: string) => To<string.normalized.NFKD>;
|
|
84
|
-
preformatted: string.normalized.NFKD;
|
|
85
|
-
};
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
export {};
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import { rootSchema } from "@ark/schema";
|
|
2
|
-
import { flatMorph } from "@ark/util";
|
|
3
|
-
import { arkModule } from "../utils.js";
|
|
4
|
-
export const normalizedForms = ["NFC", "NFD", "NFKC", "NFKD"];
|
|
5
|
-
const preformattedNodes = flatMorph(normalizedForms, (i, form) => [
|
|
6
|
-
form,
|
|
7
|
-
rootSchema({
|
|
8
|
-
domain: "string",
|
|
9
|
-
predicate: (s) => s.normalize(form) === s,
|
|
10
|
-
meta: `${form}-normalized unicode`
|
|
11
|
-
})
|
|
12
|
-
]);
|
|
13
|
-
const normalizeNodes = flatMorph(normalizedForms, (i, form) => [
|
|
14
|
-
form,
|
|
15
|
-
rootSchema({
|
|
16
|
-
in: "string",
|
|
17
|
-
morphs: (s) => s.normalize(form),
|
|
18
|
-
declaredOut: preformattedNodes[form]
|
|
19
|
-
})
|
|
20
|
-
]);
|
|
21
|
-
export const NFC = arkModule({
|
|
22
|
-
root: normalizeNodes.NFC,
|
|
23
|
-
preformatted: preformattedNodes.NFC
|
|
24
|
-
});
|
|
25
|
-
export const NFD = arkModule({
|
|
26
|
-
root: normalizeNodes.NFD,
|
|
27
|
-
preformatted: preformattedNodes.NFD
|
|
28
|
-
});
|
|
29
|
-
export const NFKC = arkModule({
|
|
30
|
-
root: normalizeNodes.NFKC,
|
|
31
|
-
preformatted: preformattedNodes.NFKC
|
|
32
|
-
});
|
|
33
|
-
export const NFKD = arkModule({
|
|
34
|
-
root: normalizeNodes.NFKD,
|
|
35
|
-
preformatted: preformattedNodes.NFKD
|
|
36
|
-
});
|
|
37
|
-
export const normalize = arkModule({
|
|
38
|
-
root: "NFC",
|
|
39
|
-
NFC,
|
|
40
|
-
NFD,
|
|
41
|
-
NFKC,
|
|
42
|
-
NFKD
|
|
43
|
-
});
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import type { Nominal, of, To } from "../../attributes.ts";
|
|
2
|
-
import type { Module, Submodule } from "../../module.ts";
|
|
3
|
-
declare namespace string {
|
|
4
|
-
type numeric = of<string, Nominal<"numeric">>;
|
|
5
|
-
}
|
|
6
|
-
export declare const numeric: stringNumeric.module;
|
|
7
|
-
export declare namespace stringNumeric {
|
|
8
|
-
type module = Module<submodule>;
|
|
9
|
-
type submodule = Submodule<$>;
|
|
10
|
-
type $ = {
|
|
11
|
-
root: string.numeric;
|
|
12
|
-
parse: (In: string.numeric) => To<number>;
|
|
13
|
-
};
|
|
14
|
-
}
|
|
15
|
-
export {};
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { intrinsic, rootSchema } from "@ark/schema";
|
|
2
|
-
import { wellFormedNumberMatcher } from "@ark/util";
|
|
3
|
-
import { arkModule } from "../utils.js";
|
|
4
|
-
import { regexStringNode } from "./utils.js";
|
|
5
|
-
const root = regexStringNode(wellFormedNumberMatcher, "a well-formed numeric string");
|
|
6
|
-
export const numeric = arkModule({
|
|
7
|
-
root,
|
|
8
|
-
parse: rootSchema({
|
|
9
|
-
in: root,
|
|
10
|
-
morphs: (s) => Number.parseFloat(s),
|
|
11
|
-
declaredOut: intrinsic.number
|
|
12
|
-
})
|
|
13
|
-
});
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import { regexStringNode } from "./utils.js";
|
|
2
|
-
// https://semver.org/
|
|
3
|
-
const semverMatcher = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/;
|
|
4
|
-
export const semver = regexStringNode(semverMatcher, "a semantic version (see https://semver.org/)");
|
|
@@ -1,135 +0,0 @@
|
|
|
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";
|
|
3
|
-
import type { Module, Submodule } from "../../module.ts";
|
|
4
|
-
import { alpha } from "./alpha.ts";
|
|
5
|
-
import { alphanumeric } from "./alphanumeric.ts";
|
|
6
|
-
import { base64 } from "./base64.ts";
|
|
7
|
-
import { capitalize } from "./capitalize.ts";
|
|
8
|
-
import { creditCard } from "./creditCard.ts";
|
|
9
|
-
import { stringDate } from "./date.ts";
|
|
10
|
-
import { digits } from "./digits.ts";
|
|
11
|
-
import { email } from "./email.ts";
|
|
12
|
-
import { type stringInteger } from "./integer.ts";
|
|
13
|
-
import { ip } from "./ip.ts";
|
|
14
|
-
import { type stringJson } from "./json.ts";
|
|
15
|
-
import { lower } from "./lower.ts";
|
|
16
|
-
import { normalize } from "./normalize.ts";
|
|
17
|
-
import { type stringNumeric } from "./numeric.ts";
|
|
18
|
-
import { semver } from "./semver.ts";
|
|
19
|
-
import { trim } from "./trim.ts";
|
|
20
|
-
import { upper } from "./upper.ts";
|
|
21
|
-
import { url } from "./url.ts";
|
|
22
|
-
import { uuid } from "./uuid.ts";
|
|
23
|
-
export declare const string: Module<{
|
|
24
|
-
trim: Submodule<trim.submodule>;
|
|
25
|
-
normalize: Submodule<{
|
|
26
|
-
root: unknown;
|
|
27
|
-
NFC: Submodule<{
|
|
28
|
-
root: unknown;
|
|
29
|
-
preformatted: unknown;
|
|
30
|
-
}>;
|
|
31
|
-
NFD: Submodule<{
|
|
32
|
-
root: unknown;
|
|
33
|
-
preformatted: unknown;
|
|
34
|
-
}>;
|
|
35
|
-
NFKC: Submodule<{
|
|
36
|
-
root: unknown;
|
|
37
|
-
preformatted: unknown;
|
|
38
|
-
}>;
|
|
39
|
-
NFKD: Submodule<{
|
|
40
|
-
root: unknown;
|
|
41
|
-
preformatted: unknown;
|
|
42
|
-
}>;
|
|
43
|
-
}>;
|
|
44
|
-
alpha: unknown;
|
|
45
|
-
alphanumeric: unknown;
|
|
46
|
-
root: unknown;
|
|
47
|
-
url: Submodule<url.submodule>;
|
|
48
|
-
json: Submodule<stringJson.submodule>;
|
|
49
|
-
base64: Submodule<{
|
|
50
|
-
root: unknown;
|
|
51
|
-
url: unknown;
|
|
52
|
-
}>;
|
|
53
|
-
creditCard: unknown;
|
|
54
|
-
integer: Submodule<stringInteger.submodule>;
|
|
55
|
-
date: Submodule<stringDate.submodule>;
|
|
56
|
-
digits: unknown;
|
|
57
|
-
email: unknown;
|
|
58
|
-
ip: Submodule<ip.submodule>;
|
|
59
|
-
numeric: Submodule<stringNumeric.submodule>;
|
|
60
|
-
semver: unknown;
|
|
61
|
-
uuid: Submodule<{
|
|
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;
|
|
71
|
-
}>;
|
|
72
|
-
capitalize: Submodule<capitalize.submodule>;
|
|
73
|
-
lower: Submodule<lower.submodule>;
|
|
74
|
-
upper: Submodule<upper.submodule>;
|
|
75
|
-
}>;
|
|
76
|
-
export type Matching<rule> = {
|
|
77
|
-
matching: constraint<rule>;
|
|
78
|
-
};
|
|
79
|
-
export declare namespace string {
|
|
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
|
-
}
|
|
96
|
-
type module = Module<string.submodule>;
|
|
97
|
-
type submodule = Submodule<$>;
|
|
98
|
-
type $ = {
|
|
99
|
-
root: string;
|
|
100
|
-
alpha: alpha;
|
|
101
|
-
alphanumeric: alphanumeric;
|
|
102
|
-
base64: base64.submodule;
|
|
103
|
-
capitalize: capitalize.submodule;
|
|
104
|
-
creditCard: creditCard;
|
|
105
|
-
date: stringDate.submodule;
|
|
106
|
-
digits: digits;
|
|
107
|
-
email: email;
|
|
108
|
-
integer: stringInteger.submodule;
|
|
109
|
-
ip: ip.submodule;
|
|
110
|
-
json: stringJson.submodule;
|
|
111
|
-
lower: lower.submodule;
|
|
112
|
-
normalize: normalize.submodule;
|
|
113
|
-
numeric: stringNumeric.submodule;
|
|
114
|
-
semver: semver;
|
|
115
|
-
trim: trim.submodule;
|
|
116
|
-
upper: upper.submodule;
|
|
117
|
-
url: url.submodule;
|
|
118
|
-
uuid: uuid.submodule;
|
|
119
|
-
};
|
|
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
|
-
}
|
|
135
|
-
}
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import { intrinsic } from "@ark/schema";
|
|
2
|
-
import { arkModule } from "../utils.js";
|
|
3
|
-
import { alpha } from "./alpha.js";
|
|
4
|
-
import { alphanumeric } from "./alphanumeric.js";
|
|
5
|
-
import { base64 } from "./base64.js";
|
|
6
|
-
import { capitalize } from "./capitalize.js";
|
|
7
|
-
import { creditCard } from "./creditCard.js";
|
|
8
|
-
import { stringDate } from "./date.js";
|
|
9
|
-
import { digits } from "./digits.js";
|
|
10
|
-
import { email } from "./email.js";
|
|
11
|
-
import { integer } from "./integer.js";
|
|
12
|
-
import { ip } from "./ip.js";
|
|
13
|
-
import { json } from "./json.js";
|
|
14
|
-
import { lower } from "./lower.js";
|
|
15
|
-
import { normalize } from "./normalize.js";
|
|
16
|
-
import { numeric } from "./numeric.js";
|
|
17
|
-
import { semver } from "./semver.js";
|
|
18
|
-
import { trim } from "./trim.js";
|
|
19
|
-
import { upper } from "./upper.js";
|
|
20
|
-
import { url } from "./url.js";
|
|
21
|
-
import { uuid } from "./uuid.js";
|
|
22
|
-
export const string = arkModule({
|
|
23
|
-
root: intrinsic.string,
|
|
24
|
-
alpha,
|
|
25
|
-
alphanumeric,
|
|
26
|
-
base64,
|
|
27
|
-
capitalize,
|
|
28
|
-
creditCard,
|
|
29
|
-
date: stringDate,
|
|
30
|
-
digits,
|
|
31
|
-
email,
|
|
32
|
-
integer,
|
|
33
|
-
ip,
|
|
34
|
-
json,
|
|
35
|
-
lower,
|
|
36
|
-
normalize,
|
|
37
|
-
numeric,
|
|
38
|
-
semver,
|
|
39
|
-
trim,
|
|
40
|
-
upper,
|
|
41
|
-
url,
|
|
42
|
-
uuid
|
|
43
|
-
});
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import type { Nominal, of, To } from "../../attributes.ts";
|
|
2
|
-
import type { Module, Submodule } from "../../module.ts";
|
|
3
|
-
declare namespace string {
|
|
4
|
-
type trimmed = of<string, Nominal<"trimmed">>;
|
|
5
|
-
}
|
|
6
|
-
export declare const trim: trim.module;
|
|
7
|
-
export declare namespace trim {
|
|
8
|
-
type module = Module<submodule>;
|
|
9
|
-
type submodule = Submodule<$>;
|
|
10
|
-
type $ = {
|
|
11
|
-
root: (In: string) => To<string.trimmed>;
|
|
12
|
-
preformatted: string.trimmed;
|
|
13
|
-
};
|
|
14
|
-
}
|
|
15
|
-
export {};
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { rootSchema } from "@ark/schema";
|
|
2
|
-
import { arkModule } from "../utils.js";
|
|
3
|
-
import { regexStringNode } from "./utils.js";
|
|
4
|
-
const preformatted = regexStringNode(
|
|
5
|
-
// no leading or trailing whitespace
|
|
6
|
-
/^\S.*\S$|^\S?$/, "trimmed");
|
|
7
|
-
export const trim = arkModule({
|
|
8
|
-
root: rootSchema({
|
|
9
|
-
in: "string",
|
|
10
|
-
morphs: (s) => s.trim(),
|
|
11
|
-
declaredOut: preformatted
|
|
12
|
-
}),
|
|
13
|
-
preformatted
|
|
14
|
-
});
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import type { Nominal, of, To } from "../../attributes.ts";
|
|
2
|
-
import type { Module, Submodule } from "../../module.ts";
|
|
3
|
-
declare namespace string {
|
|
4
|
-
type uppercase = of<string, Nominal<"uppercase">>;
|
|
5
|
-
}
|
|
6
|
-
export declare const upper: upper.module;
|
|
7
|
-
export declare namespace upper {
|
|
8
|
-
type module = Module<submodule>;
|
|
9
|
-
type submodule = Submodule<$>;
|
|
10
|
-
type $ = {
|
|
11
|
-
root: (In: string) => To<string.uppercase>;
|
|
12
|
-
preformatted: string.uppercase;
|
|
13
|
-
};
|
|
14
|
-
}
|
|
15
|
-
export {};
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { rootSchema } from "@ark/schema";
|
|
2
|
-
import { arkModule } from "../utils.js";
|
|
3
|
-
import { regexStringNode } from "./utils.js";
|
|
4
|
-
const preformatted = regexStringNode(/^[A-Z]*$/, "only uppercase letters");
|
|
5
|
-
export const upper = arkModule({
|
|
6
|
-
root: rootSchema({
|
|
7
|
-
in: "string",
|
|
8
|
-
morphs: (s) => s.toUpperCase(),
|
|
9
|
-
declaredOut: preformatted
|
|
10
|
-
}),
|
|
11
|
-
preformatted
|
|
12
|
-
});
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import type { Nominal, of, To } from "../../attributes.ts";
|
|
2
|
-
import type { Module, Submodule } from "../../module.ts";
|
|
3
|
-
declare namespace string {
|
|
4
|
-
type url = of<string, Nominal<"url">>;
|
|
5
|
-
}
|
|
6
|
-
export declare const url: url.module;
|
|
7
|
-
export declare namespace url {
|
|
8
|
-
type module = Module<submodule>;
|
|
9
|
-
type submodule = Submodule<$>;
|
|
10
|
-
type $ = {
|
|
11
|
-
root: string.url;
|
|
12
|
-
parse: (In: string.url) => To<URL>;
|
|
13
|
-
};
|
|
14
|
-
}
|
|
15
|
-
export {};
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import { rootSchema } from "@ark/schema";
|
|
2
|
-
import { arkModule } from "../utils.js";
|
|
3
|
-
const isParsableUrl = (s) => {
|
|
4
|
-
if (URL.canParse)
|
|
5
|
-
return URL.canParse(s);
|
|
6
|
-
// Can be removed once Node 18 is EOL
|
|
7
|
-
try {
|
|
8
|
-
new URL(s);
|
|
9
|
-
return true;
|
|
10
|
-
}
|
|
11
|
-
catch {
|
|
12
|
-
return false;
|
|
13
|
-
}
|
|
14
|
-
};
|
|
15
|
-
const root = rootSchema({
|
|
16
|
-
domain: "string",
|
|
17
|
-
predicate: {
|
|
18
|
-
meta: "a URL string",
|
|
19
|
-
predicate: isParsableUrl
|
|
20
|
-
}
|
|
21
|
-
});
|
|
22
|
-
export const url = arkModule({
|
|
23
|
-
root,
|
|
24
|
-
parse: rootSchema({
|
|
25
|
-
declaredIn: root,
|
|
26
|
-
in: "string",
|
|
27
|
-
morphs: (s, ctx) => {
|
|
28
|
-
try {
|
|
29
|
-
return new URL(s);
|
|
30
|
-
}
|
|
31
|
-
catch {
|
|
32
|
-
return ctx.error("a URL string");
|
|
33
|
-
}
|
|
34
|
-
},
|
|
35
|
-
declaredOut: rootSchema(URL)
|
|
36
|
-
})
|
|
37
|
-
});
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { node } from "@ark/schema";
|
|
2
|
-
// Non-trivial expressions should have an explanation or attribution
|
|
3
|
-
export const regexStringNode = (regex, description) => node("intersection", {
|
|
4
|
-
domain: "string",
|
|
5
|
-
pattern: {
|
|
6
|
-
rule: regex.source,
|
|
7
|
-
flags: regex.flags,
|
|
8
|
-
meta: description
|
|
9
|
-
}
|
|
10
|
-
});
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import type { Nominal, of } from "../../attributes.ts";
|
|
2
|
-
import type { Module, Submodule } from "../../module.ts";
|
|
3
|
-
export declare const uuid: Module<{
|
|
4
|
-
root: import("./string.ts").string.matching<string> | "00000000-0000-0000-0000-000000000000" | "ffffffff-ffff-ffff-ffff-ffffffffffff";
|
|
5
|
-
v4: unknown;
|
|
6
|
-
v6: unknown;
|
|
7
|
-
v1: unknown;
|
|
8
|
-
v2: unknown;
|
|
9
|
-
v3: unknown;
|
|
10
|
-
v5: unknown;
|
|
11
|
-
v7: unknown;
|
|
12
|
-
v8: unknown;
|
|
13
|
-
}>;
|
|
14
|
-
declare namespace string {
|
|
15
|
-
type uuid = of<string, Nominal<"uuid">>;
|
|
16
|
-
namespace uuid {
|
|
17
|
-
type v1 = of<string, Nominal<"uuid.v1">>;
|
|
18
|
-
type v2 = of<string, Nominal<"uuid.v2">>;
|
|
19
|
-
type v3 = of<string, Nominal<"uuid.v3">>;
|
|
20
|
-
type v4 = of<string, Nominal<"uuid.v4">>;
|
|
21
|
-
type v5 = of<string, Nominal<"uuid.v5">>;
|
|
22
|
-
type v6 = of<string, Nominal<"uuid.v6">>;
|
|
23
|
-
type v7 = of<string, Nominal<"uuid.v7">>;
|
|
24
|
-
type v8 = of<string, Nominal<"uuid.v8">>;
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
export declare namespace uuid {
|
|
28
|
-
type module = Module<submodule>;
|
|
29
|
-
type submodule = Submodule<$>;
|
|
30
|
-
type $ = {
|
|
31
|
-
root: string.uuid;
|
|
32
|
-
v1: string.uuid.v1;
|
|
33
|
-
v2: string.uuid.v2;
|
|
34
|
-
v3: string.uuid.v3;
|
|
35
|
-
v4: string.uuid.v4;
|
|
36
|
-
v5: string.uuid.v5;
|
|
37
|
-
v6: string.uuid.v6;
|
|
38
|
-
v7: string.uuid.v7;
|
|
39
|
-
v8: string.uuid.v8;
|
|
40
|
-
};
|
|
41
|
-
}
|
|
42
|
-
export {};
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { arkModule } from "../utils.js";
|
|
2
|
-
import { regexStringNode } from "./utils.js";
|
|
3
|
-
// Based on https://github.com/validatorjs/validator.js/blob/master/src/lib/isUUID.js
|
|
4
|
-
export const uuid = arkModule({
|
|
5
|
-
// the meta tuple expression ensures the error message does not delegate
|
|
6
|
-
// to the individual branches, which are too detailed
|
|
7
|
-
root: ["versioned | nil | max", "@", "a UUID"],
|
|
8
|
-
"#nil": "'00000000-0000-0000-0000-000000000000'",
|
|
9
|
-
"#max": "'ffffffff-ffff-ffff-ffff-ffffffffffff'",
|
|
10
|
-
"#versioned": /[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}/i,
|
|
11
|
-
v1: regexStringNode(/^[0-9a-f]{8}-[0-9a-f]{4}-1[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i, "a UUIDv1"),
|
|
12
|
-
v2: regexStringNode(/^[0-9a-f]{8}-[0-9a-f]{4}-2[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i, "a UUIDv2"),
|
|
13
|
-
v3: regexStringNode(/^[0-9a-f]{8}-[0-9a-f]{4}-3[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i, "a UUIDv3"),
|
|
14
|
-
v4: regexStringNode(/^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i, "a UUIDv4"),
|
|
15
|
-
v5: regexStringNode(/^[0-9a-f]{8}-[0-9a-f]{4}-5[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i, "a UUIDv5"),
|
|
16
|
-
v6: regexStringNode(/^[0-9a-f]{8}-[0-9a-f]{4}-6[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i, "a UUIDv6"),
|
|
17
|
-
v7: regexStringNode(/^[0-9a-f]{8}-[0-9a-f]{4}-7[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i, "a UUIDv7"),
|
|
18
|
-
v8: regexStringNode(/^[0-9a-f]{8}-[0-9a-f]{4}-8[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i, "a UUIDv8")
|
|
19
|
-
});
|