arktype 2.0.0-rc.3 → 2.0.0-rc.31

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.
Files changed (176) hide show
  1. package/out/attributes.d.ts +94 -0
  2. package/out/attributes.js +3 -0
  3. package/out/config.d.ts +1 -1
  4. package/out/generic.d.ts +55 -58
  5. package/out/generic.js +6 -8
  6. package/out/index.d.ts +6 -4
  7. package/out/index.js +4 -3
  8. package/out/keywords/{constructors/Array.d.ts → Array.d.ts} +3 -3
  9. package/out/keywords/{constructors/Array.js → Array.js} +7 -7
  10. package/out/keywords/{constructors/FormData.d.ts → FormData.d.ts} +3 -3
  11. package/out/keywords/{constructors/FormData.js → FormData.js} +8 -8
  12. package/out/keywords/{constructors/TypedArray.d.ts → TypedArray.d.ts} +1 -1
  13. package/out/keywords/{constructors/TypedArray.js → TypedArray.js} +2 -2
  14. package/out/keywords/builtins.js +2 -2
  15. package/out/keywords/{constructors/constructors.d.ts → constructors.d.ts} +1 -2
  16. package/out/keywords/{constructors/constructors.js → constructors.js} +2 -2
  17. package/out/keywords/keywords.d.ts +61 -0
  18. package/out/keywords/keywords.js +29 -0
  19. package/out/keywords/number.d.ts +23 -0
  20. package/out/keywords/{number/epoch.js → number.js} +24 -2
  21. package/out/keywords/string.d.ts +327 -0
  22. package/out/keywords/string.js +398 -0
  23. package/out/keywords/ts.d.ts +42 -4
  24. package/out/keywords/ts.js +24 -7
  25. package/out/methods/array.d.ts +12 -0
  26. package/out/methods/base.d.ts +178 -0
  27. package/out/methods/date.d.ts +10 -0
  28. package/out/methods/instantiate.d.ts +17 -0
  29. package/out/methods/morph.d.ts +12 -0
  30. package/out/methods/number.d.ts +11 -0
  31. package/out/methods/object.d.ts +106 -0
  32. package/out/methods/string.d.ts +12 -0
  33. package/out/module.d.ts +2 -2
  34. package/out/parser/{semantic → ast}/bounds.d.ts +3 -3
  35. package/out/parser/ast/default.d.ts +8 -0
  36. package/out/parser/ast/generic.d.ts +17 -0
  37. package/out/parser/ast/infer.d.ts +25 -0
  38. package/out/parser/{semantic → ast}/utils.d.ts +1 -1
  39. package/out/parser/ast/validate.d.ts +30 -0
  40. package/out/parser/ast/validate.js +3 -0
  41. package/out/parser/definition.d.ts +21 -13
  42. package/out/parser/definition.js +20 -2
  43. package/out/parser/objectLiteral.d.ts +41 -67
  44. package/out/parser/objectLiteral.js +84 -71
  45. package/out/parser/property.d.ts +36 -0
  46. package/out/parser/property.js +16 -0
  47. package/out/parser/{string/reduce → reduce}/dynamic.d.ts +10 -13
  48. package/out/parser/{string/reduce → reduce}/dynamic.js +5 -6
  49. package/out/parser/{string/reduce → reduce}/shared.d.ts +1 -1
  50. package/out/parser/{string/reduce → reduce}/static.d.ts +4 -4
  51. package/out/parser/{string/shift → shift}/operand/date.d.ts +3 -1
  52. package/out/parser/{string/shift → shift}/operand/enclosed.d.ts +4 -4
  53. package/out/parser/{string/shift → shift}/operand/enclosed.js +7 -3
  54. package/out/parser/shift/operand/operand.d.ts +9 -0
  55. package/out/parser/{string/shift → shift}/operand/operand.js +2 -2
  56. package/out/parser/{string/shift → shift}/operand/unenclosed.d.ts +15 -7
  57. package/out/parser/{string/shift → shift}/operand/unenclosed.js +12 -7
  58. package/out/parser/{string/shift → shift}/operator/bounds.d.ts +7 -7
  59. package/out/parser/{string/shift → shift}/operator/bounds.js +5 -4
  60. package/out/parser/shift/operator/brand.d.ts +6 -0
  61. package/out/parser/shift/operator/brand.js +5 -0
  62. package/out/parser/{string/shift → shift}/operator/default.d.ts +4 -6
  63. package/out/parser/{string/shift → shift}/operator/default.js +4 -6
  64. package/out/parser/{string/shift → shift}/operator/divisor.d.ts +2 -2
  65. package/out/parser/shift/operator/operator.d.ts +14 -0
  66. package/out/parser/{string/shift → shift}/operator/operator.js +7 -5
  67. package/out/parser/shift/scanner.d.ts +47 -0
  68. package/out/parser/shift/scanner.js +43 -0
  69. package/out/parser/{string/string.d.ts → string.d.ts} +9 -9
  70. package/out/parser/{string/string.js → string.js} +19 -0
  71. package/out/parser/tupleExpressions.d.ts +47 -0
  72. package/out/parser/tupleExpressions.js +67 -0
  73. package/out/parser/tupleLiteral.d.ts +95 -0
  74. package/out/parser/tupleLiteral.js +122 -0
  75. package/out/scope.d.ts +41 -34
  76. package/out/scope.js +54 -62
  77. package/out/type.d.ts +46 -22
  78. package/out/type.js +15 -11
  79. package/package.json +3 -3
  80. package/out/intersect.d.ts +0 -28
  81. package/out/keys.d.ts +0 -16
  82. package/out/keywords/ark.d.ts +0 -39
  83. package/out/keywords/ark.js +0 -24
  84. package/out/keywords/ast.d.ts +0 -193
  85. package/out/keywords/ast.js +0 -2
  86. package/out/keywords/number/epoch.d.ts +0 -10
  87. package/out/keywords/number/integer.d.ts +0 -3
  88. package/out/keywords/number/integer.js +0 -5
  89. package/out/keywords/number/number.d.ts +0 -28
  90. package/out/keywords/number/number.js +0 -9
  91. package/out/keywords/string/alpha.d.ts +0 -7
  92. package/out/keywords/string/alpha.js +0 -2
  93. package/out/keywords/string/alphanumeric.d.ts +0 -7
  94. package/out/keywords/string/alphanumeric.js +0 -2
  95. package/out/keywords/string/capitalize.d.ts +0 -15
  96. package/out/keywords/string/capitalize.js +0 -12
  97. package/out/keywords/string/creditCard.d.ts +0 -8
  98. package/out/keywords/string/creditCard.js +0 -37
  99. package/out/keywords/string/date.d.ts +0 -59
  100. package/out/keywords/string/date.js +0 -98
  101. package/out/keywords/string/digits.d.ts +0 -7
  102. package/out/keywords/string/digits.js +0 -2
  103. package/out/keywords/string/email.d.ts +0 -7
  104. package/out/keywords/string/email.js +0 -4
  105. package/out/keywords/string/integer.d.ts +0 -16
  106. package/out/keywords/string/integer.js +0 -16
  107. package/out/keywords/string/ip.d.ts +0 -20
  108. package/out/keywords/string/ip.js +0 -23
  109. package/out/keywords/string/json.d.ts +0 -15
  110. package/out/keywords/string/json.js +0 -45
  111. package/out/keywords/string/lower.d.ts +0 -15
  112. package/out/keywords/string/lower.js +0 -12
  113. package/out/keywords/string/normalize.d.ts +0 -92
  114. package/out/keywords/string/normalize.js +0 -43
  115. package/out/keywords/string/numeric.d.ts +0 -15
  116. package/out/keywords/string/numeric.js +0 -13
  117. package/out/keywords/string/semver.d.ts +0 -7
  118. package/out/keywords/string/semver.js +0 -4
  119. package/out/keywords/string/string.d.ts +0 -112
  120. package/out/keywords/string/string.js +0 -41
  121. package/out/keywords/string/trim.d.ts +0 -15
  122. package/out/keywords/string/trim.js +0 -14
  123. package/out/keywords/string/upper.d.ts +0 -15
  124. package/out/keywords/string/upper.js +0 -12
  125. package/out/keywords/string/url.d.ts +0 -15
  126. package/out/keywords/string/url.js +0 -37
  127. package/out/keywords/string/utils.d.ts +0 -2
  128. package/out/keywords/string/utils.js +0 -10
  129. package/out/keywords/string/uuid.d.ts +0 -42
  130. package/out/keywords/string/uuid.js +0 -19
  131. package/out/keywords/utils.d.ts +0 -1
  132. package/out/keywords/utils.js +0 -2
  133. package/out/parser/semantic/default.d.ts +0 -9
  134. package/out/parser/semantic/default.js +0 -1
  135. package/out/parser/semantic/infer.d.ts +0 -39
  136. package/out/parser/semantic/validate.d.ts +0 -26
  137. package/out/parser/semantic/validate.js +0 -1
  138. package/out/parser/string/shift/operand/operand.d.ts +0 -9
  139. package/out/parser/string/shift/operator/operator.d.ts +0 -13
  140. package/out/parser/string/shift/scanner.d.ts +0 -69
  141. package/out/parser/string/shift/scanner.js +0 -100
  142. package/out/parser/tuple.d.ts +0 -132
  143. package/out/parser/tuple.js +0 -158
  144. package/out/subtypes/array.d.ts +0 -13
  145. package/out/subtypes/base.d.ts +0 -85
  146. package/out/subtypes/date.d.ts +0 -11
  147. package/out/subtypes/instantiate.d.ts +0 -16
  148. package/out/subtypes/morph.d.ts +0 -13
  149. package/out/subtypes/number.d.ts +0 -12
  150. package/out/subtypes/object.d.ts +0 -33
  151. package/out/subtypes/string.d.ts +0 -13
  152. package/out/subtypes/validator.d.ts +0 -11
  153. package/out/subtypes/validator.js +0 -1
  154. /package/out/{subtypes → methods}/array.js +0 -0
  155. /package/out/{subtypes → methods}/base.js +0 -0
  156. /package/out/{subtypes → methods}/date.js +0 -0
  157. /package/out/{subtypes → methods}/instantiate.js +0 -0
  158. /package/out/{subtypes → methods}/morph.js +0 -0
  159. /package/out/{subtypes → methods}/number.js +0 -0
  160. /package/out/{subtypes → methods}/object.js +0 -0
  161. /package/out/{subtypes → methods}/string.js +0 -0
  162. /package/out/parser/{semantic → ast}/bounds.js +0 -0
  163. /package/out/{intersect.js → parser/ast/default.js} +0 -0
  164. /package/out/parser/{semantic → ast}/divisor.d.ts +0 -0
  165. /package/out/parser/{semantic → ast}/divisor.js +0 -0
  166. /package/out/{keys.js → parser/ast/generic.js} +0 -0
  167. /package/out/parser/{semantic → ast}/infer.js +0 -0
  168. /package/out/parser/{semantic → ast}/keyof.d.ts +0 -0
  169. /package/out/parser/{semantic → ast}/keyof.js +0 -0
  170. /package/out/parser/{semantic → ast}/utils.js +0 -0
  171. /package/out/parser/{string/reduce → reduce}/shared.js +0 -0
  172. /package/out/parser/{string/reduce → reduce}/static.js +0 -0
  173. /package/out/parser/{string/shift → shift}/operand/date.js +0 -0
  174. /package/out/parser/{string/shift → shift}/operand/genericArgs.d.ts +0 -0
  175. /package/out/parser/{string/shift → shift}/operand/genericArgs.js +0 -0
  176. /package/out/parser/{string/shift → shift}/operator/divisor.js +0 -0
@@ -1,98 +0,0 @@
1
- import { ArkErrors, intrinsic, rootNode } from "@ark/schema";
2
- import { number } from "../number/number.js";
3
- import { submodule } from "../utils.js";
4
- import { integer } from "./integer.js";
5
- import { regexStringNode } from "./utils.js";
6
- const dayDelimiterMatcher = /^[./-]$/;
7
- // ISO 8601 date/time modernized from https://github.com/validatorjs/validator.js/blob/master/src/lib/isISO8601.js
8
- // Based on https://tc39.es/ecma262/#sec-date-time-string-format, the T
9
- // delimiter for date/time is mandatory. Regex from validator.js strict matcher:
10
- export const iso8601Matcher = /^([+-]?\d{4}(?!\d{2}\b))((-?)((0[1-9]|1[0-2])(\3([12]\d|0[1-9]|3[01]))?|W([0-4]\d|5[0-3])(-?[1-7])?|(00[1-9]|0[1-9]\d|[12]\d{2}|3([0-5]\d|6[1-6])))([T]((([01]\d|2[0-3])((:?)[0-5]\d)?|24:?00)([.,]\d+(?!:))?)?(\17[0-5]\d([.,]\d+)?)?([zZ]|([+-])([01]\d|2[0-3]):?([0-5]\d)?)?)?)?$/;
11
- const isValidDateInstance = (date) => !Number.isNaN(+date);
12
- const writeFormattedExpected = (format) => `a ${format}-formatted date`;
13
- export const tryParseDatePattern = (data, opts) => {
14
- if (!opts?.format) {
15
- const result = new Date(data);
16
- return isValidDateInstance(result) ? result : "a valid date";
17
- }
18
- if (opts.format === "iso") {
19
- return iso8601Matcher.test(data) ?
20
- new Date(data)
21
- : writeFormattedExpected("iso");
22
- }
23
- const dataParts = data.split(dayDelimiterMatcher);
24
- // will be the first delimiter matched, if there is one
25
- const delimiter = data[dataParts[0].length];
26
- const formatParts = delimiter ? opts.format.split(delimiter) : [opts.format];
27
- if (dataParts.length !== formatParts.length)
28
- return writeFormattedExpected(opts.format);
29
- const parsedParts = {};
30
- for (let i = 0; i < formatParts.length; i++) {
31
- if (dataParts[i].length !== formatParts[i].length &&
32
- // if format is "m" or "d", data is allowed to be 1 or 2 characters
33
- !(formatParts[i].length === 1 && dataParts[i].length === 2))
34
- return writeFormattedExpected(opts.format);
35
- parsedParts[formatParts[i][0]] = dataParts[i];
36
- }
37
- const date = new Date(`${parsedParts.m}/${parsedParts.d}/${parsedParts.y}`);
38
- if (`${date.getDate()}` === parsedParts.d)
39
- return date;
40
- return writeFormattedExpected(opts.format);
41
- };
42
- const isParsableDate = (s) => !Number.isNaN(new Date(s).valueOf());
43
- const parsableDate = rootNode({
44
- domain: "string",
45
- predicate: {
46
- meta: "a parsable date",
47
- predicate: isParsableDate
48
- }
49
- }).assertHasKind("intersection");
50
- const epoch$root = integer.$root.internal
51
- .narrow((s, ctx) => {
52
- // we know this is safe since it has already
53
- // been validated as an integer string
54
- const n = Number.parseInt(s);
55
- const out = number.epoch(n);
56
- if (out instanceof ArkErrors) {
57
- ctx.errors.merge(out);
58
- return false;
59
- }
60
- return true;
61
- })
62
- .withMeta({
63
- description: "an integer string representing a safe Unix timestamp"
64
- })
65
- .assertHasKind("intersection");
66
- const epoch = submodule({
67
- $root: epoch$root,
68
- parse: rootNode({
69
- in: epoch$root,
70
- morphs: (s) => new Date(s),
71
- declaredOut: intrinsic.Date
72
- })
73
- });
74
- const iso$root = regexStringNode(iso8601Matcher, "an ISO 8601 (YYYY-MM-DDTHH:mm:ss.sssZ) date").internal.assertHasKind("intersection");
75
- const iso = submodule({
76
- $root: iso$root,
77
- parse: rootNode({
78
- in: iso$root,
79
- morphs: (s) => new Date(s),
80
- declaredOut: intrinsic.Date
81
- })
82
- });
83
- export const stringDate = submodule({
84
- $root: parsableDate,
85
- parse: rootNode({
86
- declaredIn: parsableDate,
87
- in: "string",
88
- morphs: (s, ctx) => {
89
- const date = new Date(s);
90
- if (Number.isNaN(date.valueOf()))
91
- return ctx.error("a parsable date");
92
- return date;
93
- },
94
- declaredOut: intrinsic.Date
95
- }),
96
- iso,
97
- epoch
98
- });
@@ -1,7 +0,0 @@
1
- import type { Branded, constrain } from "../ast.ts";
2
- declare namespace string {
3
- type digits = constrain<string, Branded<"digits">>;
4
- }
5
- export declare const digits: import("@ark/schema").IntersectionNode;
6
- export type digits = string.digits;
7
- export {};
@@ -1,2 +0,0 @@
1
- import { regexStringNode } from "./utils.js";
2
- export const digits = regexStringNode(/^\d*$/, "only digits 0-9");
@@ -1,7 +0,0 @@
1
- import type { Branded, constrain } from "../ast.ts";
2
- declare namespace string {
3
- type email = constrain<string, Branded<"email">>;
4
- }
5
- export declare const email: import("@ark/schema").IntersectionNode;
6
- export type email = string.email;
7
- export {};
@@ -1,4 +0,0 @@
1
- import { regexStringNode } from "./utils.js";
2
- export const email = regexStringNode(
3
- // https://www.regular-expressions.info/email.html
4
- /^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}$/, "an email address");
@@ -1,16 +0,0 @@
1
- import type { Module, Submodule } from "../../module.ts";
2
- import type { Branded, constrain, To } from "../ast.ts";
3
- import type { number } from "../number/number.ts";
4
- declare namespace string {
5
- type integer = constrain<string, Branded<"integer">>;
6
- }
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
- }
16
- export {};
@@ -1,16 +0,0 @@
1
- import { intrinsic, rootNode } from "@ark/schema";
2
- import { wellFormedIntegerMatcher } from "@ark/util";
3
- import { submodule } from "../utils.js";
4
- import { regexStringNode } from "./utils.js";
5
- const $root = regexStringNode(wellFormedIntegerMatcher, "a well-formed integer string");
6
- export const integer = submodule({
7
- $root,
8
- parse: rootNode({
9
- in: $root,
10
- morphs: (s, ctx) => {
11
- const parsed = Number.parseInt(s);
12
- return Number.isSafeInteger(parsed) ? parsed : (ctx.error("an integer in the range Number.MIN_SAFE_INTEGER to Number.MAX_SAFE_INTEGER"));
13
- },
14
- declaredOut: intrinsic.integer
15
- })
16
- });
@@ -1,20 +0,0 @@
1
- import type { Module, Submodule } from "../../module.ts";
2
- import type { Branded, constrain } from "../ast.ts";
3
- declare namespace string {
4
- type ip = constrain<string, Branded<"ip">>;
5
- namespace ip {
6
- type v4 = constrain<string, Branded<"ip.v4">>;
7
- type v6 = constrain<string, Branded<"ip.v6">>;
8
- }
9
- }
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
- export {};
@@ -1,23 +0,0 @@
1
- import { submodule } from "../utils.js";
2
- import { regexStringNode } from "./utils.js";
3
- // Based on https://github.com/validatorjs/validator.js/blob/master/src/lib/isIP.js
4
- const ipv4Segment = "(?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])";
5
- const ipv4Address = `(${ipv4Segment}[.]){3}${ipv4Segment}`;
6
- const ipv4Matcher = new RegExp(`^${ipv4Address}$`);
7
- const ipv6Segment = "(?:[0-9a-fA-F]{1,4})";
8
- const ipv6Matcher = new RegExp("^(" +
9
- `(?:${ipv6Segment}:){7}(?:${ipv6Segment}|:)|` +
10
- `(?:${ipv6Segment}:){6}(?:${ipv4Address}|:${ipv6Segment}|:)|` +
11
- `(?:${ipv6Segment}:){5}(?::${ipv4Address}|(:${ipv6Segment}){1,2}|:)|` +
12
- `(?:${ipv6Segment}:){4}(?:(:${ipv6Segment}){0,1}:${ipv4Address}|(:${ipv6Segment}){1,3}|:)|` +
13
- `(?:${ipv6Segment}:){3}(?:(:${ipv6Segment}){0,2}:${ipv4Address}|(:${ipv6Segment}){1,4}|:)|` +
14
- `(?:${ipv6Segment}:){2}(?:(:${ipv6Segment}){0,3}:${ipv4Address}|(:${ipv6Segment}){1,5}|:)|` +
15
- `(?:${ipv6Segment}:){1}(?:(:${ipv6Segment}){0,4}:${ipv4Address}|(:${ipv6Segment}){1,6}|:)|` +
16
- `(?::((?::${ipv6Segment}){0,5}:${ipv4Address}|(?::${ipv6Segment}){1,7}|:))` +
17
- ")(%[0-9a-zA-Z-.:]{1,})?$");
18
- // Based on https://github.com/validatorjs/validator.js/blob/master/src/lib/isUUID.js
19
- export const ip = submodule({
20
- $root: ["v4 | v6", "@", "an IP address"],
21
- v4: regexStringNode(ipv4Matcher, "an IPv4 address"),
22
- v6: regexStringNode(ipv6Matcher, "an IPv6 address")
23
- });
@@ -1,15 +0,0 @@
1
- import type { Module, Submodule } from "../../module.ts";
2
- import type { Branded, To, constrain } from "../ast.ts";
3
- declare namespace string {
4
- type json = constrain<string, Branded<"json">>;
5
- }
6
- export declare const json: stringJson.module;
7
- export declare namespace stringJson {
8
- type module = Module<submodule>;
9
- type submodule = Submodule<$>;
10
- type $ = {
11
- $root: string.json;
12
- parse: (In: string.json) => To<object>;
13
- };
14
- }
15
- export {};
@@ -1,45 +0,0 @@
1
- import { intrinsic, rootNode } from "@ark/schema";
2
- import { submodule } from "../utils.js";
3
- const jsonStringDescription = "a JSON string";
4
- const isParsableJson = (s) => {
5
- try {
6
- JSON.parse(s);
7
- return true;
8
- }
9
- catch {
10
- return false;
11
- }
12
- };
13
- const $root = rootNode({
14
- domain: "string",
15
- predicate: {
16
- meta: jsonStringDescription,
17
- predicate: isParsableJson
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
- }
32
- try {
33
- return JSON.parse(s);
34
- }
35
- catch (e) {
36
- return ctx.error({
37
- code: "predicate",
38
- expected: jsonStringDescription,
39
- problem: `must be ${jsonStringDescription} (${e})`
40
- });
41
- }
42
- },
43
- declaredOut: intrinsic.json
44
- })
45
- });
@@ -1,15 +0,0 @@
1
- import type { Module, Submodule } from "../../module.ts";
2
- import type { Branded, constrain, To } from "../ast.ts";
3
- declare namespace string {
4
- type lowercase = constrain<string, Branded<"lowercase">>;
5
- }
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
- }
15
- export {};
@@ -1,12 +0,0 @@
1
- import { rootNode } from "@ark/schema";
2
- import { submodule } from "../utils.js";
3
- import { regexStringNode } from "./utils.js";
4
- const preformatted = regexStringNode(/^[a-z]*$/, "only lowercase letters");
5
- export const lower = submodule({
6
- $root: rootNode({
7
- in: "string",
8
- morphs: (s) => s.toLowerCase(),
9
- declaredOut: preformatted
10
- }),
11
- preformatted
12
- });
@@ -1,92 +0,0 @@
1
- import type { Module, Submodule } from "../../module.ts";
2
- import type { type } from "../ark.ts";
3
- import type { Branded, constrain, To } from "../ast.ts";
4
- declare namespace string {
5
- type normalized = normalized.NFC;
6
- namespace normalized {
7
- type NFC = constrain<string, Branded<"normalized.NFC">>;
8
- type NFD = constrain<string, Branded<"normalized.NFD">>;
9
- type NFKC = constrain<string, Branded<"normalized.NFKC">>;
10
- type NFKD = constrain<string, Branded<"normalized.NFKD">>;
11
- }
12
- }
13
- export declare const normalizedForms: readonly ["NFC", "NFD", "NFKC", "NFKD"];
14
- export type NormalizedForm = (typeof normalizedForms)[number];
15
- export declare const NFC: Module<{
16
- $root: object;
17
- preformatted: object;
18
- }>;
19
- export declare const NFD: Module<{
20
- $root: object;
21
- preformatted: object;
22
- }>;
23
- export declare const NFKC: Module<{
24
- $root: object;
25
- preformatted: object;
26
- }>;
27
- export declare const NFKD: Module<{
28
- $root: object;
29
- preformatted: object;
30
- }>;
31
- export declare const normalize: Module<{
32
- $root: object;
33
- NFC: Submodule<{
34
- $root: object;
35
- preformatted: object;
36
- }>;
37
- NFD: Submodule<{
38
- $root: object;
39
- preformatted: object;
40
- }>;
41
- NFKC: Submodule<{
42
- $root: object;
43
- preformatted: object;
44
- }>;
45
- NFKD: Submodule<{
46
- $root: object;
47
- preformatted: object;
48
- }>;
49
- }>;
50
- export declare namespace normalize {
51
- type module = Module<submodule>;
52
- type submodule = Submodule<$>;
53
- type $ = {
54
- $root: (In: string) => To<string.normalized.NFC>;
55
- NFC: NFC.submodule;
56
- NFD: NFD.submodule;
57
- NFKC: NFKC.submodule;
58
- NFKD: NFKD.submodule;
59
- };
60
- type shallowResolutions = {
61
- [k in keyof $ as `string.normalize.${k}`]: $[k] extends type.cast<infer t> ? t : $[k];
62
- };
63
- namespace NFC {
64
- type submodule = Submodule<$>;
65
- type $ = {
66
- $root: (In: string) => To<string.normalized.NFC>;
67
- preformatted: string.normalized.NFC;
68
- };
69
- }
70
- namespace NFD {
71
- type submodule = Submodule<$>;
72
- type $ = {
73
- $root: (In: string) => To<string.normalized.NFD>;
74
- preformatted: string.normalized.NFD;
75
- };
76
- }
77
- namespace NFKC {
78
- type submodule = Submodule<$>;
79
- type $ = {
80
- $root: (In: string) => To<string.normalized.NFKC>;
81
- preformatted: string.normalized.NFKC;
82
- };
83
- }
84
- namespace NFKD {
85
- type submodule = Submodule<$>;
86
- type $ = {
87
- $root: (In: string) => To<string.normalized.NFKD>;
88
- preformatted: string.normalized.NFKD;
89
- };
90
- }
91
- }
92
- export {};
@@ -1,43 +0,0 @@
1
- import { rootNode } from "@ark/schema";
2
- import { flatMorph } from "@ark/util";
3
- import { submodule } from "../utils.js";
4
- export const normalizedForms = ["NFC", "NFD", "NFKC", "NFKD"];
5
- const preformattedNodes = flatMorph(normalizedForms, (i, form) => [
6
- form,
7
- rootNode({
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
- rootNode({
16
- in: "string",
17
- morphs: (s) => s.normalize(form),
18
- declaredOut: preformattedNodes[form]
19
- })
20
- ]);
21
- export const NFC = submodule({
22
- $root: normalizeNodes.NFC,
23
- preformatted: preformattedNodes.NFC
24
- });
25
- export const NFD = submodule({
26
- $root: normalizeNodes.NFD,
27
- preformatted: preformattedNodes.NFD
28
- });
29
- export const NFKC = submodule({
30
- $root: normalizeNodes.NFKC,
31
- preformatted: preformattedNodes.NFKC
32
- });
33
- export const NFKD = submodule({
34
- $root: normalizeNodes.NFKD,
35
- preformatted: preformattedNodes.NFKD
36
- });
37
- export const normalize = submodule({
38
- $root: "NFC",
39
- NFC,
40
- NFD,
41
- NFKC,
42
- NFKD
43
- });
@@ -1,15 +0,0 @@
1
- import type { Module, Submodule } from "../../module.ts";
2
- import type { Branded, constrain, To } from "../ast.ts";
3
- declare namespace string {
4
- type numeric = constrain<string, Branded<"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, rootNode } from "@ark/schema";
2
- import { wellFormedNumberMatcher } from "@ark/util";
3
- import { submodule } from "../utils.js";
4
- import { regexStringNode } from "./utils.js";
5
- const $root = regexStringNode(wellFormedNumberMatcher, "a well-formed numeric string");
6
- export const numeric = submodule({
7
- $root,
8
- parse: rootNode({
9
- in: $root,
10
- morphs: (s) => Number.parseFloat(s),
11
- declaredOut: intrinsic.number
12
- })
13
- });
@@ -1,7 +0,0 @@
1
- import type { Branded, constrain } from "../ast.ts";
2
- declare namespace string {
3
- type semver = constrain<string, Branded<"semver">>;
4
- }
5
- export declare const semver: import("@ark/schema").IntersectionNode;
6
- export type semver = string.semver;
7
- export {};
@@ -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,112 +0,0 @@
1
- import { type Constraint, type NodeSchema } from "@ark/schema";
2
- 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
- import { alpha } from "./alpha.ts";
6
- import { alphanumeric } from "./alphanumeric.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: object;
27
- NFC: Submodule<{
28
- $root: object;
29
- preformatted: object;
30
- }>;
31
- NFD: Submodule<{
32
- $root: object;
33
- preformatted: object;
34
- }>;
35
- NFKC: Submodule<{
36
- $root: object;
37
- preformatted: object;
38
- }>;
39
- NFKD: Submodule<{
40
- $root: object;
41
- preformatted: object;
42
- }>;
43
- }>;
44
- json: Submodule<stringJson.submodule>;
45
- $root: object;
46
- integer: Submodule<stringInteger.submodule>;
47
- alpha: object;
48
- alphanumeric: object;
49
- creditCard: object;
50
- date: Submodule<stringDate.submodule>;
51
- digits: object;
52
- email: object;
53
- ip: Submodule<ip.submodule>;
54
- numeric: Submodule<stringNumeric.submodule>;
55
- semver: object;
56
- url: Submodule<url.submodule>;
57
- uuid: Submodule<{
58
- $root: string.matching<string> | "00000000-0000-0000-0000-000000000000" | "ffffffff-ffff-ffff-ffff-ffffffffffff";
59
- v4: object;
60
- v6: object;
61
- v1: object;
62
- v2: object;
63
- v3: object;
64
- v5: object;
65
- v7: object;
66
- v8: object;
67
- }>;
68
- upper: Submodule<upper.submodule>;
69
- lower: Submodule<lower.submodule>;
70
- capitalize: Submodule<capitalize.submodule>;
71
- }>;
72
- export declare namespace string {
73
- type atLeastLength<rule> = constrain<string, AtLeastLength<rule>>;
74
- type moreThanLength<rule> = constrain<string, MoreThanLength<rule>>;
75
- type atMostLength<rule> = constrain<string, AtMostLength<rule>>;
76
- type lessThanLength<rule> = constrain<string, LessThanLength<rule>>;
77
- type exactlyLength<rule> = constrain<string, ExactlyLength<rule>>;
78
- type matching<rule> = constrain<string, Matching<rule>>;
79
- type narrowed = constrain<string, Narrowed>;
80
- type branded<rule> = constrain<string, Branded<rule>>;
81
- type is<constraints extends Constraints> = constrain<string, constraints>;
82
- type parseConstraint<kind extends Constraint.PrimitiveKind, schema extends NodeSchema<kind>> = normalizePrimitiveConstraintRoot<schema> extends infer rule ? kind extends "minLength" ? schema extends {
83
- exclusive: true;
84
- } ? moreThanLength<rule> : atLeastLength<rule> : kind extends "maxLength" ? schema extends {
85
- exclusive: true;
86
- } ? lessThanLength<rule> : atMostLength<rule> : kind extends "pattern" ? matching<rule & string> : kind extends "exactLength" ? exactlyLength<rule> : narrowed : never;
87
- type module = Module<string.submodule>;
88
- type submodule = Submodule<$>;
89
- type $ = {
90
- $root: string;
91
- alpha: alpha;
92
- alphanumeric: alphanumeric;
93
- digits: digits;
94
- numeric: stringNumeric.submodule;
95
- integer: stringInteger.submodule;
96
- creditCard: creditCard;
97
- email: email;
98
- uuid: uuid.submodule;
99
- semver: semver;
100
- ip: ip.submodule;
101
- json: stringJson.submodule;
102
- date: stringDate.submodule;
103
- trim: trim.submodule;
104
- normalize: normalize.submodule;
105
- capitalize: capitalize.submodule;
106
- lower: lower.submodule;
107
- upper: upper.submodule;
108
- };
109
- type shallowResolutions = {
110
- [k in keyof $ as `string.${k}`]: $[k] extends type.cast<infer t> ? t : $[k];
111
- };
112
- }
@@ -1,41 +0,0 @@
1
- import { intrinsic } from "@ark/schema";
2
- import { submodule } from "../utils.js";
3
- import { alpha } from "./alpha.js";
4
- import { alphanumeric } from "./alphanumeric.js";
5
- import { capitalize } from "./capitalize.js";
6
- import { creditCard } from "./creditCard.js";
7
- import { stringDate } from "./date.js";
8
- import { digits } from "./digits.js";
9
- import { email } from "./email.js";
10
- import { integer } from "./integer.js";
11
- import { ip } from "./ip.js";
12
- import { json } from "./json.js";
13
- import { lower } from "./lower.js";
14
- import { normalize } from "./normalize.js";
15
- import { numeric } from "./numeric.js";
16
- import { semver } from "./semver.js";
17
- import { trim } from "./trim.js";
18
- import { upper } from "./upper.js";
19
- import { url } from "./url.js";
20
- import { uuid } from "./uuid.js";
21
- export const string = submodule({
22
- $root: intrinsic.string,
23
- numeric,
24
- integer,
25
- alpha,
26
- alphanumeric,
27
- digits,
28
- semver,
29
- ip,
30
- creditCard,
31
- email,
32
- uuid,
33
- url,
34
- json,
35
- trim,
36
- upper,
37
- lower,
38
- normalize,
39
- capitalize,
40
- date: stringDate
41
- });
@@ -1,15 +0,0 @@
1
- import type { Module, Submodule } from "../../module.ts";
2
- import type { Branded, constrain, To } from "../ast.ts";
3
- declare namespace string {
4
- type trimmed = constrain<string, Branded<"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 { rootNode } from "@ark/schema";
2
- import { submodule } 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 = submodule({
8
- $root: rootNode({
9
- in: "string",
10
- morphs: (s) => s.trim(),
11
- declaredOut: preformatted
12
- }),
13
- preformatted
14
- });