cizgile 0.3.0 → 1.0.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.
package/dist/uri.mjs CHANGED
@@ -1,4 +1,5 @@
1
1
  import { _ as isUnreserved, a as readHexByte, c as isDigit, d as isPchar, f as isQueryChar, g as isSubDelim, h as isSegmentNzNc, i as encodeUtf8, l as isGenDelim, m as isScheme, n as percentDecode, o as readUtf8, p as isReserved, r as percentEncode, s as isAlpha, t as normalizePercentEncoding, u as isHexDigit, v as resolveEncodeSet } from "./shared/percent-DG-pZhJI.mjs";
2
+ import { i as punycodeEncode, n as domainToUnicode, r as punycodeDecode, t as domainToAscii } from "./shared/punycode-MAFJqHdd.mjs";
2
3
 
3
4
  //#region src/uri/parse.ts
4
5
  const URI_REFERENCE = /^(?:([A-Za-z][A-Za-z0-9+.-]*):)?(?:\/\/([^/?#]*))?([^?#]*)(?:\?([^#]*))?(?:#(.*))?$/s;
@@ -239,185 +240,6 @@ function normalizePath(path, options = {}) {
239
240
  return out;
240
241
  }
241
242
 
242
- //#endregion
243
- //#region src/uri/punycode.ts
244
- const BASE = 36;
245
- const T_MIN = 1;
246
- const T_MAX = 26;
247
- const SKEW = 38;
248
- const DAMP = 700;
249
- const INITIAL_BIAS = 72;
250
- const INITIAL_N = 128;
251
- const DELIMITER = "-";
252
- const PREFIX = "xn--";
253
- const MAX_INT = 2147483647;
254
- const LABEL_SEPARATORS = /[.\u3002\uFF0E\uFF61]/;
255
- function adapt(delta, numPoints, firstTime) {
256
- let d = firstTime ? Math.floor(delta / DAMP) : delta >> 1;
257
- d += Math.floor(d / numPoints);
258
- let k = 0;
259
- while (d > 455) {
260
- d = Math.floor(d / 35);
261
- k += BASE;
262
- }
263
- return k + Math.floor(36 * d / (d + SKEW));
264
- }
265
- function digit(value) {
266
- return String.fromCodePoint(value + (value < 26 ? 97 : 22));
267
- }
268
- function digitValue(cp) {
269
- if (cp >= 48 && cp <= 57) return cp - 22;
270
- if (cp >= 65 && cp <= 90) return cp - 65;
271
- if (cp >= 97 && cp <= 122) return cp - 97;
272
- return -1;
273
- }
274
- /** RFC 3492 Punycode encoding of one label, without the `xn--` prefix. */
275
- function punycodeEncode(input) {
276
- const points = Array.from(input, (ch) => ch.codePointAt(0) ?? 0);
277
- let out = "";
278
- for (const cp of points) if (cp < 128) out += String.fromCodePoint(cp);
279
- const basicCount = out.length;
280
- let handled = basicCount;
281
- if (basicCount > 0) out += DELIMITER;
282
- let n = INITIAL_N;
283
- let delta = 0;
284
- let bias = INITIAL_BIAS;
285
- while (handled < points.length) {
286
- let m = 1114112;
287
- for (const cp of points) if (cp >= n && cp < m) m = cp;
288
- delta += (m - n) * (handled + 1);
289
- n = m;
290
- for (const cp of points) {
291
- if (cp < n) delta += 1;
292
- if (cp === n) {
293
- let q = delta;
294
- for (let k = BASE;; k += BASE) {
295
- const t = k <= bias ? T_MIN : k >= bias + T_MAX ? T_MAX : k - bias;
296
- if (q < t) break;
297
- out += digit(t + (q - t) % (BASE - t));
298
- q = Math.floor((q - t) / (BASE - t));
299
- }
300
- out += digit(q);
301
- bias = adapt(delta, handled + 1, handled === basicCount);
302
- delta = 0;
303
- handled += 1;
304
- }
305
- }
306
- delta += 1;
307
- n += 1;
308
- }
309
- return out;
310
- }
311
- /**
312
- * RFC 3492 Punycode decoding of one label, without the `xn--` prefix.
313
- * @throws {RangeError} on malformed input.
314
- */
315
- function punycodeDecode(input) {
316
- const output = [];
317
- const last = input.lastIndexOf(DELIMITER);
318
- const basicEnd = last > 0 ? last : 0;
319
- for (let i = 0; i < basicEnd; i++) {
320
- const cp = input.codePointAt(i) ?? 0;
321
- if (cp >= 128) throw new RangeError("punycodeDecode: invalid basic code point");
322
- output.push(cp);
323
- }
324
- let n = INITIAL_N;
325
- let bias = INITIAL_BIAS;
326
- let i = 0;
327
- let index = basicEnd > 0 ? basicEnd + 1 : 0;
328
- while (index < input.length) {
329
- const oldI = i;
330
- let w = 1;
331
- for (let k = BASE;; k += BASE) {
332
- if (index >= input.length) throw new RangeError("punycodeDecode: truncated input");
333
- const d = digitValue(input.codePointAt(index) ?? 0);
334
- index += 1;
335
- if (d < 0) throw new RangeError("punycodeDecode: invalid digit");
336
- i += d * w;
337
- if (i > MAX_INT) throw new RangeError("punycodeDecode: overflow");
338
- const t = k <= bias ? T_MIN : k >= bias + T_MAX ? T_MAX : k - bias;
339
- if (d < t) break;
340
- w *= BASE - t;
341
- }
342
- const count = output.length + 1;
343
- bias = adapt(i - oldI, count, oldI === 0);
344
- n += Math.floor(i / count);
345
- i %= count;
346
- if (n > 1114111) throw new RangeError("punycodeDecode: code point out of range");
347
- output.splice(i, 0, n);
348
- i += 1;
349
- }
350
- return String.fromCodePoint(...output);
351
- }
352
- function isAsciiLabel(label) {
353
- for (const ch of label) if ((ch.codePointAt(0) ?? 0) >= 128) return false;
354
- return true;
355
- }
356
- function lowercaseCodePoints(text) {
357
- let out = "";
358
- for (const ch of text) out += ch.toLowerCase();
359
- return out;
360
- }
361
- function mapLabel(label) {
362
- return lowercaseCodePoints(label.replace(/\p{Cf}/gu, "").normalize("NFKC")).normalize("NFC");
363
- }
364
- function invalid(fn, label, reason) {
365
- return /* @__PURE__ */ new RangeError(`${fn}: label ${JSON.stringify(label)} ${reason}`);
366
- }
367
- function decodeLabel(fn, label) {
368
- let decoded;
369
- try {
370
- decoded = punycodeDecode(label.slice(4));
371
- } catch {
372
- throw invalid(fn, label, "is not valid Punycode");
373
- }
374
- if (decoded === "" || isAsciiLabel(decoded) || /[\p{C}\p{Z}]/u.test(decoded) || mapLabel(decoded) !== decoded || PREFIX + punycodeEncode(decoded) !== label) throw invalid(fn, label, "is not a valid A-label");
375
- return decoded;
376
- }
377
- function checkAsciiLabel(fn, label, original) {
378
- if (label.length > 63) throw invalid(fn, original, "exceeds 63 octets");
379
- if (!/^[a-z0-9-]*$/.test(label)) throw invalid(fn, original, "contains characters outside letters, digits and hyphen");
380
- if (label.startsWith("-") || label.endsWith("-")) throw invalid(fn, original, "may not start or end with a hyphen");
381
- if (label.startsWith(PREFIX)) decodeLabel(fn, label);
382
- else if (label.slice(2, 4) === "--") throw invalid(fn, original, "has hyphens in positions 3 and 4");
383
- return label;
384
- }
385
- function checkDomain(fn, labels, host) {
386
- if (labels.length > 1 && labels[labels.length - 1] === "") labels = labels.slice(0, -1);
387
- for (const label of labels) if (label === "") throw invalid(fn, host, "contains an empty label");
388
- const out = labels.join(".");
389
- if (out.length > 253) throw new RangeError(`${fn}: ${JSON.stringify(host)} exceeds 253 octets`);
390
- return out;
391
- }
392
- /**
393
- * Converts a domain to its A-label form: maps and lowercases each label the way UTS #46 does, punycodes the non-ASCII ones, and validates lengths, hyphens and existing `xn--` labels. IP literals pass through.
394
- * @throws {RangeError} when a label or the domain is not valid.
395
- */
396
- function domainToAscii(host) {
397
- if (host === "" || host.startsWith("[")) return host;
398
- const out = checkDomain("domainToAscii", host.split(LABEL_SEPARATORS).flatMap((label) => {
399
- if (isAsciiLabel(label)) return [checkAsciiLabel("domainToAscii", label.toLowerCase(), label)];
400
- const mapped = mapLabel(label);
401
- if (mapped.includes(".")) return domainToAscii(mapped).split(".");
402
- if (isAsciiLabel(mapped)) return [checkAsciiLabel("domainToAscii", mapped, label)];
403
- return [checkAsciiLabel("domainToAscii", PREFIX + punycodeEncode(mapped), label)];
404
- }), host);
405
- return host.endsWith(".") && out !== "" ? `${out}.` : out;
406
- }
407
- /**
408
- * Converts the `xn--` labels of a domain back to Unicode and lowercases the rest.
409
- * @throws {RangeError} when an `xn--` label does not decode to a valid U-label.
410
- */
411
- function domainToUnicode(host) {
412
- if (host === "" || host.startsWith("[")) return host;
413
- const out = checkDomain("domainToUnicode", host.split(".").map((label) => {
414
- const lower = label.toLowerCase();
415
- if (!isAsciiLabel(lower)) return lower;
416
- return lower.startsWith(PREFIX) ? decodeLabel("domainToUnicode", lower) : lower;
417
- }), host);
418
- return host.endsWith(".") && out !== "" ? `${out}.` : out;
419
- }
420
-
421
243
  //#endregion
422
244
  //#region src/uri/normalize.ts
423
245
  /** Default ports of the common schemes, used by `normalizeUri` and `equivalentUris`. */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cizgile",
3
- "version": "0.3.0",
3
+ "version": "1.0.0",
4
4
  "description": "RFC 3986/3987-grounded URL slugs. Transliteration, Unicode slugs, IRI to URI, percent-encoding, dot-segment removal. Zero dependencies, tree-shakeable.",
5
5
  "keywords": [
6
6
  "esm",
@@ -44,6 +44,10 @@
44
44
  "types": "./dist/uri.d.mts",
45
45
  "default": "./dist/uri.mjs"
46
46
  },
47
+ "./uri/idna": {
48
+ "types": "./dist/idna.d.mts",
49
+ "default": "./dist/idna.mjs"
50
+ },
47
51
  "./transliterate": {
48
52
  "types": "./dist/transliterate.d.mts",
49
53
  "default": "./dist/transliterate.mjs"
@@ -64,26 +68,26 @@
64
68
  "prepack": "bun run build",
65
69
  "test:bun": "bun --bun vitest run",
66
70
  "bench": "vitest bench --run",
67
- "bench:baseline": "vitest bench --run --outputJson bench/results.json && node bench/compare.mjs bench/results.json bench/baseline.json write"
71
+ "bench:baseline": "vitest bench --run --reporter=default --reporter=json --outputFile.json=bench/results.json && node bench/compare.mjs bench/results.json bench/baseline.json write"
68
72
  },
69
73
  "devDependencies": {
70
74
  "@arethetypeswrong/cli": "0.18.5",
71
- "@sindresorhus/slugify": "^3.0.0",
72
- "@types/bun": "1.4.0",
73
- "@vitest/coverage-v8": "4.1.11",
74
- "bumpp": "12.2.2",
75
- "oxfmt": "0.65.0",
76
- "oxlint": "1.80.0",
77
- "oxlint-tsgolint": "7.0.2001",
78
- "publint": "0.3.24",
79
- "rolldown": "1.2.6",
80
- "rolldown-plugin-dts": "0.28.4",
75
+ "@sindresorhus/slugify": "^3.0.1",
76
+ "@types/bun": "1.4.3",
77
+ "@vitest/coverage-v8": "5.0.5",
78
+ "bumpp": "12.3.0",
79
+ "oxfmt": "0.74.0",
80
+ "oxlint": "1.89.0",
81
+ "oxlint-tsgolint": "7.0.2004",
82
+ "publint": "0.3.25",
83
+ "rolldown": "1.2.14",
84
+ "rolldown-plugin-dts": "0.28.8",
81
85
  "slugify": "^1.6.9",
82
86
  "typescript": "7.0.2",
83
- "vitest": "4.1.11"
87
+ "vitest": "5.0.5"
84
88
  },
85
89
  "engines": {
86
90
  "node": ">=20.19.0"
87
91
  },
88
- "packageManager": "bun@1.4.0"
92
+ "packageManager": "bun@1.4.3"
89
93
  }