-
Notifications
You must be signed in to change notification settings - Fork 15
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
Showing
8 changed files
with
141 additions
and
22 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
55 changes: 55 additions & 0 deletions
55
scripts/generatePolyfill/customPolyfill/library/crypto.randomUUID/raw.js
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,55 @@ | ||
/** | ||
* 引自 [email protected] | ||
*/ | ||
|
||
/** | ||
* @source https://github.com/uuidjs/uuid/blob/v9.0.0/src/regex.js | ||
*/ | ||
const REGEX = /^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000)$/i; | ||
|
||
/** | ||
* @source https://github.com/uuidjs/uuid/blob/v9.0.0/src/validate.js | ||
*/ | ||
const validate = (uuid) => "string" === typeof uuid && REGEX.test(uuid); | ||
|
||
/** | ||
* @source https://github.com/uuidjs/uuid/blob/v9.0.0/src/rng-browser.js | ||
*/ | ||
const rnds8 = new Uint8Array(16); | ||
const rng = () => crypto.getRandomValues(rnds8); | ||
|
||
/** | ||
* @source https://github.com/uuidjs/uuid/blob/v9.0.0/src/stringify.js | ||
*/ | ||
const byteToHex = []; | ||
for (let i = 0; i < 256; ++i) { | ||
byteToHex.push((i + 256).toString(16).substring(1)); | ||
} | ||
const unsafeStringify = (arr, offset = 0) => `${byteToHex[arr[offset + 0]]}${byteToHex[arr[offset + 1]]}${byteToHex[arr[offset + 2]]}${byteToHex[arr[offset + 3]]}-${byteToHex[arr[offset + 4]]}${byteToHex[arr[offset + 5]]}-${byteToHex[arr[offset + 6]]}${byteToHex[arr[offset + 7]]}-${byteToHex[arr[offset + 8]]}${byteToHex[arr[offset + 9]]}-${byteToHex[arr[offset + 10]]}${byteToHex[arr[offset + 11]]}${byteToHex[arr[offset + 12]]}${byteToHex[arr[offset + 13]]}${byteToHex[arr[offset + 14]]}${byteToHex[arr[offset + 15]]}`.toLowerCase(); | ||
|
||
/** | ||
* @source https://github.com/uuidjs/uuid/blob/v9.0.0/src/v4.js | ||
*/ | ||
const v4 = (options = {}, buf, offset = 0) => { | ||
const rnds = options.random || (options.rng || rng)(); | ||
rnds[6] = rnds[6] & 0x0f | 0x40; | ||
rnds[8] = rnds[8] & 0x3f | 0x80; | ||
if (buf) { | ||
for (let i = 0; i < 16; ++i) { | ||
buf[offset + i] = rnds[i]; | ||
} | ||
return buf; | ||
} | ||
return unsafeStringify(rnds); | ||
}; | ||
|
||
/** | ||
* main polyfill | ||
*/ | ||
try { | ||
if (!validate(crypto.randomUUID())) { | ||
throw void 0; | ||
} | ||
} catch { | ||
crypto.randomUUID = () => 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
{ | ||
"crypto.randomUUID": { | ||
"aliases": [ | ||
"default" | ||
], | ||
"spec": "https://w3c.github.io/webcrypto/#Crypto-method-randomUUID", | ||
"docs": "https://developer.mozilla.org/en-US/docs/Web/API/Crypto/randomUUID", | ||
"notes": [ | ||
"In [email protected], there is no polyfill for this feature." | ||
], | ||
"browsers": { | ||
"android": "<92", | ||
"chrome": "<92", | ||
"edge": "<92", | ||
"edge_mob": "<92", | ||
"firefox": "<95", | ||
"firefox_mob": "<95", | ||
"ios_saf": "<15.4", | ||
"op_mini": "<65", | ||
"opera": "<78", | ||
"safari": "<15.4", | ||
"samsung_mob": "<16.0" | ||
}, | ||
"baseDir": "crypto.randomUUID", | ||
"hasTests": false, | ||
"isTestable": false, | ||
"isPublic": true, | ||
"size": 2063 | ||
} | ||
} |
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 @@ | ||
{ | ||
"type": "commonjs" | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,13 @@ | ||
{ | ||
"extends": "./tsconfig.json", | ||
"compilerOptions": { | ||
"outDir": "./dist/", | ||
"baseUrl": "./", | ||
"rootDir": "./src/", | ||
"target": "ES3", | ||
"ignoreDeprecations": "5.0", | ||
}, | ||
"exclude": [ | ||
"scripts", | ||
], | ||
} |