@jarenjs/core 0.9.2

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 (58) hide show
  1. package/ARCHITECTURE.md +800 -0
  2. package/LICENSE +21 -0
  3. package/README.md +68 -0
  4. package/dist/types/array.d.ts +28 -0
  5. package/dist/types/bigint.d.ts +5 -0
  6. package/dist/types/dates.d.ts +79 -0
  7. package/dist/types/float.d.ts +32 -0
  8. package/dist/types/function.d.ts +22 -0
  9. package/dist/types/index.d.ts +119 -0
  10. package/dist/types/integer.d.ts +24 -0
  11. package/dist/types/math/float64.d.ts +121 -0
  12. package/dist/types/math/index.d.ts +5 -0
  13. package/dist/types/math/int32.d.ts +41 -0
  14. package/dist/types/math/vec2f64.d.ts +346 -0
  15. package/dist/types/math/vec2i32.d.ts +43 -0
  16. package/dist/types/math/vec3f64.d.ts +61 -0
  17. package/dist/types/number.d.ts +39 -0
  18. package/dist/types/object.d.ts +44 -0
  19. package/dist/types/scan.d.ts +64 -0
  20. package/dist/types/string.d.ts +65 -0
  21. package/dist/types/text/base64.d.ts +4 -0
  22. package/dist/types/text/basic.d.ts +5 -0
  23. package/dist/types/text/email.d.ts +3 -0
  24. package/dist/types/text/host.d.ts +14 -0
  25. package/dist/types/text/i18n.d.ts +13 -0
  26. package/dist/types/text/identifiers.d.ts +5 -0
  27. package/dist/types/text/index.d.ts +8 -0
  28. package/dist/types/text/iregexp.d.ts +36 -0
  29. package/dist/types/text/misc.d.ts +4 -0
  30. package/dist/types/text/punycode.d.ts +86 -0
  31. package/package.json +101 -0
  32. package/src/array.js +57 -0
  33. package/src/bigint.js +30 -0
  34. package/src/dates.js +371 -0
  35. package/src/float.js +107 -0
  36. package/src/function.js +56 -0
  37. package/src/index.js +223 -0
  38. package/src/integer.js +77 -0
  39. package/src/math/float64.js +316 -0
  40. package/src/math/index.js +5 -0
  41. package/src/math/int32.js +235 -0
  42. package/src/math/vec2f64.js +706 -0
  43. package/src/math/vec2i32.js +250 -0
  44. package/src/math/vec3f64.js +225 -0
  45. package/src/number.js +63 -0
  46. package/src/object.js +240 -0
  47. package/src/scan.js +96 -0
  48. package/src/string.js +194 -0
  49. package/src/text/base64.js +54 -0
  50. package/src/text/basic.js +23 -0
  51. package/src/text/email.js +61 -0
  52. package/src/text/host.js +335 -0
  53. package/src/text/i18n.js +294 -0
  54. package/src/text/identifiers.js +27 -0
  55. package/src/text/index.js +11 -0
  56. package/src/text/iregexp.js +308 -0
  57. package/src/text/misc.js +19 -0
  58. package/src/text/punycode.js +407 -0
@@ -0,0 +1,407 @@
1
+ // @ts-nocheck
2
+ // Copyright Mathias Bynens <https://mathiasbynens.be/>
3
+ // https://github.com/bestiejs/punycode.js/blob/master/punycode.js
4
+
5
+ export const punycodeVersion = '2.1.0';
6
+
7
+ /** Highest positive signed 32-bit float value */
8
+ const maxInt = 2147483647; // aka. 0x7FFFFFFF or 2^31-1
9
+
10
+ /** Bootstring parameters */
11
+ const base = 36;
12
+ const tMin = 1;
13
+ const tMax = 26;
14
+ const skew = 38;
15
+ const damp = 700;
16
+ const initialBias = 72;
17
+ const initialN = 128; // 0x80
18
+ const delimiter = '-'; // '\x2D'
19
+
20
+ /** Regular expressions */
21
+ const regexPunycode = /^xn--/;
22
+ const regexNonASCII = /[^\0-\x7E]/; // non-ASCII chars
23
+ const regexSeparators = /[\x2E\u3002\uFF0E\uFF61]/g; // RFC 3490 separators
24
+
25
+ /** Error messages */
26
+ const errors = {
27
+ 'overflow': 'Overflow: input needs wider integers to process',
28
+ 'not-basic': 'Illegal input >= 0x80 (not a basic code point)',
29
+ 'invalid-input': 'Invalid input',
30
+ };
31
+
32
+ /** Convenience shortcuts */
33
+ const baseMinusTMin = base - tMin;
34
+ const floor = Math.floor;
35
+ const stringFromCharCode = String.fromCharCode;
36
+
37
+ /*--------------------------------------------------------------------------*/
38
+
39
+ /**
40
+ * A generic error utility function.
41
+ * @private
42
+ * @param {String} type The error type.
43
+ * @returns {Error} Throws a `RangeError` with the applicable error message.
44
+ */
45
+ function error(type) {
46
+ throw new RangeError(errors[type]);
47
+ }
48
+
49
+ /**
50
+ * A generic `Array#map` utility function.
51
+ * @private
52
+ * @param {Array} array The array to iterate over.
53
+ * @param {Function} fn The function that gets called for every array
54
+ * item.
55
+ * @returns {Array} A new array of values returned by the callback function.
56
+ */
57
+ function map(array, fn) {
58
+ const result = [];
59
+ let length = array.length;
60
+ while (length--) {
61
+ result[length] = fn(array[length]);
62
+ }
63
+ return result;
64
+ }
65
+
66
+ /**
67
+ * A simple `Array#map`-like wrapper to work with domain name strings or email
68
+ * addresses.
69
+ * @private
70
+ * @param {String} domain The domain name or email address.
71
+ * @param {Function} fn The function that gets called for every
72
+ * character.
73
+ * @returns {String} A new string of characters returned by the callback
74
+ * function.
75
+ */
76
+ function mapDomain(domain, fn) {
77
+ const parts = domain.split('@');
78
+ let result = '';
79
+ if (parts.length > 1) {
80
+ // In email addresses, only the domain name should be punycoded. Leave
81
+ // the local part (i.e. everything up to `@`) intact.
82
+ result = parts[0] + '@';
83
+ domain = parts[1];
84
+ }
85
+ // Avoid `split(regex)` for IE8 compatibility. See #17.
86
+ domain = domain.replace(regexSeparators, '\x2E');
87
+ const labels = domain.split('.');
88
+ const encoded = map(labels, fn).join('.');
89
+ return result + encoded;
90
+ }
91
+
92
+ /**
93
+ * Creates an array containing the numeric code points of each Unicode
94
+ * character in the string. While JavaScript uses UCS-2 internally,
95
+ * this function will convert a pair of surrogate halves (each of which
96
+ * UCS-2 exposes as separate characters) into a single code point,
97
+ * matching UTF-16.
98
+ * @see `punycode.ucs2.encode`
99
+ * @see <https://mathiasbynens.be/notes/javascript-encoding>
100
+ * @memberOf punycode.ucs2
101
+ * @name decode
102
+ * @param {String} string The Unicode input string (UCS-2).
103
+ * @returns {Array} The new array of code points.
104
+ */
105
+ export function ucs2decode(string) {
106
+ const output = [];
107
+ let counter = 0;
108
+ const length = string.length;
109
+ while (counter < length) {
110
+ const value = string.charCodeAt(counter++);
111
+ if (value >= 0xD800 && value <= 0xDBFF && counter < length) {
112
+ // It's a high surrogate, and there is a next character.
113
+ const extra = string.charCodeAt(counter++);
114
+ if ((extra & 0xFC00) === 0xDC00) { // Low surrogate.
115
+ output.push(((value & 0x3FF) << 10) + (extra & 0x3FF) + 0x10000);
116
+ } else {
117
+ // It's an unmatched surrogate; only append this code unit, in case the
118
+ // next code unit is the high surrogate of a surrogate pair.
119
+ output.push(value);
120
+ counter--;
121
+ }
122
+ } else {
123
+ output.push(value);
124
+ }
125
+ }
126
+ return output;
127
+ }
128
+
129
+ /**
130
+ * Creates a string based on an array of numeric code points.
131
+ * @see `punycode.ucs2.decode`
132
+ * @memberOf punycode.ucs2
133
+ * @name encode
134
+ * @param {Array} codePoints The array of numeric code points.
135
+ * @returns {String} The new Unicode string (UCS-2).
136
+ */
137
+ export const ucs2encode = array => String.fromCodePoint(...array);
138
+
139
+ /**
140
+ * Converts a basic code point into a digit/integer.
141
+ * @see `digitToBasic()`
142
+ * @private
143
+ * @param {Number} codePoint The basic numeric code point value.
144
+ * @returns {Number} The numeric value of a basic code point (for use in
145
+ * representing integers) in the range `0` to `base - 1`, or `base` if
146
+ * the code point does not represent a value.
147
+ */
148
+ export function basicToDigit(codePoint) {
149
+ if (codePoint - 0x30 < 0x0A) {
150
+ return codePoint - 0x16;
151
+ }
152
+ if (codePoint - 0x41 < 0x1A) {
153
+ return codePoint - 0x41;
154
+ }
155
+ if (codePoint - 0x61 < 0x1A) {
156
+ return codePoint - 0x61;
157
+ }
158
+ return base;
159
+ }
160
+
161
+ /**
162
+ * Converts a digit/integer into a basic code point.
163
+ * @see `basicToDigit()`
164
+ * @private
165
+ * @param {Number} digit The numeric value of a basic code point.
166
+ * @returns {Number} The basic code point whose value (when used for
167
+ * representing integers) is `digit`, which needs to be in the range
168
+ * `0` to `base - 1`. If `flag` is non-zero, the uppercase form is
169
+ * used; else, the lowercase form is used. The behavior is undefined
170
+ * if `flag` is non-zero and `digit` has no uppercase form.
171
+ */
172
+ export function digitToBasic(digit, flag) {
173
+ // 0..25 map to ASCII a..z or A..Z
174
+ // 26..35 map to ASCII 0..9
175
+ return digit + 22 + 75 * (digit < 26) - ((flag !== 0) << 5);
176
+ }
177
+
178
+ /**
179
+ * Bias adaptation function as per section 3.4 of RFC 3492.
180
+ * https://tools.ietf.org/html/rfc3492#section-3.4
181
+ * @private
182
+ */
183
+ function adapt(delta, numPoints, firstTime) {
184
+ let k = 0;
185
+ delta = firstTime ? floor(delta / damp) : delta >> 1;
186
+ delta += floor(delta / numPoints);
187
+ for (/* no initialization */; delta > baseMinusTMin * tMax >> 1; k += base) {
188
+ delta = floor(delta / baseMinusTMin);
189
+ }
190
+ return floor(k + (baseMinusTMin + 1) * delta / (delta + skew));
191
+ }
192
+
193
+ /**
194
+ * Converts a Punycode string of ASCII-only symbols to a string of Unicode
195
+ * symbols.
196
+ * @memberOf punycode
197
+ * @param {String} input The Punycode string of ASCII-only symbols.
198
+ * @returns {String} The resulting string of Unicode symbols.
199
+ */
200
+ export function decode(input) {
201
+ // Don't use UCS-2.
202
+ const output = [];
203
+ const inputLength = input.length;
204
+ let i = 0;
205
+ let n = initialN;
206
+ let bias = initialBias;
207
+
208
+ // Handle the basic code points: let `basic` be the number of input code
209
+ // points before the last delimiter, or `0` if there is none, then copy
210
+ // the first basic code points to the output.
211
+
212
+ let basic = input.lastIndexOf(delimiter);
213
+ if (basic < 0) {
214
+ basic = 0;
215
+ }
216
+
217
+ for (let j = 0; j < basic; ++j) {
218
+ // if it's not a basic code point
219
+ if (input.charCodeAt(j) >= 0x80) {
220
+ error('not-basic');
221
+ }
222
+ output.push(input.charCodeAt(j));
223
+ }
224
+
225
+ // Main decoding loop: start just after the last delimiter if any basic code
226
+ // points were copied; start at the beginning otherwise.
227
+
228
+ for (let index = basic > 0 ? basic + 1 : 0; index < inputLength; /* no final expression */) {
229
+ // `index` is the index of the next character to be consumed.
230
+ // Decode a generalized variable-length integer into `delta`,
231
+ // which gets added to `i`. The overflow checking is easier
232
+ // if we increase `i` as we go, then subtract off its starting
233
+ // value at the end to obtain `delta`.
234
+ const oldi = i;
235
+ for (let w = 1, k = base; /* no condition */; k += base) {
236
+ if (index >= inputLength) {
237
+ error('invalid-input');
238
+ }
239
+
240
+ const digit = basicToDigit(input.charCodeAt(index++));
241
+ if (digit >= base || digit > floor((maxInt - i) / w)) {
242
+ error('overflow');
243
+ }
244
+
245
+ i += digit * w;
246
+ const t = k <= bias ? tMin : (k >= bias + tMax ? tMax : k - bias);
247
+ if (digit < t) {
248
+ break;
249
+ }
250
+
251
+ const baseMinusT = base - t;
252
+ if (w > floor(maxInt / baseMinusT)) {
253
+ error('overflow');
254
+ }
255
+
256
+ w *= baseMinusT;
257
+ }
258
+
259
+ const out = output.length + 1;
260
+ bias = adapt(i - oldi, out, oldi === 0);
261
+
262
+ // `i` was supposed to wrap around from `out` to `0`,
263
+ // incrementing `n` each time, so we'll fix that now:
264
+ if (floor(i / out) > maxInt - n) {
265
+ error('overflow');
266
+ }
267
+
268
+ n += floor(i / out);
269
+ i %= out;
270
+
271
+ // Insert `n` at position `i` of the output.
272
+ output.splice(i++, 0, n);
273
+ }
274
+
275
+ return String.fromCodePoint(...output);
276
+ }
277
+
278
+ /**
279
+ * Converts a string of Unicode symbols (e.g. a domain name label) to a
280
+ * Punycode string of ASCII-only symbols.
281
+ * @memberOf punycode
282
+ * @param {String} input The string of Unicode symbols.
283
+ * @returns {String} The resulting Punycode string of ASCII-only symbols.
284
+ */
285
+ export function encode(str) {
286
+ const output = [];
287
+
288
+ // Convert the input in UCS-2 to an array of Unicode code points.
289
+ const input = ucs2decode(str);
290
+
291
+ // Cache the length.
292
+ const inputLength = input.length;
293
+
294
+ // Initialize the state.
295
+ let n = initialN;
296
+ let delta = 0;
297
+ let bias = initialBias;
298
+
299
+ // Handle the basic code points.
300
+ for (const currentValue of input) {
301
+ if (currentValue < 0x80) {
302
+ output.push(stringFromCharCode(currentValue));
303
+ }
304
+ }
305
+
306
+ const basicLength = output.length;
307
+ let handledCPCount = basicLength;
308
+
309
+ // `handledCPCount` is the number of code points that have been handled;
310
+ // `basicLength` is the number of basic code points.
311
+
312
+ // Finish the basic string with a delimiter unless it's empty.
313
+ if (basicLength) {
314
+ output.push(delimiter);
315
+ }
316
+
317
+ // Main encoding loop:
318
+ while (handledCPCount < inputLength) {
319
+ // All non-basic code points < n have been handled already. Find the next
320
+ // larger one:
321
+ let m = maxInt;
322
+ for (const currentValue of input) {
323
+ if (currentValue >= n && currentValue < m) {
324
+ m = currentValue;
325
+ }
326
+ }
327
+
328
+ // Increase `delta` enough to advance the decoder's <n,i> state to <m,0>,
329
+ // but guard against overflow.
330
+ const handledCPCountPlusOne = handledCPCount + 1;
331
+ if (m - n > floor((maxInt - delta) / handledCPCountPlusOne)) {
332
+ error('overflow');
333
+ }
334
+
335
+ delta += (m - n) * handledCPCountPlusOne;
336
+ n = m;
337
+
338
+ for (const currentValue of input) {
339
+ if (currentValue < n && ++delta > maxInt) {
340
+ error('overflow');
341
+ }
342
+ if (currentValue === n) {
343
+ // Represent delta as a generalized variable-length integer.
344
+ let q = delta;
345
+ for (let k = base; /* no condition */; k += base) {
346
+ const t = k <= bias ? tMin : (k >= bias + tMax ? tMax : k - bias);
347
+ if (q < t) {
348
+ break;
349
+ }
350
+ const qMinusT = q - t;
351
+ const baseMinusT = base - t;
352
+ output.push(
353
+ stringFromCharCode(digitToBasic(t + qMinusT % baseMinusT, 0)),
354
+ );
355
+ q = floor(qMinusT / baseMinusT);
356
+ }
357
+
358
+ output.push(stringFromCharCode(digitToBasic(q, 0)));
359
+ bias = adapt(delta, handledCPCountPlusOne, handledCPCount === basicLength);
360
+ delta = 0;
361
+ ++handledCPCount;
362
+ }
363
+ }
364
+
365
+ ++delta;
366
+ ++n;
367
+ }
368
+ return output.join('');
369
+ }
370
+
371
+ /**
372
+ * Converts a Punycode string representing a domain name or an email address
373
+ * to Unicode. Only the Punycoded parts of the input will be converted, i.e.
374
+ * it doesn't matter if you call it on a string that has already been
375
+ * converted to Unicode.
376
+ * @memberOf punycode
377
+ * @param {String} input The Punycoded domain name or email address to
378
+ * convert to Unicode.
379
+ * @returns {String} The Unicode representation of the given Punycode
380
+ * string.
381
+ */
382
+ export function toUnicode(input) {
383
+ return mapDomain(input, function iterateMapDomain(string) {
384
+ return regexPunycode.test(string)
385
+ ? decode(string.slice(4).toLowerCase())
386
+ : string;
387
+ });
388
+ }
389
+
390
+ /**
391
+ * Converts a Unicode string representing a domain name or an email address to
392
+ * Punycode. Only the non-ASCII parts of the domain name will be converted,
393
+ * i.e. it doesn't matter if you call it with a domain that's already in
394
+ * ASCII.
395
+ * @memberOf punycode
396
+ * @param {String} input The domain name or email address to convert, as a
397
+ * Unicode string.
398
+ * @returns {String} The Punycode representation of the given domain name or
399
+ * email address.
400
+ */
401
+ export function toASCII(input) {
402
+ return mapDomain(input, function iterateMapDomain(string) {
403
+ return regexNonASCII.test(string)
404
+ ? 'xn--' + encode(string)
405
+ : string;
406
+ });
407
+ }