@devvit/shared-types 0.12.2-next-2025-10-16-22-26-47-63705be33.0 → 0.12.2-next-2025-10-16-22-45-34-2b8054235.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/package.json +5 -5
- package/slug.d.ts +13 -1
- package/slug.d.ts.map +1 -1
- package/slug.js +27 -17
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@devvit/shared-types",
|
|
3
|
-
"version": "0.12.2-next-2025-10-16-22-
|
|
3
|
+
"version": "0.12.2-next-2025-10-16-22-45-34-2b8054235.0",
|
|
4
4
|
"license": "BSD-3-Clause",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -33,13 +33,13 @@
|
|
|
33
33
|
},
|
|
34
34
|
"types": "./dist/index.d.ts",
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@devvit/protos": "0.12.2-next-2025-10-16-22-
|
|
36
|
+
"@devvit/protos": "0.12.2-next-2025-10-16-22-45-34-2b8054235.0",
|
|
37
37
|
"jsonschema": "1.4.1",
|
|
38
38
|
"uuid": "9.0.0"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
|
-
"@devvit/repo-tools": "0.12.2-next-2025-10-16-22-
|
|
42
|
-
"@devvit/tsconfig": "0.12.2-next-2025-10-16-22-
|
|
41
|
+
"@devvit/repo-tools": "0.12.2-next-2025-10-16-22-45-34-2b8054235.0",
|
|
42
|
+
"@devvit/tsconfig": "0.12.2-next-2025-10-16-22-45-34-2b8054235.0",
|
|
43
43
|
"@types/redis-mock": "0.17.1",
|
|
44
44
|
"@types/uuid": "9.0.0",
|
|
45
45
|
"chokidar-cli": "3.0.0",
|
|
@@ -51,5 +51,5 @@
|
|
|
51
51
|
"vitest": "1.6.1"
|
|
52
52
|
},
|
|
53
53
|
"source": "./src/index.ts",
|
|
54
|
-
"gitHead": "
|
|
54
|
+
"gitHead": "731d5ab06d6d38a7830d585977d0bdcb6ed28415"
|
|
55
55
|
}
|
package/slug.d.ts
CHANGED
|
@@ -2,6 +2,18 @@ export declare const APP_ACCOUNT_NAME_LENGTH_LIMIT = 20;
|
|
|
2
2
|
export declare const UNIQUE_SLUG_SUFFIX_LENGTH = 3;
|
|
3
3
|
export declare const APP_SLUG_BASE_MIN_LENGTH = 3;
|
|
4
4
|
export declare const APP_SLUG_BASE_MAX_LENGTH: number;
|
|
5
|
-
|
|
5
|
+
/**
|
|
6
|
+
* Returns a string describing why the input is not sluggable, or undefined if it is sluggable.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```tsx
|
|
10
|
+
* const err = validateSluggable('My App 1');
|
|
11
|
+
* if (err) {
|
|
12
|
+
* throw new Error(`App name is not valid. (${err})`);
|
|
13
|
+
* }
|
|
14
|
+
* const slug = makeSlug('My App 1'); // 'my-app-1'
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
export declare function validateSluggable(str: string): string | undefined;
|
|
6
18
|
export declare function makeSlug(str: string): string;
|
|
7
19
|
//# sourceMappingURL=slug.d.ts.map
|
package/slug.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"slug.d.ts","sourceRoot":"","sources":["../src/slug.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,6BAA6B,KAAK,CAAC;AAChD,eAAO,MAAM,yBAAyB,IAAI,CAAC;AAG3C,eAAO,MAAM,wBAAwB,IAAI,CAAC;AAC1C,eAAO,MAAM,wBAAwB,QAC0B,CAAC;AAIhE,wBAAgB,
|
|
1
|
+
{"version":3,"file":"slug.d.ts","sourceRoot":"","sources":["../src/slug.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,6BAA6B,KAAK,CAAC;AAChD,eAAO,MAAM,yBAAyB,IAAI,CAAC;AAG3C,eAAO,MAAM,wBAAwB,IAAI,CAAC;AAC1C,eAAO,MAAM,wBAAwB,QAC0B,CAAC;AAIhE;;;;;;;;;;;GAWG;AACH,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAcjE;AAED,wBAAgB,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAM5C"}
|
package/slug.js
CHANGED
|
@@ -4,27 +4,37 @@ export const UNIQUE_SLUG_SUFFIX_LENGTH = 3;
|
|
|
4
4
|
export const APP_SLUG_BASE_MIN_LENGTH = 3;
|
|
5
5
|
export const APP_SLUG_BASE_MAX_LENGTH = APP_ACCOUNT_NAME_LENGTH_LIMIT - UNIQUE_SLUG_SUFFIX_LENGTH - 1;
|
|
6
6
|
const ALLOWED_SLUG_REGEX = /^[a-z][a-z0-9-]*$/;
|
|
7
|
-
|
|
7
|
+
/**
|
|
8
|
+
* Returns a string describing why the input is not sluggable, or undefined if it is sluggable.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```tsx
|
|
12
|
+
* const err = validateSluggable('My App 1');
|
|
13
|
+
* if (err) {
|
|
14
|
+
* throw new Error(`App name is not valid. (${err})`);
|
|
15
|
+
* }
|
|
16
|
+
* const slug = makeSlug('My App 1'); // 'my-app-1'
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
export function validateSluggable(str) {
|
|
8
20
|
const slug = str.replace(/\s+/g, '-').toLowerCase();
|
|
9
|
-
if (slug.length < APP_SLUG_BASE_MIN_LENGTH
|
|
10
|
-
return
|
|
21
|
+
if (slug.length < APP_SLUG_BASE_MIN_LENGTH) {
|
|
22
|
+
return `name length must be longer than ${APP_SLUG_BASE_MIN_LENGTH} characters; length: ${slug.length}`;
|
|
23
|
+
}
|
|
24
|
+
if (slug.length > APP_SLUG_BASE_MAX_LENGTH) {
|
|
25
|
+
return `name length must be shorter than ${APP_SLUG_BASE_MAX_LENGTH} characters; length: ${slug.length}`;
|
|
26
|
+
}
|
|
27
|
+
if (!ALLOWED_SLUG_REGEX.test(slug)) {
|
|
28
|
+
return `invalid characters; only use a-z, 0-9, and -`;
|
|
29
|
+
}
|
|
30
|
+
if (slug.includes('reddit')) {
|
|
31
|
+
return `name cannot contain the word "reddit"`;
|
|
11
32
|
}
|
|
12
|
-
return ALLOWED_SLUG_REGEX.test(slug);
|
|
13
33
|
}
|
|
14
34
|
export function makeSlug(str) {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
if (slug.length < APP_SLUG_BASE_MIN_LENGTH) {
|
|
19
|
-
reason = `name length must be longer than ${APP_SLUG_BASE_MIN_LENGTH} characters; length: ${slug.length}`;
|
|
20
|
-
}
|
|
21
|
-
else if (slug.length > APP_SLUG_BASE_MAX_LENGTH) {
|
|
22
|
-
reason = `name length must be shorter than ${APP_SLUG_BASE_MAX_LENGTH} characters; length: ${slug.length}`;
|
|
23
|
-
}
|
|
24
|
-
else if (!ALLOWED_SLUG_REGEX.test(slug)) {
|
|
25
|
-
reason = 'invalid characters; only use a-z, 0-9, and -';
|
|
26
|
-
}
|
|
27
|
-
throw new Error(`App name is not valid. (${reason})`);
|
|
35
|
+
const err = validateSluggable(str);
|
|
36
|
+
if (err) {
|
|
37
|
+
throw new Error(`App name is not valid. (${err})`);
|
|
28
38
|
}
|
|
29
39
|
return str.replace(/\s+/g, '-').toLowerCase();
|
|
30
40
|
}
|