diff --git a/snippets/UUIDGenerator.md b/snippets/UUIDGeneratorBrowser.md similarity index 64% rename from snippets/UUIDGenerator.md rename to snippets/UUIDGeneratorBrowser.md index 2d11c5540..3fc752f95 100644 --- a/snippets/UUIDGenerator.md +++ b/snippets/UUIDGeneratorBrowser.md @@ -1,16 +1,16 @@ -### UUIDGenerator +### UUIDGeneratorBrowser -Generates a UUID. +Generates a UUID in a browser. Use `crypto` API to generate a UUID, compliant with [RFC4122](https://www.ietf.org/rfc/rfc4122.txt) version 4. ```js -const UUIDGenerator = () => +const UUIDGeneratorBrowser = () => ([1e7] + -1e3 + -4e3 + -8e3 + -1e11).replace(/[018]/g, c => (c ^ (crypto.getRandomValues(new Uint8Array(1))[0] & (15 >> (c / 4)))).toString(16) ); ``` ```js -UUIDGenerator(); // '7982fcfe-5721-4632-bede-6000885be57d' +UUIDGeneratorBrowser(); // '7982fcfe-5721-4632-bede-6000885be57d' ``` diff --git a/snippets/UUIDGeneratorNode.md b/snippets/UUIDGeneratorNode.md new file mode 100644 index 000000000..d218fab70 --- /dev/null +++ b/snippets/UUIDGeneratorNode.md @@ -0,0 +1,17 @@ +### UUIDGeneratorNode + +Generates a UUID in Node.JS. + +Use `crypto` API to generate a UUID, compliant with [RFC4122](https://www.ietf.org/rfc/rfc4122.txt) version 4. + +```js +const crypto = require("crypto"); +const UUIDGeneratorNode = () => + ([1e7] + -1e3 + -4e3 + -8e3 + -1e11).replace(/[018]/g, c => + (c ^ (crypto.randomBytes(1)[0] & (15 >> (c / 4)))).toString(16) + ); +``` + +```js +UUIDGeneratorNode(); // '79c7c136-60ee-40a2-beb2-856f1feabefc' +``` diff --git a/tag_database b/tag_database index b9b43e79c..5f4e45246 100644 --- a/tag_database +++ b/tag_database @@ -139,7 +139,8 @@ toSnakeCase:string truncateString:string truthCheckCollection:object union:array -UUIDGenerator:utility +UUIDGeneratorBrowser:browser +UUIDGeneratorNode:node validateNumber:utility without:array words:string