-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.d.ts
More file actions
37 lines (35 loc) · 1.29 KB
/
index.d.ts
File metadata and controls
37 lines (35 loc) · 1.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
/**
* Generate a short code from any string using SHA-256 and Base62 encoding.
* @param input - The string to shorten
* @param length - Output length (1-22, default: 8)
* @returns An alphanumeric code (0-9, A-Z, a-z) of the specified length
* @throws {TypeError} If input is missing, not a string, or empty
* @throws {RangeError} If input exceeds 64KB or length is out of range
* @example
* ```ts
* import { gen } from 'theshortener';
*
* const code = gen('https://google.com');
* console.log(code); // "Qhq1TQ2n"
*
* const short = gen('https://google.com', 6);
* console.log(short); // "Qhq1TQ"
* ```
*/
export function gen(input: string, length?: number): string;
/**
* Async version of gen(). Runs SHA-256 + Base62 encoding in a worker thread.
* @param input - The string to shorten
* @param length - Output length (1-22, default: 8)
* @returns Promise resolving to an alphanumeric code of the specified length
* @throws {TypeError} If input is missing, not a string, or empty
* @throws {RangeError} If input exceeds 64KB or length is out of range
* @example
* ```ts
* import { genAsync } from 'theshortener';
*
* const code = await genAsync('https://google.com');
* console.log(code); // "Qhq1TQ2n"
* ```
*/
export function genAsync(input: string, length?: number): Promise<string>;