@sharadox/web-library 0.8.1-development.16 → 0.9.0-development.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.
- package/README.md +3 -0
- package/distribution/request/client-address/index.d.ts +13 -0
- package/distribution/request/client-address/index.d.ts.map +1 -0
- package/distribution/request/client-address/index.js +11 -0
- package/distribution/request/client-address/index.js.map +1 -0
- package/distribution/text/separated/index.d.ts +9 -0
- package/distribution/text/separated/index.d.ts.map +1 -0
- package/distribution/text/separated/index.js +13 -0
- package/distribution/text/separated/index.js.map +1 -0
- package/distribution/text/two-digit/index.d.ts +8 -0
- package/distribution/text/two-digit/index.d.ts.map +1 -0
- package/distribution/text/two-digit/index.js +10 -0
- package/distribution/text/two-digit/index.js.map +1 -0
- package/llms.txt +3 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -39,6 +39,9 @@ Import each utility by its path:
|
|
|
39
39
|
| `…/html/escape` | `escapeHtml(text)` | `escapeHtml("<b>") // "<b>"` |
|
|
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
|
+
| `…/text/separated` | `separated(...parts)`: `separate` with the shared `SEPARATOR` | `separated("Contact", "Ana") // "Contact · Ana"` |
|
|
43
|
+
| `…/text/two-digit` | `twoDigits(count)`: a count as two digits | `twoDigits(3) // "03"` |
|
|
44
|
+
| `…/request/client-address` | `clientAddress(headers)`: the visitor's address from `x-forwarded-for`, or `"unknown"` | `clientAddress(await headers())` |
|
|
42
45
|
| `…/math/clamp` | `clamp(value, minimum, maximum)` | `clamp(5, 0, 1) // 1` |
|
|
43
46
|
| `…/math/radians` | `radians(degrees)` | `radians(180) // Math.PI` |
|
|
44
47
|
| `…/math/pseudo-random` | `pseudoRandom(seed)`: repeatable number in [0, 1) | `pseudoRandom(3) === pseudoRandom(3)` |
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/** Anything that reads request headers by name: a `Headers`, or what Next.js `headers()` returns. */
|
|
2
|
+
export interface HeaderReader {
|
|
3
|
+
get(name: string): string | null;
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* The visitor's address as the hosting platform reports it: the first entry of `x-forwarded-for` (the visitor; the
|
|
7
|
+
* rest are proxies), or "unknown". For rate limits and abuse checks, never stored with personal data.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* clientAddress(await headers()); // "203.0.113.7"
|
|
11
|
+
*/
|
|
12
|
+
export declare function clientAddress(headers: HeaderReader): string;
|
|
13
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../source/request/client-address/index.ts"],"names":[],"mappings":"AAAA,qGAAqG;AACrG,MAAM,WAAW,YAAY;IAC3B,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAAC;CAClC;AAED;;;;;;GAMG;AACH,wBAAgB,aAAa,CAAC,OAAO,EAAE,YAAY,GAAG,MAAM,CAE3D"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The visitor's address as the hosting platform reports it: the first entry of `x-forwarded-for` (the visitor; the
|
|
3
|
+
* rest are proxies), or "unknown". For rate limits and abuse checks, never stored with personal data.
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* clientAddress(await headers()); // "203.0.113.7"
|
|
7
|
+
*/
|
|
8
|
+
export function clientAddress(headers) {
|
|
9
|
+
return (headers.get("x-forwarded-for") ?? "").split(",")[0].trim() || "unknown";
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../source/request/client-address/index.ts"],"names":[],"mappings":"AAKA;;;;;;GAMG;AACH,MAAM,UAAU,aAAa,CAAC,OAAqB;IACjD,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,iBAAiB,CAAC,IAAI,EAAE,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAE,CAAC,IAAI,EAAE,IAAI,SAAS,CAAC;AACnF,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Joins the parts that are set with the separator every Sharadox text uses (`SEPARATOR`, "·"), spaced on both sides,
|
|
3
|
+
* skipping `false`, `null`, `undefined` and empty strings.
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* separated("Contact", "Ana (Café)", undefined); // "Contact · Ana (Café)"
|
|
7
|
+
*/
|
|
8
|
+
export declare function separated(...parts: (string | false | null | undefined)[]): string;
|
|
9
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../source/text/separated/index.ts"],"names":[],"mappings":"AAGA;;;;;;GAMG;AACH,wBAAgB,SAAS,CAAC,GAAG,KAAK,EAAE,CAAC,MAAM,GAAG,KAAK,GAAG,IAAI,GAAG,SAAS,CAAC,EAAE,GAAG,MAAM,CAEjF"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { separate } from "@sharadox/web-library/text/separate";
|
|
2
|
+
import { SEPARATOR } from "@sharadox/web-library/text/separator";
|
|
3
|
+
/**
|
|
4
|
+
* Joins the parts that are set with the separator every Sharadox text uses (`SEPARATOR`, "·"), spaced on both sides,
|
|
5
|
+
* skipping `false`, `null`, `undefined` and empty strings.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* separated("Contact", "Ana (Café)", undefined); // "Contact · Ana (Café)"
|
|
9
|
+
*/
|
|
10
|
+
export function separated(...parts) {
|
|
11
|
+
return separate(SEPARATOR, ...parts);
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../source/text/separated/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,qCAAqC,CAAC;AAC/D,OAAO,EAAE,SAAS,EAAE,MAAM,sCAAsC,CAAC;AAEjE;;;;;;GAMG;AACH,MAAM,UAAU,SAAS,CAAC,GAAG,KAA4C;IACvE,OAAO,QAAQ,CAAC,SAAS,EAAE,GAAG,KAAK,CAAC,CAAC;AACvC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../source/text/two-digit/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,wBAAgB,SAAS,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAE/C"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A count as two digits, the way numbered lists and steps show it: 1 is "01", 12 stays "12".
|
|
3
|
+
*
|
|
4
|
+
* @example
|
|
5
|
+
* twoDigits(3); // "03"
|
|
6
|
+
*/
|
|
7
|
+
export function twoDigits(count) {
|
|
8
|
+
return String(count).padStart(2, "0");
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../source/text/two-digit/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,MAAM,UAAU,SAAS,CAAC,KAAa;IACrC,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;AACxC,CAAC"}
|
package/llms.txt
CHANGED
|
@@ -12,6 +12,9 @@
|
|
|
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
|
+
- text/separated → separated(...parts): separate with SEPARATOR, the one every Sharadox text uses
|
|
16
|
+
- text/two-digit → twoDigits(count): 1 → "01" (numbered lists and steps)
|
|
17
|
+
- request/client-address → clientAddress(headers): first x-forwarded-for entry, or "unknown" (rate limits, abuse checks)
|
|
15
18
|
- math/clamp, math/radians, math/pseudo-random
|
|
16
19
|
- assert/never → assertNever(value): throws; for exhaustive switches
|
|
17
20
|
- Import by path: `import { isString } from "@sharadox/web-library/type-guard/is-string";`
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sharadox/web-library",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.0-development.20",
|
|
4
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.",
|
|
5
5
|
"private": false,
|
|
6
6
|
"license": "SEE LICENSE IN LICENCA.md",
|