typebox 1.3.18 → 1.3.20

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.
@@ -14,14 +14,16 @@ function IsLabel(value) {
14
14
  // ------------------------------------------------------------------
15
15
  // NormalizeHostname
16
16
  //
17
- // Normalizes a hostname for label validation. Normalizes for NFC
18
- // such that equivalent codepoint sequences can be uniformly
19
- // compared. It also removes codepoints that IDNA mapping ignores,
20
- // and converts full stop variants to ASCII '.' so the hostname can
21
- // be split into labels.
17
+ // Normalizes a hostname for label validation. Maps fullwidth
18
+ // codepoints to their ASCII equivalent (e.g. 'a' U+FF41 maps to
19
+ // 'a'), then normalizes for NFC such that equivalent codepoint
20
+ // sequences can be uniformly compared. It also removes codepoints
21
+ // that IDNA mapping ignores, and converts full stop variants to
22
+ // ASCII '.' so the hostname can be split into labels.
22
23
  // ------------------------------------------------------------------
23
24
  function NormalizeHostname(value) {
24
25
  return value
26
+ .replace(/[\uff01-\uff5e]/g, (char) => String.fromCharCode(char.charCodeAt(0) - 0xfee0)) // RE_FULLWIDTH_MAPPING
25
27
  .normalize('NFC')
26
28
  .replace(/[\u00ad\u034f\u180b-\u180d\u200b\ufe00-\ufe0f\u{e0100}-\u{e01ef}]/gu, '') // RE_IGNORED_MAPPING
27
29
  .replace(/[\u002E\u3002\uFF0E\uFF61]/g, '.'); // RE_FULL_STOP_MAPPING
@@ -106,15 +106,13 @@ export function IsMaxLength(value, length) {
106
106
  // Array
107
107
  // --------------------------------------------------------------------------
108
108
  export function Every(value, offset, params, expression) {
109
- return G.IsEqual(offset, '0')
110
- ? `${value}.every((${params[0]}, ${params[1]}) => ${expression})`
111
- : `((value, callback) => { for(let index = ${offset}; index < value.length; index++) if (!callback(value[index], index)) return false; return true })(${value}, (${params[0]}, ${params[1]}) => ${expression})`;
109
+ return G.IsEqual(offset, '0') ? `${value}.every((${params[0]}, ${params[1]}) => (${expression}))` : `${value}.every((${params[0]}, ${params[1]}) => (${params[1]} < ${offset}) || (${expression}))`;
112
110
  }
113
111
  export function Some(value, params, expression) {
114
112
  return `${value}.some((${params[0]}, ${params[1]}) => ${expression})`;
115
113
  }
116
114
  export function SomeAll(value, params, expression) {
117
- return `((value, callback) => { let result = false; for(let index = 0; index < value.length; index++) if (callback(value[index], index)) result = true; return result })(${value}, (${params[0]}, ${params[1]}) => ${expression})`;
115
+ return `((value) => { let result = false; value.forEach((${params[0]}, ${params[1]}) => { if (${expression}) result = true }); return result })(${value})`;
118
116
  }
119
117
  export function Counted(value, params, expression) {
120
118
  return `${value}.reduce((result, ${params[0]}, ${params[1]}) => (${expression}) ? ++result : result, 0)`;
@@ -140,36 +140,24 @@ export function IsMinLength(value, length) {
140
140
  // --------------------------------------------------------------------------
141
141
  /** Returns true if every element from offset satisfies the callback, short-circuiting on the first failure */
142
142
  export function Every(value, offset, callback) {
143
- for (let index = offset; index < value.length; index++) {
144
- if (!callback(value[index], index))
145
- return false;
146
- }
147
- return true;
143
+ return value.every((item, index) => (index < offset) || callback(item, index));
148
144
  }
149
145
  /** Returns true if every element from offset satisfies the callback, using exhaustive enumeration */
150
146
  export function EveryAll(value, offset, callback) {
151
147
  let result = true;
152
- for (let index = offset; index < value.length; index++) {
153
- if (!callback(value[index], index))
154
- result = false;
155
- }
148
+ value.forEach((item, index) => { if ((index >= offset) && !callback(item, index))
149
+ result = false; });
156
150
  return result;
157
151
  }
158
152
  /** Returns true if some element satisfies the callback, short-circuiting on the first success */
159
153
  export function Some(value, callback) {
160
- for (let index = 0; index < value.length; index++) {
161
- if (callback(value[index], index))
162
- return true;
163
- }
164
- return false;
154
+ return value.some((value, index) => callback(value, index));
165
155
  }
166
156
  /** Returns true if some element satisfies the callback, using exhaustive enumeration */
167
157
  export function SomeAll(value, callback) {
168
158
  let result = false;
169
- for (let index = 0; index < value.length; index++) {
170
- if (callback(value[index], index))
171
- result = true;
172
- }
159
+ value.forEach((item, index) => { if (callback(item, index))
160
+ result = true; });
173
161
  return result;
174
162
  }
175
163
  /** Returns the count of elements that satisfy the callback */
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "typebox",
3
3
  "description": "Json Schema Type Builder with Static Type Resolution for TypeScript",
4
- "version": "1.3.18",
4
+ "version": "1.3.20",
5
5
  "keywords": [
6
6
  "typescript",
7
7
  "jsonschema"