@sharadox/web-library 0.9.0-shared-helpers.19 → 0.10.0-polish.23
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/CHANGELOG.md +7 -0
- package/README.md +1 -0
- package/distribution/identifier/uuid-version-7/index.d.ts +12 -0
- package/distribution/identifier/uuid-version-7/index.d.ts.map +1 -0
- package/distribution/identifier/uuid-version-7/index.js +22 -0
- package/distribution/identifier/uuid-version-7/index.js.map +1 -0
- package/llms.txt +1 -0
- package/package.json +4 -3
package/CHANGELOG.md
ADDED
package/README.md
CHANGED
|
@@ -40,6 +40,7 @@ Import each utility by its path:
|
|
|
40
40
|
| `…/text/separator` | `SEPARATOR` ("·"), the separator every Sharadox text uses | `separate(SEPARATOR, "Contact", "Ana") // "Contact · Ana"` |
|
|
41
41
|
| `…/text/separate` | `separate(separator, ...parts)` | `separate(SEPARATOR, "Contact", "Ana") // "Contact · Ana"` |
|
|
42
42
|
| `…/text/separated` | `separated(...parts)`: `separate` with the shared `SEPARATOR` | `separated("Contact", "Ana") // "Contact · Ana"` |
|
|
43
|
+
| `…/identifier/uuid-version-7` | `uuidVersion7()`: a new UUID version 7, time first so identifiers sort by when they were made | `uuidVersion7() // "019a8f3c-6b2e-7c41-…"` |
|
|
43
44
|
| `…/text/two-digit` | `twoDigits(count)`: a count as two digits | `twoDigits(3) // "03"` |
|
|
44
45
|
| `…/request/client-address` | `clientAddress(headers)`: the visitor's address from `x-forwarded-for`, or `"unknown"` | `clientAddress(await headers())` |
|
|
45
46
|
| `…/math/clamp` | `clamp(value, minimum, maximum)` | `clamp(5, 0, 1) // 1` |
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A new UUID version 7 (RFC 9562): the time in milliseconds first, then random bits, so identifiers sort by when
|
|
3
|
+
* they were made and never repeat. For example a contact form's conversation identifier.
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* uuidVersion7(); // "019a8f3c-6b2e-7c41-9d03-5e1f2a7b8c90"
|
|
7
|
+
*/
|
|
8
|
+
export declare function uuidVersion7({ now, random, }?: {
|
|
9
|
+
now?: number;
|
|
10
|
+
random?: Uint8Array;
|
|
11
|
+
}): string;
|
|
12
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../source/identifier/uuid-version-7/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,wBAAgB,YAAY,CAAC,EAC3B,GAAgB,EAChB,MAAmD,GACpD,GAAE;IAAE,GAAG,CAAC,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,UAAU,CAAA;CAAO,GAAG,MAAM,CAarD"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A new UUID version 7 (RFC 9562): the time in milliseconds first, then random bits, so identifiers sort by when
|
|
3
|
+
* they were made and never repeat. For example a contact form's conversation identifier.
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* uuidVersion7(); // "019a8f3c-6b2e-7c41-9d03-5e1f2a7b8c90"
|
|
7
|
+
*/
|
|
8
|
+
export function uuidVersion7({ now = Date.now(), random = crypto.getRandomValues(new Uint8Array(10)), } = {}) {
|
|
9
|
+
const bytes = new Uint8Array(16);
|
|
10
|
+
// 48 bits of Unix time in milliseconds, most significant byte first.
|
|
11
|
+
let time = now;
|
|
12
|
+
for (let index = 5; index >= 0; index--) {
|
|
13
|
+
bytes[index] = time % 256;
|
|
14
|
+
time = Math.floor(time / 256);
|
|
15
|
+
}
|
|
16
|
+
bytes.set(random.subarray(0, 10), 6);
|
|
17
|
+
bytes[6] = 0x70 | (bytes[6] & 0x0f); // version 7
|
|
18
|
+
bytes[8] = 0x80 | (bytes[8] & 0x3f); // the RFC's variant
|
|
19
|
+
const hex = [...bytes].map((byte) => byte.toString(16).padStart(2, "0")).join("");
|
|
20
|
+
return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}`;
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../source/identifier/uuid-version-7/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,MAAM,UAAU,YAAY,CAAC,EAC3B,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,EAChB,MAAM,GAAG,MAAM,CAAC,eAAe,CAAC,IAAI,UAAU,CAAC,EAAE,CAAC,CAAC,MACV,EAAE;IAC3C,MAAM,KAAK,GAAG,IAAI,UAAU,CAAC,EAAE,CAAC,CAAC;IACjC,qEAAqE;IACrE,IAAI,IAAI,GAAG,GAAG,CAAC;IACf,KAAK,IAAI,KAAK,GAAG,CAAC,EAAE,KAAK,IAAI,CAAC,EAAE,KAAK,EAAE,EAAE,CAAC;QACxC,KAAK,CAAC,KAAK,CAAC,GAAG,IAAI,GAAG,GAAG,CAAC;QAC1B,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,GAAG,GAAG,CAAC,CAAC;IAChC,CAAC;IACD,KAAK,CAAC,GAAG,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,EAAE,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;IACrC,KAAK,CAAC,CAAC,CAAC,GAAG,IAAI,GAAG,CAAC,KAAK,CAAC,CAAC,CAAE,GAAG,IAAI,CAAC,CAAC,CAAC,YAAY;IAClD,KAAK,CAAC,CAAC,CAAC,GAAG,IAAI,GAAG,CAAC,KAAK,CAAC,CAAC,CAAE,GAAG,IAAI,CAAC,CAAC,CAAC,oBAAoB;IAC1D,MAAM,GAAG,GAAG,CAAC,GAAG,KAAK,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IAClF,OAAO,GAAG,GAAG,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,IAAI,GAAG,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,GAAG,CAAC,KAAK,CAAC,EAAE,EAAE,EAAE,CAAC,IAAI,GAAG,CAAC,KAAK,CAAC,EAAE,EAAE,EAAE,CAAC,IAAI,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC,EAAE,CAAC;AAC7G,CAAC"}
|
package/llms.txt
CHANGED
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
- html/escape → escapeHtml(text)
|
|
13
13
|
- text/separator → SEPARATOR "·", the one separator every Sharadox site and library uses
|
|
14
14
|
- text/separate → separate(separator, ...parts): "a · b", skipping empty parts (pass SEPARATOR)
|
|
15
|
+
- identifier/uuid-version-7 → uuidVersion7({ now?, random? }?): RFC 9562 UUID version 7 (48-bit millisecond time, then random; sorts by creation), e.g. a contact conversation identifier
|
|
15
16
|
- text/separated → separated(...parts): separate with SEPARATOR, the one every Sharadox text uses
|
|
16
17
|
- text/two-digit → twoDigits(count): 1 → "01" (numbered lists and steps)
|
|
17
18
|
- request/client-address → clientAddress(headers): first x-forwarded-for entry, or "unknown" (rate limits, abuse checks)
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sharadox/web-library",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "General TypeScript utilities shared by every Sharadox library and application: type guards, class names, HTML escaping, text joining, math helpers and exhaustiveness checks.",
|
|
3
|
+
"version": "0.10.0-polish.23",
|
|
4
|
+
"description": "General TypeScript utilities shared by every Sharadox library and application: type guards, class names, HTML escaping, text joining, identifiers, math helpers and exhaustiveness checks.",
|
|
5
5
|
"private": false,
|
|
6
6
|
"license": "SEE LICENSE IN LICENCA.md",
|
|
7
7
|
"author": "Sharadox <contact@sharadox.com>",
|
|
@@ -22,7 +22,8 @@
|
|
|
22
22
|
"LICENCA.md",
|
|
23
23
|
"LICENSE.md",
|
|
24
24
|
"NOTICE.md",
|
|
25
|
-
"llms.txt"
|
|
25
|
+
"llms.txt",
|
|
26
|
+
"CHANGELOG.md"
|
|
26
27
|
],
|
|
27
28
|
"sideEffects": false,
|
|
28
29
|
"engines": {
|