@@ -27,16 +27,16 @@ export namespace Identifier {
2727 let counter = 0
2828
2929 export function ascending ( prefix : keyof typeof prefixes , given ?: string ) {
30- return generateID ( prefix , false , given )
30+ return generateID ( prefix , "ascending" , given )
3131 }
3232
3333 export function descending ( prefix : keyof typeof prefixes , given ?: string ) {
34- return generateID ( prefix , true , given )
34+ return generateID ( prefix , "descending" , given )
3535 }
3636
37- function generateID ( prefix : keyof typeof prefixes , descending : boolean , given ?: string ) : string {
37+ function generateID ( prefix : keyof typeof prefixes , direction : "descending" | "ascending" , given ?: string ) : string {
3838 if ( ! given ) {
39- return create ( prefix , descending )
39+ return create ( prefixes [ prefix ] , direction )
4040 }
4141
4242 if ( ! given . startsWith ( prefixes [ prefix ] ) ) {
@@ -55,7 +55,7 @@ export namespace Identifier {
5555 return result
5656 }
5757
58- export function create ( prefix : keyof typeof prefixes , descending : boolean , timestamp ?: number ) : string {
58+ export function create ( prefix : string , direction : "descending" | "ascending" , timestamp ?: number ) : string {
5959 const currentTimestamp = timestamp ?? Date . now ( )
6060
6161 if ( currentTimestamp !== lastTimestamp ) {
@@ -66,14 +66,14 @@ export namespace Identifier {
6666
6767 let now = BigInt ( currentTimestamp ) * BigInt ( 0x1000 ) + BigInt ( counter )
6868
69- now = descending ? ~ now : now
69+ now = direction === " descending" ? ~ now : now
7070
7171 const timeBytes = Buffer . alloc ( 6 )
7272 for ( let i = 0 ; i < 6 ; i ++ ) {
7373 timeBytes [ i ] = Number ( ( now >> BigInt ( 40 - 8 * i ) ) & BigInt ( 0xff ) )
7474 }
7575
76- return prefixes [ prefix ] + "_" + timeBytes . toString ( "hex" ) + randomBase62 ( LENGTH - 12 )
76+ return prefix + "_" + timeBytes . toString ( "hex" ) + randomBase62 ( LENGTH - 12 )
7777 }
7878
7979 /** Extract timestamp from an ascending ID. Does not work with descending IDs. */
0 commit comments