+2
-2
src/lib/constants.ts
+2
-2
src/lib/constants.ts
···
23
23
/** Maximum collision resolution attempts */
24
24
MAX_COLLISION_ATTEMPTS: 20,
25
25
26
-
/** Base70 character set (includes special characters) */
27
-
BASE62_CHARS: '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ+=_-?<>'
26
+
/** character set */
27
+
CHARS: '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
28
28
} as const;
29
29
30
30
/**
+9
-9
src/lib/utils/encoding.ts
+9
-9
src/lib/utils/encoding.ts
···
5
5
import { SHORTCODE } from '$lib/constants';
6
6
7
7
/**
8
-
* Base70 characters used for encoding (0-9, a-z, A-Z, and special chars: +=_-?<>)
8
+
* characters used for encoding (0-9, a-z, A-Z)
9
9
*/
10
-
const BASE_CHARS = SHORTCODE.BASE62_CHARS;
10
+
const BASE_CHARS = SHORTCODE.CHARS;
11
11
const BASE = BASE_CHARS.length;
12
12
13
13
/**
···
29
29
* Encodes a number to base string
30
30
* @param num - Number to encode
31
31
* @param length - Target length of the encoded string
32
-
* @returns Base70 encoded string
32
+
* @returns encoded string
33
33
*/
34
34
function toBase(num: number, length: number): string {
35
35
let encoded = '';
···
41
41
}
42
42
43
43
/**
44
-
* Encodes a URL to a short base70 string
45
-
* Uses a deterministic hash-to-base70 encoding
44
+
* Encodes a URL to a short string
45
+
* Uses a deterministic hash encoding
46
46
*
47
47
* @param url - URL to encode
48
48
* @param length - Target length of the shortcode (default: 6)
49
-
* @returns Short base70 encoded string
49
+
* @returns Short encoded string
50
50
*
51
51
* @example
52
52
* encodeUrl('https://github.com/user') // Returns something like 'a3k9zx'
···
57
57
}
58
58
59
59
/**
60
-
* Validates if a string is a valid base70 shortcode
60
+
* Validates if a string is a valid shortcode
61
61
* @param code - String to validate
62
62
* @returns True if the code contains only valid characters
63
63
*/
64
64
export function isValidShortcode(code: string): boolean {
65
-
return /^[0-9a-zA-Z+=_\-?<>]+$/.test(code);
65
+
return /^[0-9a-zA-Z]+$/.test(code);
66
66
}
67
67
68
68
/**
···
71
71
* @returns Number of possible combinations
72
72
*
73
73
* @example
74
-
* getMaxCombinations(6) // Returns 117649000000 (70^6)
74
+
* getMaxCombinations(6)
75
75
*/
76
76
export function getMaxCombinations(length: number): number {
77
77
return Math.pow(BASE, length);