arktype 2.0.0-rc.9 → 2.0.1

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 (128) hide show
  1. package/out/attributes.d.ts +94 -0
  2. package/out/attributes.js +3 -0
  3. package/out/generic.d.ts +13 -13
  4. package/out/index.d.ts +3 -1
  5. package/out/index.js +2 -1
  6. package/out/keywords/{constructors/Array.d.ts → Array.d.ts} +2 -2
  7. package/out/keywords/{constructors/Array.js → Array.js} +2 -2
  8. package/out/keywords/{constructors/FormData.d.ts → FormData.d.ts} +2 -2
  9. package/out/keywords/{constructors/FormData.js → FormData.js} +2 -2
  10. package/out/keywords/{constructors/TypedArray.d.ts → TypedArray.d.ts} +1 -1
  11. package/out/keywords/{constructors/TypedArray.js → TypedArray.js} +2 -2
  12. package/out/keywords/builtins.js +2 -2
  13. package/out/keywords/{constructors/constructors.d.ts → constructors.d.ts} +1 -1
  14. package/out/keywords/{constructors/constructors.js → constructors.js} +2 -2
  15. package/out/keywords/keywords.d.ts +14 -13
  16. package/out/keywords/keywords.js +9 -5
  17. package/out/keywords/number.d.ts +23 -0
  18. package/out/keywords/{number/epoch.js → number.js} +22 -1
  19. package/out/keywords/string.d.ts +327 -0
  20. package/out/keywords/string.js +398 -0
  21. package/out/keywords/ts.d.ts +31 -4
  22. package/out/keywords/ts.js +21 -8
  23. package/out/methods/array.d.ts +6 -7
  24. package/out/methods/base.d.ts +461 -35
  25. package/out/methods/date.d.ts +5 -6
  26. package/out/methods/instantiate.d.ts +4 -4
  27. package/out/methods/morph.d.ts +6 -6
  28. package/out/methods/number.d.ts +8 -9
  29. package/out/methods/object.d.ts +39 -15
  30. package/out/methods/string.d.ts +9 -10
  31. package/out/parser/ast/bounds.d.ts +1 -1
  32. package/out/parser/ast/default.d.ts +2 -2
  33. package/out/parser/ast/generic.d.ts +17 -0
  34. package/out/parser/ast/infer.d.ts +8 -22
  35. package/out/parser/ast/validate.d.ts +13 -9
  36. package/out/parser/ast/validate.js +3 -1
  37. package/out/parser/definition.d.ts +17 -8
  38. package/out/parser/definition.js +38 -3
  39. package/out/parser/objectLiteral.d.ts +39 -39
  40. package/out/parser/objectLiteral.js +83 -67
  41. package/out/parser/property.d.ts +36 -0
  42. package/out/parser/property.js +16 -0
  43. package/out/parser/reduce/dynamic.d.ts +8 -9
  44. package/out/parser/reduce/shared.d.ts +1 -1
  45. package/out/parser/reduce/static.d.ts +4 -4
  46. package/out/parser/shift/operand/date.d.ts +1 -1
  47. package/out/parser/shift/operand/enclosed.d.ts +3 -4
  48. package/out/parser/shift/operand/operand.d.ts +3 -3
  49. package/out/parser/shift/operand/operand.js +2 -2
  50. package/out/parser/shift/operand/unenclosed.d.ts +13 -5
  51. package/out/parser/shift/operand/unenclosed.js +5 -4
  52. package/out/parser/shift/operator/bounds.d.ts +5 -5
  53. package/out/parser/shift/operator/bounds.js +5 -4
  54. package/out/parser/shift/operator/brand.d.ts +6 -0
  55. package/out/parser/shift/operator/brand.js +5 -0
  56. package/out/parser/shift/operator/default.d.ts +3 -2
  57. package/out/parser/shift/operator/default.js +4 -1
  58. package/out/parser/shift/operator/divisor.d.ts +2 -2
  59. package/out/parser/shift/operator/operator.d.ts +4 -3
  60. package/out/parser/shift/operator/operator.js +7 -5
  61. package/out/parser/shift/scanner.d.ts +31 -55
  62. package/out/parser/shift/scanner.js +24 -83
  63. package/out/parser/string.d.ts +5 -4
  64. package/out/parser/string.js +18 -1
  65. package/out/parser/tupleExpressions.d.ts +48 -0
  66. package/out/parser/tupleExpressions.js +67 -0
  67. package/out/parser/tupleLiteral.d.ts +95 -0
  68. package/out/parser/tupleLiteral.js +122 -0
  69. package/out/scope.d.ts +17 -12
  70. package/out/scope.js +25 -41
  71. package/out/type.d.ts +63 -5
  72. package/out/type.js +3 -2
  73. package/package.json +8 -8
  74. package/out/keywords/constructors/Date.d.ts +0 -31
  75. package/out/keywords/inference.d.ts +0 -220
  76. package/out/keywords/inference.js +0 -2
  77. package/out/keywords/number/epoch.d.ts +0 -9
  78. package/out/keywords/number/integer.d.ts +0 -3
  79. package/out/keywords/number/integer.js +0 -5
  80. package/out/keywords/number/number.d.ts +0 -53
  81. package/out/keywords/number/number.js +0 -21
  82. package/out/keywords/string/alpha.d.ts +0 -7
  83. package/out/keywords/string/alpha.js +0 -2
  84. package/out/keywords/string/alphanumeric.d.ts +0 -7
  85. package/out/keywords/string/alphanumeric.js +0 -2
  86. package/out/keywords/string/capitalize.d.ts +0 -15
  87. package/out/keywords/string/capitalize.js +0 -12
  88. package/out/keywords/string/creditCard.d.ts +0 -8
  89. package/out/keywords/string/creditCard.js +0 -37
  90. package/out/keywords/string/date.d.ts +0 -55
  91. package/out/keywords/string/date.js +0 -98
  92. package/out/keywords/string/digits.d.ts +0 -7
  93. package/out/keywords/string/digits.js +0 -2
  94. package/out/keywords/string/email.d.ts +0 -7
  95. package/out/keywords/string/email.js +0 -4
  96. package/out/keywords/string/integer.d.ts +0 -16
  97. package/out/keywords/string/integer.js +0 -16
  98. package/out/keywords/string/ip.d.ts +0 -20
  99. package/out/keywords/string/ip.js +0 -23
  100. package/out/keywords/string/json.d.ts +0 -16
  101. package/out/keywords/string/json.js +0 -53
  102. package/out/keywords/string/lower.d.ts +0 -15
  103. package/out/keywords/string/lower.js +0 -12
  104. package/out/keywords/string/normalize.d.ts +0 -88
  105. package/out/keywords/string/normalize.js +0 -43
  106. package/out/keywords/string/numeric.d.ts +0 -15
  107. package/out/keywords/string/numeric.js +0 -13
  108. package/out/keywords/string/semver.d.ts +0 -7
  109. package/out/keywords/string/semver.js +0 -4
  110. package/out/keywords/string/string.d.ts +0 -108
  111. package/out/keywords/string/string.js +0 -41
  112. package/out/keywords/string/trim.d.ts +0 -15
  113. package/out/keywords/string/trim.js +0 -14
  114. package/out/keywords/string/upper.d.ts +0 -15
  115. package/out/keywords/string/upper.js +0 -12
  116. package/out/keywords/string/url.d.ts +0 -15
  117. package/out/keywords/string/url.js +0 -37
  118. package/out/keywords/string/utils.d.ts +0 -2
  119. package/out/keywords/string/utils.js +0 -10
  120. package/out/keywords/string/uuid.d.ts +0 -42
  121. package/out/keywords/string/uuid.js +0 -19
  122. package/out/keywords/utils.d.ts +0 -1
  123. package/out/keywords/utils.js +0 -2
  124. package/out/methods/validator.d.ts +0 -11
  125. package/out/methods/validator.js +0 -1
  126. package/out/parser/tuple.d.ts +0 -143
  127. package/out/parser/tuple.js +0 -164
  128. /package/out/{keywords/constructors/Date.js → parser/ast/generic.js} +0 -0
@@ -1,53 +0,0 @@
1
- import type { Module, Submodule } from "../../module.ts";
2
- import type { Branded, constrain, constraint, Constraints, Narrowed, Optional } from "../inference.ts";
3
- import { epoch } from "./epoch.ts";
4
- import { integer } from "./integer.ts";
5
- export declare const number: number.module;
6
- export type AtLeast<rule> = {
7
- atLeast: constraint<rule>;
8
- };
9
- export type AtMost<rule> = {
10
- atMost: constraint<rule>;
11
- };
12
- export type MoreThan<rule> = {
13
- moreThan: constraint<rule>;
14
- };
15
- export type LessThan<rule> = {
16
- lessThan: constraint<rule>;
17
- };
18
- export type DivisibleBy<rule> = {
19
- divisibleBy: constraint<rule>;
20
- };
21
- export declare namespace number {
22
- type atLeast<rule> = constrain<number, AtLeast<rule>>;
23
- type moreThan<rule> = constrain<number, MoreThan<rule>>;
24
- type atMost<rule> = constrain<number, AtMost<rule>>;
25
- type lessThan<rule> = constrain<number, LessThan<rule>>;
26
- type divisibleBy<rule> = constrain<number, DivisibleBy<rule>>;
27
- type narrowed = constrain<number, Narrowed>;
28
- type optional = constrain<number, Optional>;
29
- type branded<rule> = constrain<number, Branded<rule>>;
30
- type NaN = branded<"NaN">;
31
- type Infinity = branded<"Infinity">;
32
- type NegativeInfinity = branded<"NegativeInfinity">;
33
- type safe = branded<"safe">;
34
- type is<constraints extends Constraints> = constrain<number, constraints>;
35
- type minSchemaToConstraint<schema, rule> = schema extends {
36
- exclusive: true;
37
- } ? MoreThan<rule> : AtLeast<rule>;
38
- type maxSchemaToConstraint<schema, rule> = schema extends {
39
- exclusive: true;
40
- } ? LessThan<rule> : AtMost<rule>;
41
- type withConstraint<constraint> = constraint extends MoreThan<infer rule> ? moreThan<rule> : constraint extends AtLeast<infer rule> ? atLeast<rule> : constraint extends AtMost<infer rule> ? atMost<rule> : constraint extends LessThan<infer rule> ? lessThan<rule> : constraint extends DivisibleBy<infer rule> ? divisibleBy<rule> : constraint extends Optional ? optional : constraint extends Narrowed ? narrowed : never;
42
- type module = Module<submodule>;
43
- type submodule = Submodule<$>;
44
- type $ = {
45
- root: number;
46
- epoch: epoch;
47
- integer: integer;
48
- safe: safe;
49
- NaN: NaN;
50
- Infinity: Infinity;
51
- NegativeInfinity: NegativeInfinity;
52
- };
53
- }
@@ -1,21 +0,0 @@
1
- import { intrinsic, rootSchema } from "@ark/schema";
2
- import { arkModule } from "../utils.js";
3
- import { epoch } from "./epoch.js";
4
- import { integer } from "./integer.js";
5
- export const number = arkModule({
6
- root: intrinsic.number,
7
- integer,
8
- epoch,
9
- safe: rootSchema({
10
- domain: "number",
11
- min: Number.MIN_SAFE_INTEGER,
12
- max: Number.MAX_SAFE_INTEGER,
13
- predicate: {
14
- predicate: n => !Number.isNaN(n),
15
- meta: "a safe number"
16
- }
17
- }),
18
- NaN: ["===", Number.NaN],
19
- Infinity: ["===", Number.POSITIVE_INFINITY],
20
- NegativeInfinity: ["===", Number.NEGATIVE_INFINITY]
21
- });
@@ -1,7 +0,0 @@
1
- import type { Branded, constrain } from "../inference.ts";
2
- declare namespace string {
3
- type alpha = constrain<string, Branded<"alpha">>;
4
- }
5
- export declare const alpha: import("@ark/schema").IntersectionNode;
6
- export type alpha = string.alpha;
7
- export {};
@@ -1,2 +0,0 @@
1
- import { regexStringNode } from "./utils.js";
2
- export const alpha = regexStringNode(/^[A-Za-z]*$/, "only letters");
@@ -1,7 +0,0 @@
1
- import type { Branded, constrain } from "../inference.ts";
2
- declare namespace string {
3
- type alphanumeric = constrain<string, Branded<"alphanumeric">>;
4
- }
5
- export declare const alphanumeric: import("@ark/schema").IntersectionNode;
6
- export type alphanumeric = string.alphanumeric;
7
- export {};
@@ -1,2 +0,0 @@
1
- import { regexStringNode } from "./utils.js";
2
- export const alphanumeric = regexStringNode(/^[A-Za-z\d]*$/, "only letters and digits 0-9");
@@ -1,15 +0,0 @@
1
- import type { Module, Submodule } from "../../module.ts";
2
- import type { Branded, constrain, To } from "../inference.ts";
3
- declare namespace string {
4
- type capitalized = constrain<string, Branded<"capitalized">>;
5
- }
6
- export declare const capitalize: capitalize.module;
7
- export declare namespace capitalize {
8
- type module = Module<submodule>;
9
- type submodule = Submodule<$>;
10
- type $ = {
11
- root: (In: string) => To<string.capitalized>;
12
- preformatted: string.capitalized;
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].*$/, "capitalized");
5
- export const capitalize = arkModule({
6
- root: rootSchema({
7
- in: "string",
8
- morphs: (s) => s.charAt(0).toUpperCase() + s.slice(1),
9
- declaredOut: preformatted
10
- }),
11
- preformatted
12
- });
@@ -1,8 +0,0 @@
1
- import type { Branded, constrain } from "../inference.ts";
2
- export declare const isLuhnValid: (creditCardInput: string) => boolean;
3
- declare namespace string {
4
- type creditCard = constrain<string, Branded<"creditCard">>;
5
- }
6
- export declare const creditCard: import("@ark/schema").BaseRoot<import("@ark/schema").InternalRootDeclaration>;
7
- export type creditCard = string.creditCard;
8
- export {};
@@ -1,37 +0,0 @@
1
- import { rootSchema } from "@ark/schema";
2
- // https://github.com/validatorjs/validator.js/blob/master/src/lib/isLuhnNumber.js
3
- export const isLuhnValid = (creditCardInput) => {
4
- const sanitized = creditCardInput.replace(/[- ]+/g, "");
5
- let sum = 0;
6
- let digit;
7
- let tmpNum;
8
- let shouldDouble = false;
9
- for (let i = sanitized.length - 1; i >= 0; i--) {
10
- digit = sanitized.substring(i, i + 1);
11
- tmpNum = Number.parseInt(digit, 10);
12
- if (shouldDouble) {
13
- tmpNum *= 2;
14
- if (tmpNum >= 10)
15
- sum += (tmpNum % 10) + 1;
16
- else
17
- sum += tmpNum;
18
- }
19
- else
20
- sum += tmpNum;
21
- shouldDouble = !shouldDouble;
22
- }
23
- return !!(sum % 10 === 0 ? sanitized : false);
24
- };
25
- // https://github.com/validatorjs/validator.js/blob/master/src/lib/isCreditCard.js
26
- const creditCardMatcher = /^(?:4[0-9]{12}(?:[0-9]{3,6})?|5[1-5][0-9]{14}|(222[1-9]|22[3-9][0-9]|2[3-6][0-9]{2}|27[01][0-9]|2720)[0-9]{12}|6(?:011|5[0-9][0-9])[0-9]{12,15}|3[47][0-9]{13}|3(?:0[0-5]|[68][0-9])[0-9]{11}|(?:2131|1800|35\d{3})\d{11}|6[27][0-9]{14}|^(81[0-9]{14,17}))$/;
27
- export const creditCard = rootSchema({
28
- domain: "string",
29
- pattern: {
30
- meta: "a credit card number",
31
- rule: creditCardMatcher.source
32
- },
33
- predicate: {
34
- meta: "a credit card number",
35
- predicate: isLuhnValid
36
- }
37
- });
@@ -1,55 +0,0 @@
1
- import type { Module, Submodule } from "../../module.ts";
2
- import type { Branded, To, constrain } from "../inference.ts";
3
- type DayDelimiter = "." | "/" | "-";
4
- type DayPart = DayPatterns[PartKey];
5
- type PartKey = keyof DayPatterns;
6
- type DayPatterns = {
7
- y: "yy" | "yyyy";
8
- m: "mm" | "m";
9
- d: "dd" | "d";
10
- };
11
- type fragment<part extends DayPart, delimiter extends DayDelimiter> = `${delimiter}${part}` | "";
12
- export type DayPattern<delimiter extends DayDelimiter = DayDelimiter> = delimiter extends unknown ? {
13
- [k1 in keyof DayPatterns]: {
14
- [k2 in Exclude<keyof DayPatterns, k1>]: `${DayPatterns[k1]}${fragment<DayPatterns[k2], delimiter>}${fragment<DayPatterns[Exclude<keyof DayPatterns, k1 | k2>], delimiter>}`;
15
- }[Exclude<keyof DayPatterns, k1>];
16
- }[keyof DayPatterns] : never;
17
- export type DateFormat = "iso" | DayPattern;
18
- export type DateOptions = {
19
- format?: DateFormat;
20
- };
21
- export declare const iso8601Matcher: RegExp;
22
- export declare const tryParseDatePattern: (data: string, opts?: DateOptions) => Date | string;
23
- declare namespace string {
24
- type date = constrain<string, Branded<"date">>;
25
- namespace date {
26
- type epoch = constrain<string, Branded<"date.epoch">>;
27
- type iso = constrain<string, Branded<"date.iso">>;
28
- }
29
- }
30
- export declare const stringDate: stringDate.module;
31
- export declare namespace stringDate {
32
- type module = Module<stringDate.submodule>;
33
- type submodule = Submodule<$>;
34
- type $ = {
35
- root: string.date;
36
- parse: (In: string.date) => To<Date>;
37
- iso: iso.submodule;
38
- epoch: epoch.submodule;
39
- };
40
- namespace iso {
41
- type submodule = Submodule<$>;
42
- type $ = {
43
- root: string.date.iso;
44
- parse: (In: string.date.iso) => To<Date>;
45
- };
46
- }
47
- namespace epoch {
48
- type submodule = Submodule<$>;
49
- type $ = {
50
- root: string.date.epoch;
51
- parse: (In: string.date.epoch) => To<Date>;
52
- };
53
- }
54
- }
55
- export {};
@@ -1,98 +0,0 @@
1
- import { ArkErrors, intrinsic, rootSchema } from "@ark/schema";
2
- import { number } from "../number/number.js";
3
- import { arkModule } 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 = rootSchema({
44
- domain: "string",
45
- predicate: {
46
- meta: "a parsable date",
47
- predicate: isParsableDate
48
- }
49
- }).assertHasKind("intersection");
50
- const epochRoot = 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 = arkModule({
67
- root: epochRoot,
68
- parse: rootSchema({
69
- in: epochRoot,
70
- morphs: (s) => new Date(s),
71
- declaredOut: intrinsic.Date
72
- })
73
- });
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
- morphs: (s) => new Date(s),
80
- declaredOut: intrinsic.Date
81
- })
82
- });
83
- export const stringDate = arkModule({
84
- root: parsableDate,
85
- parse: rootSchema({
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 "../inference.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 "../inference.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 "../inference.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, rootSchema } from "@ark/schema";
2
- import { wellFormedIntegerMatcher } from "@ark/util";
3
- import { arkModule } from "../utils.js";
4
- import { regexStringNode } from "./utils.js";
5
- const root = regexStringNode(wellFormedIntegerMatcher, "a well-formed integer string");
6
- export const integer = arkModule({
7
- root,
8
- parse: rootSchema({
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 "../inference.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 { arkModule } 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
- // Adjusted to incorporate unmerged fix in https://github.com/validatorjs/validator.js/pull/2083
5
- const ipv4Segment = "(?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])";
6
- const ipv4Address = `(${ipv4Segment}[.]){3}${ipv4Segment}`;
7
- const ipv4Matcher = new RegExp(`^${ipv4Address}$`);
8
- const ipv6Segment = "(?:[0-9a-fA-F]{1,4})";
9
- const ipv6Matcher = new RegExp("^(" +
10
- `(?:${ipv6Segment}:){7}(?:${ipv6Segment}|:)|` +
11
- `(?:${ipv6Segment}:){6}(?:${ipv4Address}|:${ipv6Segment}|:)|` +
12
- `(?:${ipv6Segment}:){5}(?::${ipv4Address}|(:${ipv6Segment}){1,2}|:)|` +
13
- `(?:${ipv6Segment}:){4}(?:(:${ipv6Segment}){0,1}:${ipv4Address}|(:${ipv6Segment}){1,3}|:)|` +
14
- `(?:${ipv6Segment}:){3}(?:(:${ipv6Segment}){0,2}:${ipv4Address}|(:${ipv6Segment}){1,4}|:)|` +
15
- `(?:${ipv6Segment}:){2}(?:(:${ipv6Segment}){0,3}:${ipv4Address}|(:${ipv6Segment}){1,5}|:)|` +
16
- `(?:${ipv6Segment}:){1}(?:(:${ipv6Segment}){0,4}:${ipv4Address}|(:${ipv6Segment}){1,6}|:)|` +
17
- `(?::((?::${ipv6Segment}){0,5}:${ipv4Address}|(?::${ipv6Segment}){1,7}|:))` +
18
- ")(%[0-9a-zA-Z.]{1,})?$");
19
- export const ip = arkModule({
20
- root: ["v4 | v6", "@", "an IP address"],
21
- v4: regexStringNode(ipv4Matcher, "an IPv4 address"),
22
- v6: regexStringNode(ipv6Matcher, "an IPv6 address")
23
- });
@@ -1,16 +0,0 @@
1
- import type { Module, Submodule } from "../../module.ts";
2
- import type { Branded, To, constrain } from "../inference.ts";
3
- declare namespace string {
4
- type json = constrain<string, Branded<"json">>;
5
- }
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
- }
16
- export {};
@@ -1,53 +0,0 @@
1
- import { intrinsic, rootSchema } from "@ark/schema";
2
- import { arkModule } from "../utils.js";
3
- const jsonStringDescription = "a JSON string";
4
- export const writeJsonSyntaxErrorProblem = (error) => {
5
- if (!(error instanceof SyntaxError))
6
- throw error;
7
- return `must be ${jsonStringDescription} (${error})`;
8
- };
9
- const root = rootSchema({
10
- domain: "string",
11
- predicate: {
12
- meta: jsonStringDescription,
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
- }
26
- }
27
- });
28
- export const json = arkModule({
29
- root,
30
- parse: rootSchema({
31
- in: "string",
32
- morphs: (s, ctx) => {
33
- if (s.length === 0) {
34
- return ctx.error({
35
- code: "predicate",
36
- expected: jsonStringDescription,
37
- actual: "empty"
38
- });
39
- }
40
- try {
41
- return JSON.parse(s);
42
- }
43
- catch (e) {
44
- return ctx.error({
45
- code: "predicate",
46
- expected: jsonStringDescription,
47
- problem: writeJsonSyntaxErrorProblem(e)
48
- });
49
- }
50
- },
51
- declaredOut: intrinsic.json
52
- })
53
- });
@@ -1,15 +0,0 @@
1
- import type { Module, Submodule } from "../../module.ts";
2
- import type { Branded, constrain, To } from "../inference.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 { rootSchema } from "@ark/schema";
2
- import { arkModule } from "../utils.js";
3
- import { regexStringNode } from "./utils.js";
4
- const preformatted = regexStringNode(/^[a-z]*$/, "only lowercase letters");
5
- export const lower = arkModule({
6
- root: rootSchema({
7
- in: "string",
8
- morphs: (s) => s.toLowerCase(),
9
- declaredOut: preformatted
10
- }),
11
- preformatted
12
- });
@@ -1,88 +0,0 @@
1
- import type { Module, Submodule } from "../../module.ts";
2
- import type { Branded, constrain, To } from "../inference.ts";
3
- declare namespace string {
4
- type normalized = normalized.NFC;
5
- namespace normalized {
6
- type NFC = constrain<string, Branded<"normalized.NFC">>;
7
- type NFD = constrain<string, Branded<"normalized.NFD">>;
8
- type NFKC = constrain<string, Branded<"normalized.NFKC">>;
9
- type NFKD = constrain<string, Branded<"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 {};