@ewanc26/utils 0.1.2 → 0.1.4

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
@@ -1,43 +1,12 @@
1
1
  # @ewanc26/utils
2
2
 
3
- Shared utility functions extracted from [ewancroft.uk](https://ewancroft.uk). Zero runtime dependencies.
4
-
5
- ## Modules
6
-
7
- - **Date & Locale** — `formatRelativeTime`, `formatLocalizedDate`, `getUserLocale`
8
- - **Number Formatting** — `formatCompactNumber`, `formatNumber`
9
- - **URL Utilities** — `getDomain`, `atUriToBlueskyUrl`, `getBlueskyProfileUrl`, `isExternalUrl`
10
- - **Validators & Text** — `isValidTid`, `isValidDid`, `truncateText`, `escapeHtml`, `getInitials`, `debounce`, `throttle`
11
- - **RSS Generation** — `generateRSSFeed`, `generateRSSItem`, `createRSSResponse`, `escapeXml`, `normalizeCharacters`, `formatRSSDate`
12
-
13
- ## Installation
3
+ Shared utility functions date formatting, number formatting, URL utilities, validators, text helpers, and RSS generation. Zero runtime dependencies.
14
4
 
15
5
  ```bash
16
6
  pnpm add @ewanc26/utils
17
7
  ```
18
8
 
19
- ## Quick Examples
20
-
21
- ```typescript
22
- import { formatRelativeTime, formatCompactNumber, getDomain, isValidDid, generateRSSFeed } from '@ewanc26/utils';
23
-
24
- formatRelativeTime('2025-11-13T00:00:00Z'); // '3d ago'
25
- formatCompactNumber(1500); // '1.5K'
26
- getDomain('https://www.example.com/path'); // 'example.com'
27
- isValidDid('did:plc:abc123'); // true
28
-
29
- const xml = generateRSSFeed({ title: 'My Blog', link: 'https://mysite.com', description: '…' }, items);
30
- ```
31
-
32
- All functions are SSR-safe and fall back to `en-GB` when `navigator` / `window` are unavailable.
33
-
34
- ## Build
35
-
36
- ```bash
37
- pnpm build # tsc
38
- pnpm dev # tsc --watch
39
- pnpm check # tsc --noEmit
40
- ```
9
+ Full documentation at **[docs.ewancroft.uk](https://docs.ewancroft.uk/projects/utils)**.
41
10
 
42
11
  ## Licence
43
12
 
package/dist/index.d.ts CHANGED
@@ -4,4 +4,5 @@ export * from './url.js';
4
4
  export * from './validators.js';
5
5
  export * from './rss.js';
6
6
  export * from './locale.js';
7
+ export * from './slug.js';
7
8
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAChC,cAAc,mBAAmB,CAAC;AAClC,cAAc,UAAU,CAAC;AACzB,cAAc,iBAAiB,CAAC;AAChC,cAAc,UAAU,CAAC;AACzB,cAAc,aAAa,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAChC,cAAc,mBAAmB,CAAC;AAClC,cAAc,UAAU,CAAC;AACzB,cAAc,iBAAiB,CAAC;AAChC,cAAc,UAAU,CAAC;AACzB,cAAc,aAAa,CAAC;AAC5B,cAAc,WAAW,CAAC"}
package/dist/index.js CHANGED
@@ -4,3 +4,4 @@ export * from './url.js';
4
4
  export * from './validators.js';
5
5
  export * from './rss.js';
6
6
  export * from './locale.js';
7
+ export * from './slug.js';
package/dist/slug.d.ts ADDED
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Normalize a slug to be URI-compatible.
3
+ *
4
+ * Transformations:
5
+ * - Lowercase
6
+ * - Spaces → hyphens
7
+ * - Remove all characters except alphanumeric, hyphens, underscores
8
+ * - Collapse multiple hyphens into one
9
+ * - Strip leading/trailing hyphens
10
+ */
11
+ export declare function normalizeSlug(slug: string): string;
12
+ /**
13
+ * Check if a string matches AT Protocol TID format (12–16 base32 characters).
14
+ */
15
+ export declare function isTidFormat(str: string): boolean;
16
+ //# sourceMappingURL=slug.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"slug.d.ts","sourceRoot":"","sources":["../src/slug.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAQlD;AAED;;GAEG;AACH,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAEhD"}
package/dist/slug.js ADDED
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Normalize a slug to be URI-compatible.
3
+ *
4
+ * Transformations:
5
+ * - Lowercase
6
+ * - Spaces → hyphens
7
+ * - Remove all characters except alphanumeric, hyphens, underscores
8
+ * - Collapse multiple hyphens into one
9
+ * - Strip leading/trailing hyphens
10
+ */
11
+ export function normalizeSlug(slug) {
12
+ return slug
13
+ .toLowerCase()
14
+ .trim()
15
+ .replace(/\s+/g, '-')
16
+ .replace(/[^a-z0-9\-_]/g, '')
17
+ .replace(/-+/g, '-')
18
+ .replace(/^-+|-+$/g, '');
19
+ }
20
+ /**
21
+ * Check if a string matches AT Protocol TID format (12–16 base32 characters).
22
+ */
23
+ export function isTidFormat(str) {
24
+ return /^[a-zA-Z0-9]{12,16}$/.test(str);
25
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ewanc26/utils",
3
- "version": "0.1.2",
3
+ "version": "0.1.4",
4
4
  "description": "Shared utility functions extracted from ewancroft.uk",
5
5
  "type": "module",
6
6
  "exports": {
package/src/index.ts CHANGED
@@ -4,3 +4,4 @@ export * from './url.js';
4
4
  export * from './validators.js';
5
5
  export * from './rss.js';
6
6
  export * from './locale.js';
7
+ export * from './slug.js';
package/src/slug.ts ADDED
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Normalize a slug to be URI-compatible.
3
+ *
4
+ * Transformations:
5
+ * - Lowercase
6
+ * - Spaces → hyphens
7
+ * - Remove all characters except alphanumeric, hyphens, underscores
8
+ * - Collapse multiple hyphens into one
9
+ * - Strip leading/trailing hyphens
10
+ */
11
+ export function normalizeSlug(slug: string): string {
12
+ return slug
13
+ .toLowerCase()
14
+ .trim()
15
+ .replace(/\s+/g, '-')
16
+ .replace(/[^a-z0-9\-_]/g, '')
17
+ .replace(/-+/g, '-')
18
+ .replace(/^-+|-+$/g, '');
19
+ }
20
+
21
+ /**
22
+ * Check if a string matches AT Protocol TID format (12–16 base32 characters).
23
+ */
24
+ export function isTidFormat(str: string): boolean {
25
+ return /^[a-zA-Z0-9]{12,16}$/.test(str);
26
+ }