-
Notifications
You must be signed in to change notification settings - Fork 10.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: move away from old default uuid (#33275)
* feat: move away from old default uuid * fix test * update uuid for v5 * fix import * move to secure algo
- Loading branch information
Showing
25 changed files
with
132 additions
and
48 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
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 |
---|---|---|
@@ -1,3 +1,2 @@ | ||
declare module "stream-filter" | ||
declare module "ansi-wordwrap" | ||
declare module 'uuid/v4'; |
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
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,27 @@ | ||
/** | ||
* Copied from https://github.com/lukeed/uuid | ||
* https://github.com/lukeed/uuid/blob/master/test/index.js | ||
*/ | ||
import isUUID from "is-uuid" | ||
import { v4 as uuid } from "../uuid" | ||
|
||
describe(`uuid`, () => { | ||
it(`returns`, () => { | ||
const out = uuid() | ||
expect(out).toHaveLength(36) | ||
expect(typeof out).toBe(`string`) | ||
}) | ||
|
||
it(`unique`, () => { | ||
const length = 1e6 | ||
expect(uuid()).not.toBe(uuid()) | ||
|
||
const unique = new Set(Array.from({ length }, uuid)) | ||
expect(unique.size).toBe(length) | ||
}) | ||
|
||
it(`validate`, () => { | ||
const arr = Array.from({ length: 1e3 }, uuid) | ||
expect(arr.map(item => isUUID.v4(item)).filter(Boolean)).toHaveLength(1e3) | ||
}) | ||
}) |
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,36 @@ | ||
/** | ||
* Copied from https://github.com/lukeed/uuid | ||
* https://github.com/lukeed/uuid/blob/master/src/secure.js | ||
*/ | ||
import { randomBytes } from "crypto" | ||
|
||
const SIZE = 4096 | ||
const HEX: Array<string> = [] | ||
let IDX = 0 | ||
let BUFFER: Buffer | ||
|
||
for (; IDX < 256; IDX++) { | ||
HEX[IDX] = (IDX + 256).toString(16).substring(1) | ||
} | ||
|
||
export function v4(): string { | ||
if (!BUFFER || IDX + 16 > SIZE) { | ||
BUFFER = randomBytes(SIZE) | ||
IDX = 0 | ||
} | ||
|
||
let i = 0 | ||
let tmp | ||
let out = `` | ||
for (; i < 16; i++) { | ||
tmp = BUFFER[IDX + i] | ||
if (i == 6) out += HEX[(tmp & 15) | 64] | ||
else if (i == 8) out += HEX[(tmp & 63) | 128] | ||
else out += HEX[tmp] | ||
|
||
if (i & 1 && i > 1 && i < 11) out += `-` | ||
} | ||
|
||
IDX += 16 | ||
return out | ||
} |
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
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
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
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
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
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
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
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
Oops, something went wrong.