arktype 2.0.0-rc.0 → 2.0.0-rc.10
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/config.d.ts +1 -1
- package/out/generic.d.ts +55 -53
- package/out/generic.js +9 -11
- package/out/index.d.ts +5 -5
- package/out/index.js +3 -2
- package/out/keywords/{builtin.d.ts → builtins.d.ts} +9 -5
- package/out/keywords/{builtin.js → builtins.js} +2 -2
- package/out/keywords/constructors/Array.d.ts +12 -8
- package/out/keywords/constructors/Array.js +7 -7
- package/out/keywords/constructors/Date.d.ts +32 -0
- package/out/keywords/constructors/FormData.d.ts +12 -6
- package/out/keywords/constructors/FormData.js +19 -6
- package/out/keywords/constructors/TypedArray.d.ts +18 -14
- package/out/keywords/constructors/TypedArray.js +2 -2
- package/out/keywords/constructors/constructors.d.ts +21 -32
- package/out/keywords/constructors/constructors.js +13 -28
- package/out/keywords/inference.d.ts +227 -0
- package/out/keywords/keywords.d.ts +61 -0
- package/out/keywords/keywords.js +26 -0
- package/out/keywords/number/epoch.d.ts +1 -2
- package/out/keywords/number/epoch.js +2 -2
- package/out/keywords/number/integer.js +2 -2
- package/out/keywords/number/number.d.ts +37 -9
- package/out/keywords/number/number.js +17 -5
- package/out/keywords/string/alpha.d.ts +1 -1
- package/out/keywords/string/alphanumeric.d.ts +1 -1
- package/out/keywords/string/capitalize.d.ts +11 -10
- package/out/keywords/string/capitalize.js +4 -4
- package/out/keywords/string/creditCard.d.ts +1 -1
- package/out/keywords/string/creditCard.js +2 -2
- package/out/keywords/string/date.d.ts +27 -26
- package/out/keywords/string/date.js +16 -16
- package/out/keywords/string/digits.d.ts +1 -1
- package/out/keywords/string/email.d.ts +1 -1
- package/out/keywords/string/integer.d.ts +11 -10
- package/out/keywords/string/integer.js +7 -7
- package/out/keywords/string/ip.d.ts +12 -12
- package/out/keywords/string/ip.js +5 -5
- package/out/keywords/string/json.d.ts +12 -10
- package/out/keywords/string/json.js +24 -16
- package/out/keywords/string/lower.d.ts +11 -10
- package/out/keywords/string/lower.js +4 -4
- package/out/keywords/string/normalize.d.ts +63 -47
- package/out/keywords/string/normalize.js +14 -14
- package/out/keywords/string/numeric.d.ts +11 -10
- package/out/keywords/string/numeric.js +7 -7
- package/out/keywords/string/semver.d.ts +1 -1
- package/out/keywords/string/string.d.ts +78 -26
- package/out/keywords/string/string.js +5 -5
- package/out/keywords/string/trim.d.ts +11 -10
- package/out/keywords/string/trim.js +4 -4
- package/out/keywords/string/upper.d.ts +11 -10
- package/out/keywords/string/upper.js +4 -4
- package/out/keywords/string/url.d.ts +11 -10
- package/out/keywords/string/url.js +8 -8
- package/out/keywords/string/uuid.d.ts +27 -23
- package/out/keywords/string/uuid.js +3 -3
- package/out/keywords/ts.d.ts +44 -22
- package/out/keywords/ts.js +20 -14
- 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 +96 -0
- package/out/{subtypes → methods}/date.d.ts +5 -5
- package/out/{subtypes → methods}/instantiate.d.ts +5 -4
- package/out/methods/morph.d.ts +12 -0
- package/out/{subtypes → methods}/number.d.ts +6 -6
- package/out/methods/object.d.ts +81 -0
- package/out/{subtypes → methods}/string.d.ts +7 -7
- package/out/{subtypes → methods}/validator.d.ts +2 -2
- package/out/module.d.ts +2 -2
- package/out/parser/{semantic → ast}/bounds.d.ts +6 -4
- package/out/parser/ast/default.d.ts +8 -0
- package/out/parser/ast/infer.d.ts +39 -0
- package/out/parser/ast/utils.d.ts +4 -0
- package/out/parser/ast/validate.d.ts +26 -0
- package/out/parser/definition.d.ts +9 -12
- package/out/parser/objectLiteral.d.ts +11 -25
- package/out/parser/objectLiteral.js +6 -24
- package/out/parser/{string/reduce → reduce}/dynamic.d.ts +5 -7
- 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 -1
- package/out/parser/{string/shift → shift}/operand/enclosed.js +7 -3
- package/out/parser/{string/shift → shift}/operand/unenclosed.d.ts +7 -8
- package/out/parser/{string/shift → shift}/operand/unenclosed.js +7 -3
- package/out/parser/{string/shift → shift}/operator/bounds.d.ts +7 -6
- package/out/parser/{string/shift → shift}/operator/default.d.ts +3 -6
- package/out/parser/{string/shift → shift}/operator/default.js +1 -6
- package/out/parser/{string/shift → shift}/operator/operator.js +2 -2
- package/out/parser/{string/shift → shift}/scanner.d.ts +6 -2
- package/out/parser/{string/shift → shift}/scanner.js +7 -5
- package/out/parser/{string/string.d.ts → string.d.ts} +8 -8
- package/out/parser/{string/string.js → string.js} +2 -0
- package/out/parser/tuple.d.ts +54 -43
- package/out/parser/tuple.js +36 -30
- package/out/scope.d.ts +41 -34
- package/out/scope.js +48 -27
- package/out/type.d.ts +25 -20
- package/out/type.js +23 -14
- 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 -33
- package/out/keywords/ark.js +0 -18
- package/out/keywords/ast.d.ts +0 -193
- package/out/parser/semantic/default.d.ts +0 -8
- package/out/parser/semantic/default.js +0 -1
- package/out/parser/semantic/infer.d.ts +0 -33
- package/out/parser/semantic/utils.d.ts +0 -4
- package/out/parser/semantic/validate.d.ts +0 -29
- package/out/subtypes/base.d.ts +0 -84
- package/out/subtypes/morph.d.ts +0 -13
- package/out/subtypes/object.d.ts +0 -33
- /package/out/{intersect.js → keywords/constructors/Date.js} +0 -0
- /package/out/keywords/{ast.js → inference.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/{subtypes → methods}/validator.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/{semantic → ast}/validate.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
- /package/out/parser/{string/shift → shift}/operator/operator.d.ts +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { ArkErrors, intrinsic,
|
|
1
|
+
import { ArkErrors, intrinsic, rootSchema } from "@ark/schema";
|
|
2
2
|
import { number } from "../number/number.js";
|
|
3
|
-
import {
|
|
3
|
+
import { arkModule } from "../utils.js";
|
|
4
4
|
import { integer } from "./integer.js";
|
|
5
5
|
import { regexStringNode } from "./utils.js";
|
|
6
6
|
const dayDelimiterMatcher = /^[./-]$/;
|
|
@@ -40,14 +40,14 @@ export const tryParseDatePattern = (data, opts) => {
|
|
|
40
40
|
return writeFormattedExpected(opts.format);
|
|
41
41
|
};
|
|
42
42
|
const isParsableDate = (s) => !Number.isNaN(new Date(s).valueOf());
|
|
43
|
-
const parsableDate =
|
|
43
|
+
const parsableDate = rootSchema({
|
|
44
44
|
domain: "string",
|
|
45
45
|
predicate: {
|
|
46
46
|
meta: "a parsable date",
|
|
47
47
|
predicate: isParsableDate
|
|
48
48
|
}
|
|
49
49
|
}).assertHasKind("intersection");
|
|
50
|
-
const
|
|
50
|
+
const epochRoot = integer.root.internal
|
|
51
51
|
.narrow((s, ctx) => {
|
|
52
52
|
// we know this is safe since it has already
|
|
53
53
|
// been validated as an integer string
|
|
@@ -63,26 +63,26 @@ const epoch$root = integer.$root.internal
|
|
|
63
63
|
description: "an integer string representing a safe Unix timestamp"
|
|
64
64
|
})
|
|
65
65
|
.assertHasKind("intersection");
|
|
66
|
-
const epoch =
|
|
67
|
-
|
|
68
|
-
parse:
|
|
69
|
-
in:
|
|
66
|
+
const epoch = arkModule({
|
|
67
|
+
root: epochRoot,
|
|
68
|
+
parse: rootSchema({
|
|
69
|
+
in: epochRoot,
|
|
70
70
|
morphs: (s) => new Date(s),
|
|
71
71
|
declaredOut: intrinsic.Date
|
|
72
72
|
})
|
|
73
73
|
});
|
|
74
|
-
const
|
|
75
|
-
const iso =
|
|
76
|
-
|
|
77
|
-
parse:
|
|
78
|
-
in:
|
|
74
|
+
const isoRoot = regexStringNode(iso8601Matcher, "an ISO 8601 (YYYY-MM-DDTHH:mm:ss.sssZ) date").internal.assertHasKind("intersection");
|
|
75
|
+
const iso = arkModule({
|
|
76
|
+
root: isoRoot,
|
|
77
|
+
parse: rootSchema({
|
|
78
|
+
in: isoRoot,
|
|
79
79
|
morphs: (s) => new Date(s),
|
|
80
80
|
declaredOut: intrinsic.Date
|
|
81
81
|
})
|
|
82
82
|
});
|
|
83
|
-
export const
|
|
84
|
-
|
|
85
|
-
parse:
|
|
83
|
+
export const stringDate = arkModule({
|
|
84
|
+
root: parsableDate,
|
|
85
|
+
parse: rootSchema({
|
|
86
86
|
declaredIn: parsableDate,
|
|
87
87
|
in: "string",
|
|
88
88
|
morphs: (s, ctx) => {
|
|
@@ -1,15 +1,16 @@
|
|
|
1
|
-
import type { Submodule } from "../../module.ts";
|
|
2
|
-
import type { Branded, constrain, To } from "../
|
|
1
|
+
import type { Module, Submodule } from "../../module.ts";
|
|
2
|
+
import type { Branded, constrain, To } from "../inference.ts";
|
|
3
3
|
import type { number } from "../number/number.ts";
|
|
4
4
|
declare namespace string {
|
|
5
5
|
type integer = constrain<string, Branded<"integer">>;
|
|
6
6
|
}
|
|
7
|
-
export declare const integer:
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
}
|
|
7
|
+
export declare const integer: stringInteger.module;
|
|
8
|
+
export declare namespace stringInteger {
|
|
9
|
+
type module = Module<submodule>;
|
|
10
|
+
type submodule = Submodule<$>;
|
|
11
|
+
type $ = {
|
|
12
|
+
root: string.integer;
|
|
13
|
+
parse: (In: string.integer) => To<number.divisibleBy<1>>;
|
|
14
|
+
};
|
|
15
|
+
}
|
|
15
16
|
export {};
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { intrinsic,
|
|
1
|
+
import { intrinsic, rootSchema } from "@ark/schema";
|
|
2
2
|
import { wellFormedIntegerMatcher } from "@ark/util";
|
|
3
|
-
import {
|
|
3
|
+
import { arkModule } from "../utils.js";
|
|
4
4
|
import { regexStringNode } from "./utils.js";
|
|
5
|
-
const
|
|
6
|
-
export const integer =
|
|
7
|
-
|
|
8
|
-
parse:
|
|
9
|
-
in:
|
|
5
|
+
const root = regexStringNode(wellFormedIntegerMatcher, "a well-formed integer string");
|
|
6
|
+
export const integer = arkModule({
|
|
7
|
+
root,
|
|
8
|
+
parse: rootSchema({
|
|
9
|
+
in: root,
|
|
10
10
|
morphs: (s, ctx) => {
|
|
11
11
|
const parsed = Number.parseInt(s);
|
|
12
12
|
return Number.isSafeInteger(parsed) ? parsed : (ctx.error("an integer in the range Number.MIN_SAFE_INTEGER to Number.MAX_SAFE_INTEGER"));
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { Submodule } from "../../module.ts";
|
|
2
|
-
import type { Branded, constrain } from "../
|
|
1
|
+
import type { Module, Submodule } from "../../module.ts";
|
|
2
|
+
import type { Branded, constrain } from "../inference.ts";
|
|
3
3
|
declare namespace string {
|
|
4
4
|
type ip = constrain<string, Branded<"ip">>;
|
|
5
5
|
namespace ip {
|
|
@@ -7,14 +7,14 @@ declare namespace string {
|
|
|
7
7
|
type v6 = constrain<string, Branded<"ip.v6">>;
|
|
8
8
|
}
|
|
9
9
|
}
|
|
10
|
-
export declare const ip:
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
}
|
|
10
|
+
export declare const ip: ip.module;
|
|
11
|
+
export declare namespace ip {
|
|
12
|
+
type module = Module<submodule>;
|
|
13
|
+
type submodule = Submodule<$>;
|
|
14
|
+
type $ = {
|
|
15
|
+
root: string.ip;
|
|
16
|
+
v4: string.ip.v4;
|
|
17
|
+
v6: string.ip.v6;
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
20
|
export {};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { arkModule } from "../utils.js";
|
|
2
2
|
import { regexStringNode } from "./utils.js";
|
|
3
3
|
// Based on https://github.com/validatorjs/validator.js/blob/master/src/lib/isIP.js
|
|
4
|
+
// Adjusted to incorporate unmerged fix in https://github.com/validatorjs/validator.js/pull/2083
|
|
4
5
|
const ipv4Segment = "(?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])";
|
|
5
6
|
const ipv4Address = `(${ipv4Segment}[.]){3}${ipv4Segment}`;
|
|
6
7
|
const ipv4Matcher = new RegExp(`^${ipv4Address}$`);
|
|
@@ -14,10 +15,9 @@ const ipv6Matcher = new RegExp("^(" +
|
|
|
14
15
|
`(?:${ipv6Segment}:){2}(?:(:${ipv6Segment}){0,3}:${ipv4Address}|(:${ipv6Segment}){1,5}|:)|` +
|
|
15
16
|
`(?:${ipv6Segment}:){1}(?:(:${ipv6Segment}){0,4}:${ipv4Address}|(:${ipv6Segment}){1,6}|:)|` +
|
|
16
17
|
`(?::((?::${ipv6Segment}){0,5}:${ipv4Address}|(?::${ipv6Segment}){1,7}|:))` +
|
|
17
|
-
")(%[0-9a-zA-Z
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
$root: ["v4 | v6", "@", "an IP address"],
|
|
18
|
+
")(%[0-9a-zA-Z.]{1,})?$");
|
|
19
|
+
export const ip = arkModule({
|
|
20
|
+
root: ["v4 | v6", "@", "an IP address"],
|
|
21
21
|
v4: regexStringNode(ipv4Matcher, "an IPv4 address"),
|
|
22
22
|
v6: regexStringNode(ipv6Matcher, "an IPv6 address")
|
|
23
23
|
});
|
|
@@ -1,14 +1,16 @@
|
|
|
1
|
-
import type { Submodule } from "../../module.ts";
|
|
2
|
-
import type { Branded, To, constrain } from "../
|
|
1
|
+
import type { Module, Submodule } from "../../module.ts";
|
|
2
|
+
import type { Branded, To, constrain } from "../inference.ts";
|
|
3
3
|
declare namespace string {
|
|
4
4
|
type json = constrain<string, Branded<"json">>;
|
|
5
5
|
}
|
|
6
|
-
export declare const
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
$
|
|
12
|
-
|
|
13
|
-
|
|
6
|
+
export declare const writeJsonSyntaxErrorProblem: (error: unknown) => string;
|
|
7
|
+
export declare const json: stringJson.module;
|
|
8
|
+
export declare namespace stringJson {
|
|
9
|
+
type module = Module<submodule>;
|
|
10
|
+
type submodule = Submodule<$>;
|
|
11
|
+
type $ = {
|
|
12
|
+
root: string.json;
|
|
13
|
+
parse: (In: string.json) => To<object>;
|
|
14
|
+
};
|
|
15
|
+
}
|
|
14
16
|
export {};
|
|
@@ -1,25 +1,33 @@
|
|
|
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:
|
|
13
|
+
predicate: (s, ctx) => {
|
|
14
|
+
try {
|
|
15
|
+
JSON.parse(s);
|
|
16
|
+
return true;
|
|
17
|
+
}
|
|
18
|
+
catch (e) {
|
|
19
|
+
return ctx.reject({
|
|
20
|
+
code: "predicate",
|
|
21
|
+
expected: jsonStringDescription,
|
|
22
|
+
problem: writeJsonSyntaxErrorProblem(e)
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
}
|
|
18
26
|
}
|
|
19
27
|
});
|
|
20
|
-
export const json =
|
|
21
|
-
|
|
22
|
-
parse:
|
|
28
|
+
export const json = arkModule({
|
|
29
|
+
root,
|
|
30
|
+
parse: rootSchema({
|
|
23
31
|
in: "string",
|
|
24
32
|
morphs: (s, ctx) => {
|
|
25
33
|
if (s.length === 0) {
|
|
@@ -36,7 +44,7 @@ export const json = submodule({
|
|
|
36
44
|
return ctx.error({
|
|
37
45
|
code: "predicate",
|
|
38
46
|
expected: jsonStringDescription,
|
|
39
|
-
problem:
|
|
47
|
+
problem: writeJsonSyntaxErrorProblem(e)
|
|
40
48
|
});
|
|
41
49
|
}
|
|
42
50
|
},
|
|
@@ -1,14 +1,15 @@
|
|
|
1
|
-
import type { Submodule } from "../../module.ts";
|
|
2
|
-
import type { Branded, constrain, To } from "../
|
|
1
|
+
import type { Module, Submodule } from "../../module.ts";
|
|
2
|
+
import type { Branded, constrain, To } from "../inference.ts";
|
|
3
3
|
declare namespace string {
|
|
4
4
|
type lowercase = constrain<string, Branded<"lowercase">>;
|
|
5
5
|
}
|
|
6
|
-
export
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
}
|
|
6
|
+
export declare const lower: lower.module;
|
|
7
|
+
export declare namespace lower {
|
|
8
|
+
type module = Module<submodule>;
|
|
9
|
+
type submodule = Submodule<$>;
|
|
10
|
+
type $ = {
|
|
11
|
+
root: (In: string) => To<string.lowercase>;
|
|
12
|
+
preformatted: string.lowercase;
|
|
13
|
+
};
|
|
14
|
+
}
|
|
14
15
|
export {};
|
|
@@ -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,5 +1,5 @@
|
|
|
1
|
-
import type { Submodule } from "../../module.ts";
|
|
2
|
-
import type { Branded, constrain, To } from "../
|
|
1
|
+
import type { Module, Submodule } from "../../module.ts";
|
|
2
|
+
import type { Branded, constrain, To } from "../inference.ts";
|
|
3
3
|
declare namespace string {
|
|
4
4
|
type normalized = normalized.NFC;
|
|
5
5
|
namespace normalized {
|
|
@@ -11,62 +11,78 @@ declare namespace string {
|
|
|
11
11
|
}
|
|
12
12
|
export declare const normalizedForms: readonly ["NFC", "NFD", "NFKC", "NFKD"];
|
|
13
13
|
export type NormalizedForm = (typeof normalizedForms)[number];
|
|
14
|
-
export
|
|
15
|
-
|
|
16
|
-
preformatted:
|
|
14
|
+
export declare const NFC: Module<{
|
|
15
|
+
root: unknown;
|
|
16
|
+
preformatted: unknown;
|
|
17
17
|
}>;
|
|
18
|
-
export declare const
|
|
19
|
-
|
|
20
|
-
preformatted:
|
|
18
|
+
export declare const NFD: Module<{
|
|
19
|
+
root: unknown;
|
|
20
|
+
preformatted: unknown;
|
|
21
21
|
}>;
|
|
22
|
-
export
|
|
23
|
-
|
|
24
|
-
preformatted:
|
|
22
|
+
export declare const NFKC: Module<{
|
|
23
|
+
root: unknown;
|
|
24
|
+
preformatted: unknown;
|
|
25
25
|
}>;
|
|
26
|
-
export declare const
|
|
27
|
-
|
|
28
|
-
preformatted:
|
|
26
|
+
export declare const NFKD: Module<{
|
|
27
|
+
root: unknown;
|
|
28
|
+
preformatted: unknown;
|
|
29
29
|
}>;
|
|
30
|
-
export
|
|
31
|
-
|
|
32
|
-
preformatted: string.normalized.NFKC;
|
|
33
|
-
}>;
|
|
34
|
-
export declare const NFKC: import("../../module.ts").Module<{
|
|
35
|
-
$root: object;
|
|
36
|
-
preformatted: object;
|
|
37
|
-
}>;
|
|
38
|
-
export type NFKD = Submodule<{
|
|
39
|
-
$root: (In: string) => To<string.normalized.NFKD>;
|
|
40
|
-
preformatted: string.normalized.NFKD;
|
|
41
|
-
}>;
|
|
42
|
-
export declare const NFKD: import("../../module.ts").Module<{
|
|
43
|
-
$root: object;
|
|
44
|
-
preformatted: object;
|
|
45
|
-
}>;
|
|
46
|
-
export declare const normalize: import("../../module.ts").Module<{
|
|
47
|
-
$root: object;
|
|
30
|
+
export declare const normalize: Module<{
|
|
31
|
+
root: unknown;
|
|
48
32
|
NFC: Submodule<{
|
|
49
|
-
|
|
50
|
-
preformatted:
|
|
33
|
+
root: unknown;
|
|
34
|
+
preformatted: unknown;
|
|
51
35
|
}>;
|
|
52
36
|
NFD: Submodule<{
|
|
53
|
-
|
|
54
|
-
preformatted:
|
|
37
|
+
root: unknown;
|
|
38
|
+
preformatted: unknown;
|
|
55
39
|
}>;
|
|
56
40
|
NFKC: Submodule<{
|
|
57
|
-
|
|
58
|
-
preformatted:
|
|
41
|
+
root: unknown;
|
|
42
|
+
preformatted: unknown;
|
|
59
43
|
}>;
|
|
60
44
|
NFKD: Submodule<{
|
|
61
|
-
|
|
62
|
-
preformatted:
|
|
45
|
+
root: unknown;
|
|
46
|
+
preformatted: unknown;
|
|
63
47
|
}>;
|
|
64
48
|
}>;
|
|
65
|
-
export
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
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
|
+
}
|
|
72
88
|
export {};
|
|
@@ -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,15 @@
|
|
|
1
|
-
import type { Submodule } from "../../module.ts";
|
|
2
|
-
import type { Branded, constrain, To } from "../
|
|
1
|
+
import type { Module, Submodule } from "../../module.ts";
|
|
2
|
+
import type { Branded, constrain, To } from "../inference.ts";
|
|
3
3
|
declare namespace string {
|
|
4
4
|
type numeric = constrain<string, Branded<"numeric">>;
|
|
5
5
|
}
|
|
6
|
-
export declare const numeric:
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
}
|
|
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
|
+
}
|
|
14
15
|
export {};
|
|
@@ -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
|
})
|