@sharadox/web-library 0.6.1 → 0.8.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/README.md CHANGED
@@ -27,23 +27,25 @@ pnpm add @sharadox/web-library
27
27
 
28
28
  Import each utility by its path:
29
29
 
30
- | Import | Export | Example |
31
- | -------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ---------------------------------------------------- |
32
- | `@sharadox/web-library/type-guard/is-string` | `isString(value)` | `isString("a") // true` |
33
- | `…/type-guard/is-non-empty-string` | `isNonEmptyString(value)` | `isNonEmptyString("") // false` |
34
- | `…/type-guard/is-number` | `isNumber(value)`: finite numbers only | `isNumber(NaN) // false` |
35
- | `…/type-guard/is-boolean` | `isBoolean(value)` | `isBoolean(false) // true` |
36
- | `…/type-guard/is-record` | `isRecord(value)`: plain objects only | `isRecord([]) // false` |
37
- | `…/type-guard/is-defined` | `isDefined(value)`: not `null`/`undefined` | `[1, undefined].filter(isDefined) // [1]` |
38
- | `…/class-name` | `classNames(...names)` | `classNames("a", false, "b") // "a b"` |
39
- | `…/html/escape` | `escapeHtml(text)` | `escapeHtml("<b>") // "&lt;b&gt;"` |
40
- | `…/text/separate` | `separate(separator, ...parts)` | `separate("•", "Contact", "Ana") // "Contact • Ana"` |
41
- | `…/math/clamp` | `clamp(value, minimum, maximum)` | `clamp(5, 0, 1) // 1` |
42
- | `…/math/radians` | `radians(degrees)` | `radians(180) // Math.PI` |
43
- | `…/math/pseudo-random` | `pseudoRandom(seed)`: repeatable number in [0, 1) | `pseudoRandom(3) === pseudoRandom(3)` |
44
- | `…/assert/never` | `assertNever(value)`: exhaustive `switch` checks | `default: return assertNever(kind)` |
45
- | `…/navigation/soft-navigation` | `beginSoftNavigation()`, `isSoftNavigation()`, `markSoftNavigationDocument()`, `endSoftNavigationDocument()`: a page rebuilt in place (language switch) skips entrance effects | `const [skip] = useState(isSoftNavigation)` |
46
- | `…/layout/on-screen` | `isOnScreen(element)`: any part inside the viewport now | `if (isOnScreen(card)) …` |
30
+ | Import | Export | Example |
31
+ | -------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ---------------------------------------------------------- |
32
+ | `@sharadox/web-library/type-guard/is-string` | `isString(value)` | `isString("a") // true` |
33
+ | `…/type-guard/is-non-empty-string` | `isNonEmptyString(value)` | `isNonEmptyString("") // false` |
34
+ | `…/type-guard/is-number` | `isNumber(value)`: finite numbers only | `isNumber(NaN) // false` |
35
+ | `…/type-guard/is-boolean` | `isBoolean(value)` | `isBoolean(false) // true` |
36
+ | `…/type-guard/is-record` | `isRecord(value)`: plain objects only | `isRecord([]) // false` |
37
+ | `…/type-guard/is-defined` | `isDefined(value)`: not `null`/`undefined` | `[1, undefined].filter(isDefined) // [1]` |
38
+ | `…/class-name` | `classNames(...names)` | `classNames("a", false, "b") // "a b"` |
39
+ | `…/html/escape` | `escapeHtml(text)` | `escapeHtml("<b>") // "&lt;b&gt;"` |
40
+ | `…/text/separator` | `SEPARATOR` ("·"), the separator every Sharadox text uses | `separate(SEPARATOR, "Contact", "Ana") // "Contact · Ana"` |
41
+ | `…/text/separate` | `separate(separator, ...parts)` | `separate(SEPARATOR, "Contact", "Ana") // "Contact · Ana"` |
42
+ | `…/math/clamp` | `clamp(value, minimum, maximum)` | `clamp(5, 0, 1) // 1` |
43
+ | `…/math/radians` | `radians(degrees)` | `radians(180) // Math.PI` |
44
+ | `…/math/pseudo-random` | `pseudoRandom(seed)`: repeatable number in [0, 1) | `pseudoRandom(3) === pseudoRandom(3)` |
45
+ | `…/assert/never` | `assertNever(value)`: exhaustive `switch` checks | `default: return assertNever(kind)` |
46
+ | `…/navigation/soft-navigation` | `beginSoftNavigation()`, `isSoftNavigation()`, `markSoftNavigationDocument()`, `endSoftNavigationDocument()`: a page rebuilt in place (language switch) skips entrance effects | `const [skip] = useState(isSoftNavigation)` |
47
+ | `…/navigation/new-tab` | `leavesSite(href)`, `newTab(href)`: links that leave the site (other sites, email, phone, messages, maps) open in a new tab | `<a href={href} {...newTab(href)}>` |
48
+ | `…/layout/on-screen` | `isOnScreen(element)`: any part inside the viewport now | `if (isOnScreen(card)) …` |
47
49
 
48
50
  ## Develop
49
51
 
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Whether a link leaves the site: anything that isn't one of its own paths (`/…`), sections (`#…`) or relative
3
+ * addresses. Other sites, and the apps that handle email, phones, messages and maps (`mailto:`, `tel:`, `sms:`, a map
4
+ * link), all leave it.
5
+ *
6
+ * @example
7
+ * leavesSite("mailto:ana@example.com"); // true
8
+ * leavesSite("/en/privacy"); // false
9
+ */
10
+ export declare function leavesSite(href: string): boolean;
11
+ /**
12
+ * The attributes that open a link in a new tab when it leaves the site (see `leavesSite`), so the visitor keeps the
13
+ * page where they were while an email web app, a map or another site opens beside it; nothing for the site's own
14
+ * links. `noopener noreferrer` keeps the new page from reaching back into this one.
15
+ *
16
+ * @example
17
+ * <a href={href} {...newTab(href)}>…</a>
18
+ */
19
+ export declare function newTab(href: string): {
20
+ target?: "_blank";
21
+ rel?: "noopener noreferrer";
22
+ };
23
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../source/navigation/new-tab/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAEhD;AAED;;;;;;;GAOG;AACH,wBAAgB,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG;IAAE,MAAM,CAAC,EAAE,QAAQ,CAAC;IAAC,GAAG,CAAC,EAAE,qBAAqB,CAAA;CAAE,CAEvF"}
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Whether a link leaves the site: anything that isn't one of its own paths (`/…`), sections (`#…`) or relative
3
+ * addresses. Other sites, and the apps that handle email, phones, messages and maps (`mailto:`, `tel:`, `sms:`, a map
4
+ * link), all leave it.
5
+ *
6
+ * @example
7
+ * leavesSite("mailto:ana@example.com"); // true
8
+ * leavesSite("/en/privacy"); // false
9
+ */
10
+ export function leavesSite(href) {
11
+ return /^[a-z][a-z\d+.-]*:/i.test(href) || href.startsWith("//");
12
+ }
13
+ /**
14
+ * The attributes that open a link in a new tab when it leaves the site (see `leavesSite`), so the visitor keeps the
15
+ * page where they were while an email web app, a map or another site opens beside it; nothing for the site's own
16
+ * links. `noopener noreferrer` keeps the new page from reaching back into this one.
17
+ *
18
+ * @example
19
+ * <a href={href} {...newTab(href)}>…</a>
20
+ */
21
+ export function newTab(href) {
22
+ return leavesSite(href) ? { target: "_blank", rel: "noopener noreferrer" } : {};
23
+ }
24
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../source/navigation/new-tab/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,MAAM,UAAU,UAAU,CAAC,IAAY;IACrC,OAAO,qBAAqB,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;AACnE,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,MAAM,CAAC,IAAY;IACjC,OAAO,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,QAAQ,EAAE,GAAG,EAAE,qBAAqB,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;AAClF,CAAC"}
@@ -1,9 +1,9 @@
1
1
  /**
2
2
  * Joins the parts that are set with a separator surrounded by spaces, skipping `false`, `null`, `undefined` and empty
3
- * strings. Brands keep their separator in one constant and pass it here.
3
+ * strings. Pass `SEPARATOR` (from `…/text/separator`), the one every Sharadox text uses.
4
4
  *
5
5
  * @example
6
- * separate("•", "Contact", "Ana", undefined); // "Contact • Ana"
6
+ * separate(SEPARATOR, "Contact", "Ana", undefined); // "Contact · Ana"
7
7
  */
8
8
  export declare function separate(separator: string, ...parts: (string | false | null | undefined)[]): string;
9
9
  //# sourceMappingURL=index.d.ts.map
@@ -1,9 +1,9 @@
1
1
  /**
2
2
  * Joins the parts that are set with a separator surrounded by spaces, skipping `false`, `null`, `undefined` and empty
3
- * strings. Brands keep their separator in one constant and pass it here.
3
+ * strings. Pass `SEPARATOR` (from `…/text/separator`), the one every Sharadox text uses.
4
4
  *
5
5
  * @example
6
- * separate("•", "Contact", "Ana", undefined); // "Contact • Ana"
6
+ * separate(SEPARATOR, "Contact", "Ana", undefined); // "Contact · Ana"
7
7
  */
8
8
  export function separate(separator, ...parts) {
9
9
  return parts.filter(Boolean).join(` ${separator} `);
@@ -0,0 +1,9 @@
1
+ /**
2
+ * The separator every Sharadox text uses between labels side by side: titles ("Sharadox · Simple"), footers, tags,
3
+ * email subjects. One constant, so it changes in one place for every site and library.
4
+ *
5
+ * @example
6
+ * separate(SEPARATOR, "Velvet", "Midnight"); // "Velvet · Midnight"
7
+ */
8
+ export declare const SEPARATOR = "\u00B7";
9
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../source/text/separator/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,eAAO,MAAM,SAAS,WAAM,CAAC"}
@@ -0,0 +1,9 @@
1
+ /**
2
+ * The separator every Sharadox text uses between labels side by side: titles ("Sharadox · Simple"), footers, tags,
3
+ * email subjects. One constant, so it changes in one place for every site and library.
4
+ *
5
+ * @example
6
+ * separate(SEPARATOR, "Velvet", "Midnight"); // "Velvet · Midnight"
7
+ */
8
+ export const SEPARATOR = "·";
9
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../source/text/separator/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG,GAAG,CAAC"}
package/llms.txt CHANGED
@@ -10,10 +10,12 @@
10
10
  - type-guard/is-defined → isDefined(value): not null/undefined
11
11
  - class-name → classNames(...names): joins truthy names
12
12
  - html/escape → escapeHtml(text)
13
- - text/separate → separate(separator, ...parts): "a • b", skipping empty parts
13
+ - text/separator → SEPARATOR "·", the one separator every Sharadox site and library uses
14
+ - text/separate → separate(separator, ...parts): "a · b", skipping empty parts (pass SEPARATOR)
14
15
  - math/clamp, math/radians, math/pseudo-random
15
16
  - assert/never → assertNever(value): throws; for exhaustive switches
16
17
  - Import by path: `import { isString } from "@sharadox/web-library/type-guard/is-string";`
17
18
  - License: Sharadox Open Source License 0.1.0
18
19
  - navigation/soft-navigation: beginSoftNavigation(ms=2000), isSoftNavigation() (shared on globalThis), markSoftNavigationDocument() + SOFT_NAVIGATION_ATTRIBUTE ("data-soft-navigation") — lets components skip entrance effects when a page is rebuilt in place (language switch)
20
+ - navigation/new-tab: leavesSite(href) (any scheme like https:, mailto:, tel:, sms:, or //host) and newTab(href) → { target: "_blank", rel: "noopener noreferrer" } or {} — every Sharadox site opens links that leave it in a new tab
19
21
  - navigation/soft-navigation endSoftNavigationDocument() clears the mark (the <html> element can outlive the navigation); layout/on-screen isOnScreen(element)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sharadox/web-library",
3
- "version": "0.6.1",
3
+ "version": "0.8.0",
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",