From f34e37bce823441cd9cf7ce4e99f49bfccd10816 Mon Sep 17 00:00:00 2001 From: Sebastian Scholl Date: Fri, 6 Nov 2020 09:18:22 +0100 Subject: [PATCH 1/6] docs: fix typo in readme (#530) --- README.md | 2 +- README_js.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 6cea0393..3910ed41 100644 --- a/README.md +++ b/README.md @@ -246,7 +246,7 @@ uuidv4(v4options); // ⇨ '109156be-c4fb-41ea-b1b4-efe1671c5836' ### uuid.v5(name, namespace[, buffer[, offset]]) -Createa an RFC version 5 (namespace w/ SHA-1) UUID +Create an RFC version 5 (namespace w/ SHA-1) UUID | | | | --- | --- | diff --git a/README_js.md b/README_js.md index 6dbd05b9..f0a70e40 100644 --- a/README_js.md +++ b/README_js.md @@ -252,7 +252,7 @@ uuidv4(v4options); // RESULT ### uuid.v5(name, namespace[, buffer[, offset]]) -Createa an RFC version 5 (namespace w/ SHA-1) UUID +Create an RFC version 5 (namespace w/ SHA-1) UUID | | | | --- | --- | From f3bd455da03e35ca4466c55a455e599f1566ffa2 Mon Sep 17 00:00:00 2001 From: Christoph Tavan Date: Mon, 9 Nov 2020 13:35:42 +0100 Subject: [PATCH 2/6] docs: fix react-native link from preface --- README.md | 2 +- README_js.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 3910ed41..11b7cc7e 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ For the creation of [RFC4122](http://www.ietf.org/rfc/rfc4122.txt) UUIDs - Node 8, 10, 12, 14 - Chrome, Safari, Firefox, Edge, IE 11 browsers - Webpack and rollup.js module bundlers - - [React Native / Expo](#react-native-expo) + - [React Native / Expo](#react-native--expo) - **Secure** - Cryptographically-strong random values - **Small** - Zero-dependency, small footprint, plays nice with "tree shaking" packagers - **CLI** - Includes the [`uuid` command line](#command-line) utility diff --git a/README_js.md b/README_js.md index f0a70e40..a2769a22 100644 --- a/README_js.md +++ b/README_js.md @@ -24,7 +24,7 @@ For the creation of [RFC4122](http://www.ietf.org/rfc/rfc4122.txt) UUIDs - Node 8, 10, 12, 14 - Chrome, Safari, Firefox, Edge, IE 11 browsers - Webpack and rollup.js module bundlers - - [React Native / Expo](#react-native-expo) + - [React Native / Expo](#react-native--expo) - **Secure** - Cryptographically-strong random values - **Small** - Zero-dependency, small footprint, plays nice with "tree shaking" packagers - **CLI** - Includes the [`uuid` command line](#command-line) utility From 16c8f6df2f6b09b4d6235602d6a591188320a82e Mon Sep 17 00:00:00 2001 From: Drew Thaler Date: Sat, 21 Nov 2020 04:38:48 -0800 Subject: [PATCH 3/6] fix: lazy load getRandomValues (#537) Without this change, React Native projects must manage an implicit dependency on `react-native-get-random-values`, and try to ensure that it gets loaded before `uuid` does. With this change, the React Native polyfill simply needs to be installed sometime before the first uuid is created. Fixes #536 --- src/rng-browser.js | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/src/rng-browser.js b/src/rng-browser.js index 1af1e4c9..38ed20ba 100644 --- a/src/rng-browser.js +++ b/src/rng-browser.js @@ -2,23 +2,27 @@ // require the crypto API and do not support built-in fallback to lower quality random number // generators (like Math.random()). -// getRandomValues needs to be invoked in a context where "this" is a Crypto implementation. Also, -// find the complete implementation of crypto (msCrypto) on IE11. -const getRandomValues = - (typeof crypto !== 'undefined' && - crypto.getRandomValues && - crypto.getRandomValues.bind(crypto)) || - (typeof msCrypto !== 'undefined' && - typeof msCrypto.getRandomValues === 'function' && - msCrypto.getRandomValues.bind(msCrypto)); +let getRandomValues; const rnds8 = new Uint8Array(16); export default function rng() { + // lazy load so that environments that need to polyfill have a chance to do so if (!getRandomValues) { - throw new Error( - 'crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported' - ); + // getRandomValues needs to be invoked in a context where "this" is a Crypto implementation. Also, + // find the complete implementation of crypto (msCrypto) on IE11. + getRandomValues = + (typeof crypto !== 'undefined' && + crypto.getRandomValues && + crypto.getRandomValues.bind(crypto)) || + (typeof msCrypto !== 'undefined' && + typeof msCrypto.getRandomValues === 'function' && + msCrypto.getRandomValues.bind(msCrypto)); + if (!getRandomValues) { + throw new Error( + 'crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported' + ); + } } return getRandomValues(rnds8); From 334ef62c330d92f8ca376d09087e8ee9abc5cc12 Mon Sep 17 00:00:00 2001 From: Christoph Tavan Date: Sat, 21 Nov 2020 14:08:43 +0100 Subject: [PATCH 4/6] chore(release): 8.3.2-beta.0 --- package-lock.json | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/package-lock.json b/package-lock.json index 8cae0822..c17be37a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "uuid", - "version": "8.3.1", + "version": "8.3.2-beta.0", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 5c5ab2a4..305eae7a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "uuid", - "version": "8.3.1", + "version": "8.3.2-beta.0", "description": "RFC4122 (v1, v4, and v5) UUIDs", "commitlint": { "extends": [ From df0f5d1957d83b377e637457df26d1feb69dcfd6 Mon Sep 17 00:00:00 2001 From: Joseph Mearman Date: Tue, 8 Dec 2020 20:31:54 +0000 Subject: [PATCH 5/6] docs: add examples of per-version validation (#543) --- README.md | 17 +++++++++++++++++ README_js.md | 17 +++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/README.md b/README.md index 11b7cc7e..ed27e576 100644 --- a/README.md +++ b/README.md @@ -296,6 +296,23 @@ uuidValidate('not a UUID'); // ⇨ false uuidValidate('6ec0bd7f-11c0-43da-975e-2a8ad9ebae0b'); // ⇨ true ``` +Using `validate` and `version` together it is possible to do per-version validation, e.g. validate for only v4 UUIds. + +```javascript +import { version as uuidVersion } from 'uuid'; +import { validate as uuidValidate } from 'uuid'; + +function uuidValidateV4(uuid) { + return uuidValidate(uuid) && uuidVersion(uuid) === 4; +} + +const v1Uuid = 'd9428888-122b-11e1-b85c-61cd3cbb3210'; +const v4Uuid = '109156be-c4fb-41ea-b1b4-efe1671c5836'; + +uuidValidateV4(v4Uuid); // ⇨ true +uuidValidateV4(v1Uuid); // ⇨ false +``` + ### uuid.version(str) Detect RFC version of a UUID diff --git a/README_js.md b/README_js.md index a2769a22..0e858a47 100644 --- a/README_js.md +++ b/README_js.md @@ -302,6 +302,23 @@ uuidValidate('not a UUID'); // RESULT uuidValidate('6ec0bd7f-11c0-43da-975e-2a8ad9ebae0b'); // RESULT ``` +Using `validate` and `version` together it is possible to do per-version validation, e.g. validate for only v4 UUIds. + +```javascript --run +import { version as uuidVersion } from 'uuid'; +import { validate as uuidValidate } from 'uuid'; + +function uuidValidateV4(uuid) { + return uuidValidate(uuid) && uuidVersion(uuid) === 4; +} + +const v1Uuid = 'd9428888-122b-11e1-b85c-61cd3cbb3210'; +const v4Uuid = '109156be-c4fb-41ea-b1b4-efe1671c5836'; + +uuidValidateV4(v4Uuid); // RESULT +uuidValidateV4(v1Uuid); // RESULT +``` + ### uuid.version(str) Detect RFC version of a UUID From ed3240154759b748f6a3b7d545f3b10759ee4ba7 Mon Sep 17 00:00:00 2001 From: Christoph Tavan Date: Tue, 8 Dec 2020 21:38:05 +0100 Subject: [PATCH 6/6] chore(release): 8.3.2 --- CHANGELOG.md | 6 ++++++ package-lock.json | 2 +- package.json | 2 +- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bcefac2f..7519d19d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,12 @@ All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines. +### [8.3.2](https://github.com/uuidjs/uuid/compare/v8.3.1...v8.3.2) (2020-12-08) + +### Bug Fixes + +- lazy load getRandomValues ([#537](https://github.com/uuidjs/uuid/issues/537)) ([16c8f6d](https://github.com/uuidjs/uuid/commit/16c8f6df2f6b09b4d6235602d6a591188320a82e)), closes [#536](https://github.com/uuidjs/uuid/issues/536) + ### [8.3.1](https://github.com/uuidjs/uuid/compare/v8.3.0...v8.3.1) (2020-10-04) ### Bug Fixes diff --git a/package-lock.json b/package-lock.json index c17be37a..787509be 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "uuid", - "version": "8.3.2-beta.0", + "version": "8.3.2", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 305eae7a..f0ab3711 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "uuid", - "version": "8.3.2-beta.0", + "version": "8.3.2", "description": "RFC4122 (v1, v4, and v5) UUIDs", "commitlint": { "extends": [