-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5a0254b
commit c1b3e13
Showing
6 changed files
with
28 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,16 @@ | ||
// @ts-nocheck | ||
// https://github.com/ai/nanoid | ||
// Currently does not support commonjs imports, so we copypasta this file here | ||
import { webcrypto } from 'crypto'; | ||
export type CryptoModule = { | ||
getRandomValues<T extends ArrayBufferView | null>(array: T): T; | ||
}; | ||
|
||
export const nanoid = (t = 21) => | ||
webcrypto | ||
.getRandomValues(new Uint8Array(t)) | ||
.reduce( | ||
(t: any, e: any) => | ||
(t += (e &= 63) < 36 ? e.toString(36) : e < 62 ? (e - 26).toString(36).toUpperCase() : e < 63 ? '_' : '-'), | ||
'', | ||
); | ||
// cross compatible nanoid implementation from | ||
// https://github.com/ai/nanoid | ||
export const nanoid = | ||
(crypto: CryptoModule) => | ||
(t = 21) => | ||
crypto | ||
.getRandomValues(new Uint8Array(t)) | ||
.reduce( | ||
(t: any, e: any) => | ||
(t += (e &= 63) < 36 ? e.toString(36) : e < 62 ? (e - 26).toString(36).toUpperCase() : e < 63 ? '_' : '-'), | ||
'', | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { webcrypto } from 'node:crypto'; | ||
|
||
import { nanoid } from '@envy/core'; | ||
|
||
export const generateId = nanoid(webcrypto as any); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import { nanoid } from '@envy/core'; | ||
|
||
export const generateId = nanoid(crypto); |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters