@ewanc26/utils 0.1.2 → 0.1.3

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/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.3",
4
4
  "description": "Shared utility functions extracted from ewancroft.uk",
5
5
  "type": "module",
6
6
  "exports": {
@@ -19,12 +19,12 @@
19
19
  "dist",
20
20
  "src"
21
21
  ],
22
- "devDependencies": {
23
- "typescript": "^5.9.3"
24
- },
25
22
  "scripts": {
26
23
  "build": "tsc --project tsconfig.json",
27
24
  "dev": "tsc --project tsconfig.json --watch",
28
25
  "check": "tsc --noEmit"
26
+ },
27
+ "devDependencies": {
28
+ "typescript": "^5.9.3"
29
29
  }
30
- }
30
+ }
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
+ }