Skip to content

Commit

Permalink
feat: add typescript support
Browse files Browse the repository at this point in the history
  • Loading branch information
Tienisto committed Sep 22, 2024
1 parent 396b78a commit aaf6e42
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"version": "0.0.3",
"description": "A library to generate URL-friendly, unique, and short IDs that are sortable by time. Inspired by nanoid and UUIDv7.",
"main": "./src/tempoId.js",
"types": "./src/tempoId.d.ts",
"type": "module",
"scripts": {
"test": "node test/test.js"
Expand Down
53 changes: 53 additions & 0 deletions src/tempoid.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
export declare const Alphabet: {
readonly numbers: string;
readonly hexadecimalLowercase: string;
readonly hexadecimalUppercase: string;
readonly lowercase: string;
readonly uppercase: string;
readonly alphanumeric: string;
readonly url: string;
readonly base64: string;
readonly noDoppelganger: string;
};

export interface TempoIdOptions {
/**
* Length of the time part. Defaults to 8.
*/
timeLength?: number;

/**
* Length of the random part. Defaults to 13.
*/
randomLength?: number;

/**
* Custom time value in milliseconds.
*/
time?: number;

/**
* Custom start time.
*/
startTime?: Date;

/**
* Whether to pad the time part on the left. Defaults to true.
*/
padLeft?: boolean;

/**
* Custom alphabet to use.
*/
alphabet?: string;
}

/**
* Generates a new TempoId with a time part and a random part.
* The total length of the ID will be the sum of `timeLength`
* and `randomLength`. Both default to 8 for `timeLength` and 13 for `randomLength`.
*
* @param options - The options for generating the TempoId.
* @returns The generated TempoId.
*/
export declare function tempoId(options?: TempoIdOptions): string;

0 comments on commit aaf6e42

Please sign in to comment.