@depup/typebox 1.3.9-depup.0 → 1.3.14-depup.0

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 (101) hide show
  1. package/README.md +2 -2
  2. package/build/format/date.d.mts +1 -1
  3. package/build/format/date.mjs +1 -1
  4. package/build/format/date_time.d.mts +2 -2
  5. package/build/format/date_time.mjs +3 -3
  6. package/build/format/email.d.mts +1 -1
  7. package/build/format/email.mjs +2 -2
  8. package/build/format/hostname.mjs +2 -10
  9. package/build/format/idn_email.d.mts +1 -1
  10. package/build/format/idn_email.mjs +3 -3
  11. package/build/format/idn_hostname.d.mts +1 -0
  12. package/build/format/idn_hostname.mjs +3 -11
  13. package/build/format/idna/format/bidi.d.mts +3 -0
  14. package/build/format/idna/format/bidi.mjs +98 -0
  15. package/build/format/idna/format/puny.d.mts +3 -0
  16. package/build/format/idna/format/puny.mjs +144 -0
  17. package/build/format/idna/hostname.d.mts +1 -0
  18. package/build/format/idna/hostname.mjs +16 -0
  19. package/build/format/idna/idn-hostname.d.mts +1 -0
  20. package/build/format/idna/idn-hostname.mjs +23 -0
  21. package/build/format/idna/index.d.mts +2 -0
  22. package/build/format/idna/index.mjs +2 -0
  23. package/build/format/idna/label/ascii.d.mts +1 -0
  24. package/build/format/idna/label/ascii.mjs +9 -0
  25. package/build/format/idna/label/puny.d.mts +1 -0
  26. package/build/format/idna/label/puny.mjs +28 -0
  27. package/build/format/idna/label/unicode.d.mts +1 -0
  28. package/build/format/idna/label/unicode.mjs +106 -0
  29. package/build/format/idna/pattern/pattern.d.mts +30 -0
  30. package/build/format/idna/pattern/pattern.mjs +70 -0
  31. package/build/format/ipv4.d.mts +0 -1
  32. package/build/format/ipv4.mjs +2 -32
  33. package/build/format/ipv6.mjs +2 -61
  34. package/build/format/iri.d.mts +2 -2
  35. package/build/format/iri.mjs +26 -8
  36. package/build/format/iri_reference.d.mts +2 -2
  37. package/build/format/iri_reference.mjs +9 -55
  38. package/build/format/regex.d.mts +1 -2
  39. package/build/format/regex.mjs +2 -6
  40. package/build/format/time.d.mts +2 -2
  41. package/build/format/time.mjs +19 -14
  42. package/build/format/uri.d.mts +1 -1
  43. package/build/format/uri.mjs +3 -130
  44. package/build/format/uri_reference.d.mts +1 -1
  45. package/build/format/uri_reference.mjs +2 -3
  46. package/build/format/uri_template.d.mts +2 -3
  47. package/build/format/uri_template.mjs +4 -5
  48. package/build/format/url.d.mts +3 -3
  49. package/build/format/url.mjs +4 -5
  50. package/build/guard/guard.mjs +2 -2
  51. package/build/guard/string.d.mts +2 -2
  52. package/build/guard/string.mjs +7 -7
  53. package/build/schema/engine/_regexp.d.mts +2 -0
  54. package/build/schema/engine/_regexp.mjs +4 -0
  55. package/build/schema/engine/_stack.mjs +1 -1
  56. package/build/schema/engine/additionalProperties.mjs +4 -3
  57. package/build/schema/engine/pattern.mjs +3 -2
  58. package/build/schema/engine/patternProperties.mjs +4 -3
  59. package/build/schema/engine/schema.mjs +13 -4
  60. package/build/schema/resolve/ref.d.mts +1 -0
  61. package/build/schema/resolve/ref.mjs +13 -3
  62. package/build/schema/types/index.d.mts +0 -2
  63. package/build/schema/types/index.mjs +0 -2
  64. package/build/system/memory/clone.mjs +14 -11
  65. package/build/system/memory/discard.mjs +6 -5
  66. package/build/system/settings/settings.d.mts +9 -0
  67. package/build/system/settings/settings.mjs +2 -0
  68. package/build/type/engine/call/distribute_arguments.d.mts +6 -1
  69. package/build/type/engine/call/distribute_arguments.mjs +16 -3
  70. package/build/type/engine/call/instantiate.mjs +34 -4
  71. package/build/type/engine/evaluate/broaden.d.mts +5 -5
  72. package/build/type/engine/evaluate/broaden.mjs +20 -26
  73. package/build/type/engine/evaluate/compare.d.mts +6 -10
  74. package/build/type/engine/evaluate/compare.mjs +9 -13
  75. package/build/type/engine/evaluate/composite.d.mts +7 -4
  76. package/build/type/engine/evaluate/composite.mjs +12 -19
  77. package/build/type/engine/evaluate/distribute.d.mts +4 -20
  78. package/build/type/engine/evaluate/distribute.mjs +8 -20
  79. package/build/type/engine/evaluate/evaluate.d.mts +4 -4
  80. package/build/type/engine/evaluate/evaluate.mjs +11 -8
  81. package/build/type/engine/evaluate/flatten.d.mts +1 -1
  82. package/build/type/engine/evaluate/flatten.mjs +3 -4
  83. package/build/type/engine/evaluate/narrow.d.mts +17 -2
  84. package/build/type/engine/evaluate/narrow.mjs +26 -6
  85. package/build/type/engine/exclude/operation.mjs +3 -4
  86. package/build/type/engine/extract/operation.d.mts +1 -1
  87. package/build/type/engine/extract/operation.mjs +3 -4
  88. package/build/type/engine/priority/priority.d.mts +2 -2
  89. package/build/type/engine/priority/priority.mjs +3 -4
  90. package/build/type/script/parser.mjs +8 -1
  91. package/changes.json +1 -1
  92. package/package.json +3 -3
  93. package/readme.md +66 -62
  94. package/build/format/_idna.d.mts +0 -2
  95. package/build/format/_idna.mjs +0 -246
  96. package/build/format/_puny.d.mts +0 -1
  97. package/build/format/_puny.mjs +0 -77
  98. package/build/schema/types/contentEncoding.d.mts +0 -9
  99. package/build/schema/types/contentEncoding.mjs +0 -13
  100. package/build/schema/types/contentMediaType.d.mts +0 -9
  101. package/build/schema/types/contentMediaType.mjs +0 -13
package/readme.md CHANGED
@@ -111,54 +111,52 @@ type User = Type.Static<typeof User> // type User = {
111
111
 
112
112
  ## Script
113
113
 
114
- [Documentation](https://sinclairzx81.github.io/typebox/#/docs/script/overview) | [Example 1](https://www.typescriptlang.org/play/?target=99&module=7#code/JYWwDg9gTgLgBAFQJ5gKZwGZQiOByGFVAIwgA88AoSgehrgFkIATAVwBtVKBjCAOwDO8AN5wAChCFwAvnAC8iIgDoAytyjAwMABQADSnDiE0cAKoDUUeXGEHDcYMwBccPqxDFLAGjuG+AQxBUFyENPgBzO2k7Y3QAYRwgvngFW3sHZ1d3TygfdJhUMhgQmDDwvPt-VhgAC2gXc0somKJxSRSbXwyXNw9vLphgGE4SsorDUmYkUeAI8bgq2vqzC1yu3hAkmAEXBM3UZIBtAF1m3QBKajo4ACVUDE5uQf5KCSElMGw0WGBUASVHK92h8vpZBn8lINhlw3jAQRBvuD-os6lB4Yjfv9AbD0WDMUoUdBcT8IQEgkD3p8EXiIRstliCiB-lSMRCCkUKXCWTT-nSDtsAYzmaCScjqqjiUiAcxOZL8XzkgzUEy5RDCWjuaKlGSuLR6ABJPgYSwHbhcDCsPhPYD8OCfP787SQIQuZBoVQwfyDbgAHliEAwbSEAD5zp1DM64YCI8CoZw7JGCeKidG7cD1drAlwY+8FdtDgAGY6QwowBPAvMCQvFjOpxOV6tJpZonWUaRAA) | [Example 2](https://www.typescriptlang.org/play/?target=99&module=7#code/JYWwDg9gTgLgBAFQJ5gKZwGZQiOByGFVAIwgA88AoSgehrgFkIATAVwBtVKBjCAOwDO8AKoDUUOAF5ERAHQB5YgCtU3GAAoA3pThxgzAFwy0sgHKsQxceoCUAGh1w+AQxCojyEwGUYUYHwBzW0oAXxsefiE4AGEcNz54aU9UBWVVDW1dfQ85c0tre0cYVDIYHO9ffyDC3WdWGAALaCNRcVDw3kF4AAUIKKS5RRU1LUds4xS8qyhbB10YYBhOcpSfP0DZx1JmJBXZNarN2vqmqBaxKDm4XhB4mAE9gEEoKGckdVjb1ATwsOo6OAAJVQGE4amA-EovSEsjA2DQsGAqAEsn0UL6MFh8PEC2RsgWSy40MxcIgCNxKLqjWgWLJOKRKLRxNp5IZsippxZ9LxLjc6JhpNZeJud0ZxRAKMF3JRxVK-JJ2MRwri33uqPFksVFPZJxpUqVjOY8q5BtkItVYtQEpN2o5eq1bN5XFo9AAknwMOJvtwuBhWHxwfw4HDkar1JAhHsfM4FtwADyENAQDBwYkAPhscEywYxqKNugjmIJnEchZ11KgedLubtlad1Zh5oSAgA2gAGAC6+JKMAbmKb93bXdrVYLuYHrc75c59ZCQA) | [Challenge](test/typescript/readme.md)
114
+ [Documentation](https://sinclairzx81.github.io/typebox/#/docs/script/overview) | [Example 1](https://www.typescriptlang.org/play/?target=99&module=7#code/JYWwDg9gTgLgBAFQJ5gKZwGZQiOByGFVAIwgA88AoSgehrgFkBDGAC0YgBMBXAG1WoBjCADsAzvGZs4AXkREAdAGVBUYGBgAKAAaU4cQmjgA1VIJjQALLLgBvOGQBccEdxDFUUADRwkz1+6ePgBe-m4e3nAA7mGBUHAAvnoGRCZmFlAAzDb2Ti7hQb6xESHFnonJhuim5tAATDkOZZF++XEV2gCU1HRwAOJQTGCswIJiHDz8QqIS-YPDo+NyyGjKqupaUqw+uvpVabCoZDnJ+pBiwDDAos41GZZepy7QIEy8t+nQmY-6+twAbh9alA6skkntUn1UDhUDAoEgTr84P9PFdBKgxB9DmQANoAXR+v2AIk4owxzXxYMqqSknmAb0RvyY7mAqBEMCB90J+lJGAw3DEqE5Vm5cDEaEEfCYUGFUEsVIhRgYGPYclsTwA5tCQLD4c4oTC4UhRa8YHS3s5aWo3lSutR9sqxKr5KslDAWKMADxVCAYOZDEZjHF4R2sPB4gB8+l6DpVjKRCcTSeTKZTvX0WsNerscAUecSotTReLJfTcFN5veObzCgqJfrDeTvQSQA) | [Example 2](https://www.typescriptlang.org/play/?target=99&module=7#code/JYWwDg9gTgLgBAFQJ5gKZwGZQiOByGFVAIwgA88AoSgehrgFkBDGAC0YgBMBXAG1WoBjCADsAzvABqqQTGgAWOAF5ERAHQB5YgCsZMABQBvOGQBcqtGoBy3EMVRR9ASgA0cJOeSWbdh87cAXp7qPvaOrnAA7sHetmHOcAC+TpTC4lJ60ADMyhaomjp6RiYx+aF+ER551nEVgaU1vuFJKWkScNKy0ABMuV75WrqyxWbV5eFuVf2N8U4t1HRwAOJQTGCswIJiHDz8QqLt0rCoZH3qg0WGlHBwkGLAMMCi5p1yUPIu13Ai0CBMvC9MlAsp8btwAG6ArpQbqUZKpA7wJaoHCoGBQJBnSwXYZXG7ghyPQSoMQNACCUFWSH0RxgJ1cX2AIk4mxJ5MpTGp03GzhS8La8GYdKgwH+WIGhVxXyYdmAqBEMChbw+XxZGAw3DEqCVClBcDEaEEfCYUB170+-MRjBJ7BU0xxBjxcAA5iiQGiMeZkaj0Ug9X9haKAYwWA4g3CUpRCGhrWJbdUAMowFibAA80ZRGFjrAAfDd8wXC4sM9nck7CxXK1XqzX84sbq6fZ64MY1G2knra13u1363AA2H-uZW+3El8exPJ3X6IkgA)
115
115
 
116
- TypeBox includes a runtime TypeScript engine that can transform TypeScript definitions to JSON Schema. The engine is fully type-safe and supports many programmable constructs including Conditional, Mapped, Indexed, Generics, Distributive Generics, and more.
116
+ TypeBox includes a micro TypeScript engine that can transform TypeScript definitions to JSON Schema. The engine is fully type-safe and supports many programmable constructs including Conditional, Mapped, Indexed, Generics, Distributive Generics, and more.
117
117
 
118
118
  ### Example
119
119
 
120
- Syntax highlighting is available via the [Visual Studio Marketplace](https://marketplace.visualstudio.com/items?itemName=sinclairzx81.typebox-script)
120
+ Syntax highlighting is available via the [Visual Studio Marketplace](https://marketplace.visualstudio.com/items?itemName=sinclairzx81.typebox-script).
121
121
 
122
122
  ```typescript
123
- // Module
124
- const { Post } = Type.Script(`
125
- type User = {
126
- id: number,
127
- name: string
123
+ import Type from 'typebox'
124
+
125
+ // Math Module
126
+
127
+ const Math = Type.Script(`
128
+ type Vector4 = { x: number, y: number, z: number, w: number }
129
+ type Vector3 = { x: number, y: number, z: number }
130
+ type Vector2 = { x: number, y: number }
131
+ `)
132
+
133
+ // Graphics Module
134
+
135
+ const Graphics = Type.Script(Math, `
136
+ type Vertex = {
137
+ position: Vector4,
138
+ normal: Vector3,
139
+ uv: Vector2
128
140
  }
129
- type Comment = {
130
- id: number,
131
- text: string,
132
- author: User
141
+ type Geometry = {
142
+ vertices: Vertex[],
143
+ indices: number[]
133
144
  }
134
- type Post = {
135
- id: number,
136
- title: string,
137
- body: string,
138
- author: User,
139
- comments: Comment[]
145
+ type Material = {
146
+ ambient: Vector4,
147
+ diffuse: Vector4,
148
+ specular: Vector4
149
+ }
150
+ type Mesh = {
151
+ geometry: Geometry,
152
+ material: Material
140
153
  }
141
154
  `)
142
155
 
143
- // Reflection
144
- Post.properties.id
145
- Post.properties.title
146
- Post.properties.author.properties.id
147
- Post.properties.author.properties.name
148
- Post.properties.comments.items.properties.text
149
- Post.properties.comments.items.properties.author.properties.id
150
- Post.properties.comments.items.properties.author.properties.name
151
-
152
- // Inference
153
- function present(post: Type.Static<typeof Post>) {
154
- post.id
155
- post.title
156
- post.author.id
157
- post.author.name
158
- post.comments[0].text
159
- post.comments[0].author.id
160
- post.comments[0].author.name
161
- }
156
+ type Mesh = Type.Static<typeof Graphics['Mesh']> // type Mesh = {
157
+ // geometry: { ... },
158
+ // material: { ... }
159
+ // }
162
160
  ```
163
161
 
164
162
  <a name="Schema"></a>
@@ -177,18 +175,21 @@ import Schema from 'typebox/schema'
177
175
 
178
176
  ### Compile
179
177
 
180
- The compiler accepts JSON Schema and returns Validator instances.
178
+ The compiler accepts either TypeBox types or native JSON Schema.
181
179
 
182
180
  ```typescript
183
- const Vector = Schema.Compile(Type.Object({ // const Vector: Validator<TObject<{
181
+
182
+ // Type
183
+
184
+ const VectorA = Schema.Compile(Type.Object({ // const VectorA: Validator<TObject<{
184
185
  x: Type.Number(), // x: TNumber
185
186
  y: Type.Number(), // y: TNumber
186
187
  z: Type.Number() // z: TNumber
187
188
  })) // }>>
188
- ```
189
- With JSON Schema
190
- ```typescript
191
- const Vector = Schema.Compile({ // const Vector: Validator<{
189
+
190
+ // Schema
191
+
192
+ const VectorB = Schema.Compile({ // const VectorB: Validator<{
192
193
  type: 'object', // type: "object";
193
194
  required: ['x', 'y', 'z'], // required: ["x", "y", "z"];
194
195
  properties: { // properties: { ... };
@@ -201,35 +202,36 @@ const Vector = Schema.Compile({ // const Vector: Validator<{
201
202
 
202
203
  ### Validate
203
204
 
204
- Validator instances provide functions to Check and Parse values.
205
+ Compiled validator instances provide functions to Check and Parse values.
205
206
 
206
207
  ```typescript
208
+
209
+ // Compile
210
+
207
211
  const Vector = Schema.Compile(Type.Script(`{
208
212
  x: number
209
213
  y: number
210
214
  z: number
211
215
  }`))
212
216
 
213
- const valid = Vector.Check({ // const valid: boolean
214
- x: 1,
215
- y: 0,
216
- z: 0
217
- })
218
-
219
- const value = Vector.Parse({ // const value: {
220
- x: 1, // x: number
221
- y: 0, // y: number
222
- z: 0 // z: number
223
- }) // }
224
- ```
217
+ // Check
225
218
 
219
+ const valid = Vector.Check({ x: 1, y: 0, z: 0 }) // const valid: boolean
226
220
 
221
+ // Parse
222
+
223
+ const result = Vector.Parse({ x: 1, y: 0, z: 0 }) // const result: {
224
+ // x: number
225
+ // y: number
226
+ // z: number
227
+ // }
228
+ ```
227
229
 
228
230
  ### Coverage
229
231
 
230
- The following table shows specification coverage implemented by TypeBox.
232
+ [JSON Schema Test Suite](https://github.com/json-schema-org/JSON-Schema-Test-Suite) | [JSON Schema Compliance Suite](https://github.com/sinclairzx81/json-schema-compliance-suite)
231
233
 
232
- [JSON Schema Test Suite](https://github.com/json-schema-org/JSON-Schema-Test-Suite)
234
+ TypeBox supports all major JSON Schema draft versions and tracks compliance against the official JSON Schema Test Suite. It also maintains a separate JavaScript compliance suite to track ecosystem adoption as JSON Schema moves toward the Version 1 candidate. The following table shows TypeBox specification coverage.
233
235
 
234
236
  | Spec | 3 | 4 | 6 | 7 | 2019-09 | 2020-12 | v1 |
235
237
  |:-----|:--|:--|:--|:--|:--|:--|:--|
@@ -279,10 +281,13 @@ The following table shows specification coverage implemented by TypeBox.
279
281
  | unevaluatedProperties | - | - | - | - | ✅ | ✅ | 128/129 |
280
282
  | uniqueItems | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
281
283
 
282
-
283
284
  ### Performance
284
285
 
285
- The following table shows compile performance for various JSON Schema structures using AJV8 as a basis for comparison.
286
+ TypeBox tracks comparative performance against AJV8 as the de facto JSON Schema performance standard. For broader comparative benchmarks, refer to the community maintained projects below.
287
+
288
+ [Runtime Benchmarks](https://moltar.github.io/typescript-runtime-type-benchmarks/) | [Schema Benchmarks](https://schemabenchmarks.dev/)
289
+
290
+ The following table shows compilation performance for various JSON Schema structures. These benchmarks measure the time required to JIT compile schematics, with faster compilation resulting in faster application startup.
286
291
 
287
292
  ```python
288
293
  ┌──────────────────────┬─────────────┬─────────────┐
@@ -314,8 +319,7 @@ The following table shows compile performance for various JSON Schema structures
314
319
  └──────────────────────┴─────────────┴─────────────┘
315
320
  ```
316
321
 
317
-
318
- The following tables shows validation performance for various JSON Schema structures using AJV8 as a basis for comparison.
322
+ The following tables shows validation performance for various JSON Schema structures. These benchmarks measure overall validation throughput for JIT compiled schematics.
319
323
 
320
324
  ```python
321
325
  ┌──────────────────────┬──────────────┬──────────────┐
@@ -1,2 +0,0 @@
1
- export declare function IsIdnLabel(value: string): boolean;
2
- export declare function IsLabel(value: string): boolean;
@@ -1,246 +0,0 @@
1
- import { Unreachable } from '../system/unreachable/index.mjs';
2
- import * as Puny from './_puny.mjs';
3
- // ------------------------------------------------------------------
4
- // Unicode General Category Helper (RFC 5892)
5
- // ------------------------------------------------------------------
6
- function IsNonspacingMark(cp) {
7
- return /\p{Mn}/u.test(String.fromCodePoint(cp));
8
- }
9
- function IsSpacingCombiningMark(cp) {
10
- return /\p{Mc}/u.test(String.fromCodePoint(cp));
11
- }
12
- function IsEnclosingMark(cp) {
13
- return /\p{Me}/u.test(String.fromCodePoint(cp));
14
- }
15
- function IsCombiningMark(cp) {
16
- return IsNonspacingMark(cp) || IsSpacingCombiningMark(cp) || IsEnclosingMark(cp);
17
- }
18
- // ------------------------------------------------------------------
19
- // RFC 5892 §2.6 DISALLOWED exceptions
20
- //
21
- // https://tools.ietf.org/html/rfc5892#section-2.6
22
- // ------------------------------------------------------------------
23
- const RFC5892_DISALLOWED = new Set([
24
- 0x0640, // ARABIC TATWEEL
25
- 0x07fa, // NKO LAJANYALAN
26
- 0x302e, // HANGUL SINGLE DOT TONE MARK
27
- 0x302f, // HANGUL DOUBLE DOT TONE MARK
28
- 0x3031, // VERTICAL KANA REPEAT MARK
29
- 0x3032, // VERTICAL KANA REPEAT WITH VOICED ITERATION MARK
30
- 0x3033, // VERTICAL KANA REPEAT MARK UPPER HALF
31
- 0x3034, // VERTICAL KANA REPEAT WITH VOICED ITERATION MARK UPPER HALF
32
- 0x3035, // VERTICAL KANA REPEAT MARK LOWER HALF
33
- 0x303b // VERTICAL IDEOGRAPHIC ITERATION MARK
34
- ]);
35
- // ------------------------------------------------------------------
36
- // A set of Virama (halant) code points used to validate CONTEXTJ
37
- // rules (RFC 5892 Appendix A.1). These characters allow a subsequent
38
- // Zero Width Non-Joiner (U+200C) or Zero Width Joiner (U+200D) to
39
- // be valid in a label.
40
- // ------------------------------------------------------------------
41
- const VIRAMA_CPS = new Set([
42
- 0x094d,
43
- 0x09cd,
44
- 0x0a4d,
45
- 0x0acd,
46
- 0x0b4d,
47
- 0x0bcd,
48
- 0x0c4d,
49
- 0x0ccd,
50
- 0x0d3b,
51
- 0x0d3c,
52
- 0x0d4d,
53
- 0x0dca,
54
- 0x1b44,
55
- 0x1baa,
56
- 0x1bab,
57
- 0xa9c0,
58
- 0x11046,
59
- 0x1107f,
60
- 0x110b9,
61
- 0x11133,
62
- 0x11134,
63
- 0x111c0,
64
- 0x11235,
65
- 0x1134d,
66
- 0x11442,
67
- 0x114c2,
68
- 0x115bf,
69
- 0x1163f,
70
- 0x116b6,
71
- 0x11c3f,
72
- 0x11d44,
73
- 0x11d45
74
- ]);
75
- // ------------------------------------------------------------------
76
- // Guards for CONTEXTO rules (RFC 5892 Appendix A)
77
- // ------------------------------------------------------------------
78
- function IsGreek(cp) {
79
- return /\p{Script=Greek}/u.test(String.fromCodePoint(cp));
80
- }
81
- function IsHebrew(cp) {
82
- return /\p{Script=Hebrew}/u.test(String.fromCodePoint(cp));
83
- }
84
- function IsHiragana(cp) {
85
- return /\p{Script=Hiragana}/u.test(String.fromCodePoint(cp));
86
- }
87
- function IsKatakana(cp) {
88
- return /\p{Script=Katakana}/u.test(String.fromCodePoint(cp));
89
- }
90
- function IsHan(cp) {
91
- return /\p{Script=Han}/u.test(String.fromCodePoint(cp));
92
- }
93
- function IsArabicIndicDigit(cp) {
94
- return cp >= 0x0660 && cp <= 0x0669;
95
- }
96
- function IsExtendedArabicIndicDigit(cp) {
97
- return cp >= 0x06f0 && cp <= 0x06f9;
98
- }
99
- function IsVirama(cp) {
100
- return VIRAMA_CPS.has(cp);
101
- }
102
- // ------------------------------------------------------------------
103
- // IsUnicodeLabel
104
- // ------------------------------------------------------------------
105
- function IsUnicodeLabel(value) {
106
- // deno-coverage-ignore-start - unable to reach via format guards
107
- if (value.length === 0)
108
- return Unreachable(); // false
109
- // deno-coverage-ignore-stop
110
- // Use spread to handle surrogate pairs and provide O(1) neighbor access
111
- const cps = [...value].map((c) => c.codePointAt(0));
112
- const len = cps.length;
113
- // RFC 5891 §4.2.3.2: Hyphen rules
114
- if (cps[0] === 0x2d || cps[len - 1] === 0x2d)
115
- return false;
116
- if (len >= 4 && cps[2] === 0x2d && cps[3] === 0x2d)
117
- return false;
118
- // RFC 5891 §4.2.3.2 - Must not begin with a combining mark
119
- if (IsCombiningMark(cps[0]))
120
- return false;
121
- let hasJapanese = false;
122
- let hasArabicIndic = false;
123
- let hasExtendedArabicIndic = false;
124
- for (let i = 0; i < len; i++) {
125
- const cp = cps[i];
126
- // 1. DISALLOWED exceptions
127
- if (RFC5892_DISALLOWED.has(cp))
128
- return false;
129
- // 2. Collect Flags
130
- if (IsHiragana(cp) || IsKatakana(cp) || IsHan(cp))
131
- hasJapanese = true;
132
- if (IsArabicIndicDigit(cp))
133
- hasArabicIndic = true;
134
- if (IsExtendedArabicIndicDigit(cp))
135
- hasExtendedArabicIndic = true;
136
- // 3. CONTEXTO / CONTEXTJ Neighbor Rules
137
- const prev = cps[i - 1], next = cps[i + 1];
138
- switch (cp) {
139
- case 0x00b7:
140
- if (prev !== 0x006c || next !== 0x006c)
141
- return false;
142
- break; // MIDDLE DOT (Catalan)
143
- case 0x0375:
144
- if (next === undefined || !IsGreek(next))
145
- return false;
146
- break; // Greek KERAIA
147
- case 0x05f3:
148
- case 0x05f4:
149
- if (prev === undefined || !IsHebrew(prev))
150
- return false;
151
- break; // Hebrew GERESH
152
- case 0x200c: // ZWNJ - RFC 5892 Appendix A.1
153
- // Note: Full validation requires a Unicode joining type table. We reject
154
- // only when preceded by ASCII (U+0000-U+007F), which can never satisfy
155
- // the Virama or cursive-joining rules.
156
- if (prev === undefined || (prev < 0x0080 && !IsVirama(prev)))
157
- return false;
158
- break;
159
- case 0x200d: // ZWJ - RFC 5892 Appendix A.2
160
- if (prev === undefined || !IsVirama(prev))
161
- return false;
162
- break;
163
- case 0x30fb: /* Checked at end via hasJapanese */
164
- break; // KATAKANA MIDDLE DOT
165
- }
166
- }
167
- // 4. Global Context Validations (Post-loop)
168
- // RFC 5892 Appendix A.7 - Katakana Middle Dot requirement
169
- if (value.includes('\u30fb') && !hasJapanese)
170
- return false;
171
- // RFC 5892 Appendix A.8/A.9 - Mixing Arabic Digits
172
- if (hasArabicIndic && hasExtendedArabicIndic)
173
- return false;
174
- return true;
175
- }
176
- // ------------------------------------------------------------------
177
- // IsAsciiLabel
178
- // ------------------------------------------------------------------
179
- function IsAsciiLabel(value) {
180
- // Must not start or end with a hyphen
181
- if (value.charCodeAt(0) === 45 || value.charCodeAt(value.length - 1) === 45)
182
- return false;
183
- // RFC 5891 §4.2.3.1 : "--" at positions 3-4 is reserved for A-labels only
184
- if (value.length >= 4 && value.charCodeAt(2) === 45 && value.charCodeAt(3) === 45)
185
- return false;
186
- // All characters must be alphanumeric or hyphen
187
- for (let i = 0; i < value.length; i++) {
188
- const ch = value.charCodeAt(i);
189
- if (!((ch >= 97 && ch <= 122) || // a-z
190
- (ch >= 65 && ch <= 90) || // A-Z
191
- (ch >= 48 && ch <= 57) || // 0-9
192
- ch === 45 // '-'
193
- ))
194
- return false;
195
- }
196
- return true;
197
- }
198
- // ------------------------------------------------------------------
199
- // IsPunyLabel
200
- // ------------------------------------------------------------------
201
- function IsPuny(value) {
202
- return value.toLowerCase().startsWith('xn--');
203
- }
204
- function IsPunyLabel(value) {
205
- try {
206
- const payload = value.slice(4).toLowerCase();
207
- // 1. Structural Validation (RFC 3492 syntax)
208
- //
209
- // If the payload contains a hyphen, it MUST be a delimiter separating basic
210
- // ASCII characters from the variable-length integers. A payload consisting
211
- // of ONLY a hyphen or starting with multiple hyphens without basic ASCII
212
- // characters (like "-9uc") is fundamentally malformed.
213
- //
214
- const lastHyphen = payload.lastIndexOf('-');
215
- if (lastHyphen === 0) {
216
- // Catches "-9uc" right here because the delimiter is at index 0, meaning 0
217
- // basic ASCII characters preceded it, which is non-canonical.
218
- return false;
219
- }
220
- // 2. Decode the payload
221
- const decoded = Puny.Decode(payload);
222
- if (!decoded)
223
- return false;
224
- // 3. Validate the output rules against RFC 5892
225
- return IsUnicodeLabel(decoded);
226
- }
227
- catch {
228
- return false;
229
- }
230
- }
231
- // ------------------------------------------------------------------
232
- // IsIdnLabel
233
- // ------------------------------------------------------------------
234
- export function IsIdnLabel(value) {
235
- if (value.length === 0 || value.length > 63)
236
- return false;
237
- return IsPuny(value) ? IsPunyLabel(value) : IsUnicodeLabel(value);
238
- }
239
- // ------------------------------------------------------------------
240
- // IsLabel
241
- // ------------------------------------------------------------------
242
- export function IsLabel(value) {
243
- if (value.length === 0 || value.length > 63)
244
- return false;
245
- return IsPuny(value) ? IsPunyLabel(value) : IsAsciiLabel(value);
246
- }
@@ -1 +0,0 @@
1
- export declare function Decode(value: string): string;
@@ -1,77 +0,0 @@
1
- import { Unreachable } from '../system/unreachable/index.mjs';
2
- // ------------------------------------------------------------------
3
- // PunyCode (RFC 3492)
4
- // ------------------------------------------------------------------
5
- const PUNYCODE_BASE = 36;
6
- const PUNYCODE_TMIN = 1;
7
- const PUNYCODE_TMAX = 26;
8
- const PUNYCODE_SKEW = 38;
9
- const PUNYCODE_DAMP = 700;
10
- const PUNYCODE_INITIAL_BIAS = 72;
11
- const PUNYCODE_INITIAL_N = 128;
12
- // ------------------------------------------------------------------
13
- // Adapt
14
- // ------------------------------------------------------------------
15
- function Adapt(delta, numPoints, firstTime) {
16
- delta = firstTime ? Math.floor(delta / PUNYCODE_DAMP) : delta >> 1;
17
- delta += Math.floor(delta / numPoints);
18
- let k = 0;
19
- while (delta > (((PUNYCODE_BASE - PUNYCODE_TMIN) * PUNYCODE_TMAX) >> 1)) {
20
- delta = Math.floor(delta / (PUNYCODE_BASE - PUNYCODE_TMIN));
21
- k += PUNYCODE_BASE;
22
- }
23
- return k + Math.floor(((PUNYCODE_BASE - PUNYCODE_TMIN + 1) * delta) / (delta + PUNYCODE_SKEW));
24
- }
25
- // ------------------------------------------------------------------
26
- // Decode
27
- // ------------------------------------------------------------------
28
- export function Decode(value) {
29
- const output = [];
30
- let n = PUNYCODE_INITIAL_N;
31
- let i = 0;
32
- let bias = PUNYCODE_INITIAL_BIAS;
33
- const delimIdx = value.lastIndexOf('-');
34
- if (delimIdx > 0) {
35
- for (let j = 0; j < delimIdx; j++) {
36
- const cp = value.charCodeAt(j);
37
- if (cp >= 128)
38
- throw new Error('Invalid punycode: non-basic before delimiter');
39
- output.push(cp);
40
- }
41
- }
42
- let inIdx = delimIdx < 0 ? 0 : delimIdx + 1;
43
- while (inIdx < value.length) {
44
- const oldi = i;
45
- let w = 1;
46
- let k = PUNYCODE_BASE;
47
- while (true) {
48
- if (inIdx >= value.length)
49
- throw new Error('Invalid punycode: unexpected end of input');
50
- const ch = value.charCodeAt(inIdx++);
51
- let digit;
52
- if (ch >= 0x61 && ch <= 0x7a)
53
- digit = ch - 0x61; // a-z => 0-25
54
- else if (ch >= 0x30 && ch <= 0x39)
55
- digit = ch - 0x30 + 26; // 0-9 => 26-35
56
- // deno-coverage-ignore-start - _idna.ts maps input to lowercase, so we can't reach here
57
- else if (ch >= 0x41 && ch <= 0x5a)
58
- Unreachable(); // digit = ch - 0x41 // A-Z => 0-25
59
- // deno-coverage-ignore-stop
60
- else
61
- throw new Error('Invalid punycode: bad digit character');
62
- i += digit * w;
63
- const t = k <= bias ? PUNYCODE_TMIN : k >= bias + PUNYCODE_TMAX ? PUNYCODE_TMAX : k - bias;
64
- if (digit < t)
65
- break;
66
- w *= PUNYCODE_BASE - t;
67
- k += PUNYCODE_BASE;
68
- }
69
- const outLen = output.length + 1;
70
- bias = Adapt(i - oldi, outLen, oldi === 0);
71
- n += Math.floor(i / outLen);
72
- i %= outLen;
73
- output.splice(i, 0, n);
74
- i++;
75
- }
76
- return globalThis.String.fromCodePoint(...output);
77
- }
@@ -1,9 +0,0 @@
1
- import { type XSchemaObject } from './schema.mjs';
2
- export interface XContentEncoding<ContentEncoding extends string = string> {
3
- contentEncoding: ContentEncoding;
4
- }
5
- /**
6
- * Returns true if the schema contains a valid contentEncoding property
7
- * @specification Json Schema 7
8
- */
9
- export declare function IsContentEncoding(schema: XSchemaObject): schema is XContentEncoding;
@@ -1,13 +0,0 @@
1
- // deno-fmt-ignore-file
2
- import { Guard } from '../../guard/index.mjs';
3
- // ------------------------------------------------------------------
4
- // Guard
5
- // ------------------------------------------------------------------
6
- /**
7
- * Returns true if the schema contains a valid contentEncoding property
8
- * @specification Json Schema 7
9
- */
10
- export function IsContentEncoding(schema) {
11
- return Guard.HasPropertyKey(schema, 'contentEncoding')
12
- && Guard.IsString(schema.contentEncoding);
13
- }
@@ -1,9 +0,0 @@
1
- import { type XSchemaObject } from './schema.mjs';
2
- export interface XContentMediaType<ContentMediaType extends string = string> {
3
- contentMediaType: ContentMediaType;
4
- }
5
- /**
6
- * Returns true if the schema contains a valid contentMediaType property
7
- * @specification Json Schema 7
8
- */
9
- export declare function IsContentMediaType(schema: XSchemaObject): schema is XContentMediaType;
@@ -1,13 +0,0 @@
1
- // deno-fmt-ignore-file
2
- import { Guard } from '../../guard/index.mjs';
3
- // ------------------------------------------------------------------
4
- // Guard
5
- // ------------------------------------------------------------------
6
- /**
7
- * Returns true if the schema contains a valid contentMediaType property
8
- * @specification Json Schema 7
9
- */
10
- export function IsContentMediaType(schema) {
11
- return Guard.HasPropertyKey(schema, 'contentMediaType')
12
- && Guard.IsString(schema.contentMediaType);
13
- }