@getpaseo/protocol 0.1.84 → 0.1.86

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.
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Validate that a string is a valid git branch name slug.
3
+ * Must be lowercase alphanumeric with hyphens and forward slashes only.
4
+ */
5
+ export declare function validateBranchSlug(slug: string): {
6
+ valid: boolean;
7
+ error?: string;
8
+ };
9
+ export declare const MAX_SLUG_LENGTH = 50;
10
+ /**
11
+ * Convert a string to kebab-case for branch names.
12
+ */
13
+ export declare function slugify(input: string): string;
14
+ //# sourceMappingURL=branch-slug.d.ts.map
@@ -0,0 +1,49 @@
1
+ /**
2
+ * Validate that a string is a valid git branch name slug.
3
+ * Must be lowercase alphanumeric with hyphens and forward slashes only.
4
+ */
5
+ export function validateBranchSlug(slug) {
6
+ if (!slug || slug.length === 0) {
7
+ return { valid: false, error: "Branch name cannot be empty" };
8
+ }
9
+ if (slug.length > 100) {
10
+ return { valid: false, error: "Branch name too long (max 100 characters)" };
11
+ }
12
+ const validPattern = /^[a-z0-9-/]+$/;
13
+ if (!validPattern.test(slug)) {
14
+ return {
15
+ valid: false,
16
+ error: "Branch name must contain only lowercase letters, numbers, hyphens, and forward slashes",
17
+ };
18
+ }
19
+ if (slug.startsWith("-") || slug.endsWith("-")) {
20
+ return {
21
+ valid: false,
22
+ error: "Branch name cannot start or end with a hyphen",
23
+ };
24
+ }
25
+ if (slug.includes("--")) {
26
+ return { valid: false, error: "Branch name cannot have consecutive hyphens" };
27
+ }
28
+ return { valid: true };
29
+ }
30
+ export const MAX_SLUG_LENGTH = 50;
31
+ /**
32
+ * Convert a string to kebab-case for branch names.
33
+ */
34
+ export function slugify(input) {
35
+ const slug = input
36
+ .toLowerCase()
37
+ .replace(/[^a-z0-9]+/g, "-")
38
+ .replace(/^-+|-+$/g, "");
39
+ if (slug.length <= MAX_SLUG_LENGTH) {
40
+ return slug;
41
+ }
42
+ const truncated = slug.slice(0, MAX_SLUG_LENGTH);
43
+ const lastHyphen = truncated.lastIndexOf("-");
44
+ if (lastHyphen > MAX_SLUG_LENGTH / 2) {
45
+ return truncated.slice(0, lastHyphen);
46
+ }
47
+ return truncated.replace(/-+$/, "");
48
+ }
49
+ //# sourceMappingURL=branch-slug.js.map