diff --git a/README.md b/README.md index bd837dc1d..bde7d8eff 100644 --- a/README.md +++ b/README.md @@ -100,6 +100,7 @@ * [`setStyle`](#setstyle) * [`show`](#show) * [`toggleClass`](#toggleclass) +* [`UUIDGeneratorBrowser`](#uuidgeneratorbrowser) @@ -189,6 +190,7 @@ * [`JSONToFile`](#jsontofile) * [`readFileLines`](#readfilelines) +* [`UUIDGeneratorNode`](#uuidgeneratornode) @@ -251,7 +253,6 @@ * [`timeTaken`](#timetaken) * [`toDecimalMark`](#todecimalmark) * [`toOrdinalSuffix`](#toordinalsuffix) -* [`UUIDGenerator`](#uuidgenerator) * [`validateNumber`](#validatenumber) @@ -1979,6 +1980,32 @@ toggleClass(document.querySelector('p.special'), 'special'); // The paragraph wi +[⬆ Back to top](#table-of-contents) + + +### UUIDGeneratorBrowser + +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 UUIDGeneratorBrowser = () => + ([1e7] + -1e3 + -4e3 + -8e3 + -1e11).replace(/[018]/g, c => + (c ^ (crypto.getRandomValues(new Uint8Array(1))[0] & (15 >> (c / 4)))).toString(16) + ); +``` + +
+Examples + +```js +UUIDGeneratorBrowser(); // '7982fcfe-5721-4632-bede-6000885be57d' +``` + +
+ + [⬆ Back to top](#table-of-contents) ## Date @@ -3083,6 +3110,33 @@ console.log(arr); // ['line1', 'line2', 'line3'] +[⬆ Back to top](#table-of-contents) + + +### 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) + ); +``` + +
+Examples + +```js +UUIDGeneratorNode(); // '79c7c136-60ee-40a2-beb2-856f1feabefc' +``` + +
+ + [⬆ Back to top](#table-of-contents) ## Object @@ -4130,32 +4184,6 @@ toOrdinalSuffix('123'); // "123rd" [⬆ Back to top](#table-of-contents) -### UUIDGenerator - -Generates a UUID. - -Use `crypto` API to generate a UUID, compliant with [RFC4122](https://www.ietf.org/rfc/rfc4122.txt) version 4. - -```js -const UUIDGenerator = () => - ([1e7] + -1e3 + -4e3 + -8e3 + -1e11).replace(/[018]/g, c => - (c ^ (crypto.getRandomValues(new Uint8Array(1))[0] & (15 >> (c / 4)))).toString(16) - ); -``` - -
-Examples - -```js -UUIDGenerator(); // '7982fcfe-5721-4632-bede-6000885be57d' -``` - -
- - -[⬆ Back to top](#table-of-contents) - - ### validateNumber Returns `true` if the given value is a number, `false` otherwise. diff --git a/docs/index.html b/docs/index.html index ffe40d5df..9fbd42386 100644 --- a/docs/index.html +++ b/docs/index.html @@ -169,6 +169,7 @@ setStyle show toggleClass +UUIDGeneratorBrowser

Date

getDaysDiffBetweenDates @@ -222,6 +223,7 @@

Node

JSONToFile readFileLines +UUIDGeneratorNode

Object

cleanObj @@ -266,7 +268,6 @@ timeTaken toDecimalMark toOrdinalSuffix -UUIDGenerator validateNumber
 

Adapter

@@ -937,6 +938,16 @@ Scroll by a fraction of the distance from the top. Use window.requestAnima
toggleClass(document.querySelector('p.special'), 'special'); // The paragraph will not have the 'special' class anymore
 
+

UUIDGeneratorBrowser

+

Generates a UUID in a browser.

+

Use crypto API to generate a UUID, compliant with RFC4122 version 4.

+
const UUIDGeneratorBrowser = () =>
+  ([1e7] + -1e3 + -4e3 + -8e3 + -1e11).replace(/[018]/g, c =>
+    (c ^ (crypto.getRandomValues(new Uint8Array(1))[0] & (15 >> (c / 4)))).toString(16)
+  );
+
+
UUIDGeneratorBrowser(); // '7982fcfe-5721-4632-bede-6000885be57d'
+

Date

getDaysDiffBetweenDates

Returns the difference (in days) between two dates.

@@ -1384,6 +1395,17 @@ contents of test.txt : let arr = readFileLines('test.txt'); console.log(arr); // ['line1', 'line2', 'line3'] +

UUIDGeneratorNode

+

Generates a UUID in Node.JS.

+

Use crypto API to generate a UUID, compliant with RFC4122 version 4.

+
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)
+  );
+
+
UUIDGeneratorNode(); // '79c7c136-60ee-40a2-beb2-856f1feabefc'
+

Object

cleanObj

Removes any properties except the ones specified from a JSON object.

@@ -1823,16 +1845,6 @@ If digit is found in teens pattern, use teens ordinal.

toOrdinalSuffix('123'); // "123rd"
 
-

UUIDGenerator

-

Generates a UUID.

-

Use crypto API to generate a UUID, compliant with RFC4122 version 4.

-
const UUIDGenerator = () =>
-  ([1e7] + -1e3 + -4e3 + -8e3 + -1e11).replace(/[018]/g, c =>
-    (c ^ (crypto.getRandomValues(new Uint8Array(1))[0] & (15 >> (c / 4)))).toString(16)
-  );
-
-
UUIDGenerator(); // '7982fcfe-5721-4632-bede-6000885be57d'
-

validateNumber

Returns true if the given value is a number, false otherwise.

Use !isNaN in combination with parseFloat() to check if the argument is a number. diff --git a/snippets/UUIDGeneratorNode.md b/snippets/UUIDGeneratorNode.md index d218fab70..bbcb51b8f 100644 --- a/snippets/UUIDGeneratorNode.md +++ b/snippets/UUIDGeneratorNode.md @@ -5,7 +5,7 @@ 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 crypto = require('crypto'); const UUIDGeneratorNode = () => ([1e7] + -1e3 + -4e3 + -8e3 + -1e11).replace(/[018]/g, c => (c ^ (crypto.randomBytes(1)[0] & (15 >> (c / 4)))).toString(16)