From eb12529fe8dc35d70c96b4b9139d1aab60a7b89e Mon Sep 17 00:00:00 2001 From: Jake Verbaten Date: Tue, 7 Apr 2020 16:13:34 +0200 Subject: [PATCH 1/2] Add an example of how to use the module to the README Place the example using `require` as high up in the README as is sensible. --- README.md | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 2b7c2cf1..52d29655 100644 --- a/README.md +++ b/README.md @@ -36,14 +36,21 @@ versions, all of which are supported here. In order of popularity, they are: **Unsure which one to use?** Use version 4 (random) unless you have a specific need for one of the other versions. See also [this FAQ](https://github.com/tc39/proposal-uuid#faq). -### Create Version 4 (Random) UUIDs +### Create Version 4 (Random) UUIDs (ESM) ```javascript import { v4 as uuidv4 } from 'uuid'; uuidv4(); // ⇨ '9b1deb4d-3b7d-4bad-9bdd-2b0d7b3dcb6d' ``` -### Create Version 1 (Timestamp) UUIDs +### Create Version 4 (Random) UUIDs + +```javascript +const uuidv4 = require('uuid').v4 +uuidv4(); // ⇨ '9b1deb4d-3b7d-4bad-9bdd-2b0d7b3dcb6d' +``` + +### Create Version 1 (Timestamp) UUIDs (ESM) ```javascript import { v1 as uuidv1 } from 'uuid'; @@ -403,4 +410,4 @@ const uuid = require('uuid'); // <== REMOVED! This usage pattern was already discouraged in uuid\@3 and has been removed in uuid\@7. ---- -Markdown generated from [README_js.md](README_js.md) by [![RunMD Logo](http://i.imgur.com/h0FVyzU.png)](https://github.com/broofa/runmd) \ No newline at end of file +Markdown generated from [README_js.md](README_js.md) by [![RunMD Logo](http://i.imgur.com/h0FVyzU.png)](https://github.com/broofa/runmd) From c071cbeba4cd542eb22774bab38e4b37d9e55fe1 Mon Sep 17 00:00:00 2001 From: Christoph Tavan Date: Tue, 7 Apr 2020 20:03:13 +0200 Subject: [PATCH 2/2] fixup! Add an example of how to use the module to the README --- README.md | 47 ++++++++++++++++++++++++----------------------- README_js.md | 11 ++++++++++- 2 files changed, 34 insertions(+), 24 deletions(-) diff --git a/README.md b/README.md index 52d29655..e38b6900 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,7 @@ For the creation of [RFC4122](http://www.ietf.org/rfc/rfc4122.txt) UUIDs **Upgrading from uuid\@3?** Your code is probably okay, but check out [Upgrading From uuid\@3](#upgrading-from-uuid3) for details. -## Quickstart - Node.js/CommonJS +## Quickstart ```shell npm install uuid @@ -36,25 +36,27 @@ versions, all of which are supported here. In order of popularity, they are: **Unsure which one to use?** Use version 4 (random) unless you have a specific need for one of the other versions. See also [this FAQ](https://github.com/tc39/proposal-uuid#faq). -### Create Version 4 (Random) UUIDs (ESM) +### Create Version 4 (Random) UUIDs + +ECMAScript Module syntax: ```javascript import { v4 as uuidv4 } from 'uuid'; uuidv4(); // ⇨ '9b1deb4d-3b7d-4bad-9bdd-2b0d7b3dcb6d' ``` -### Create Version 4 (Random) UUIDs +CommonJS syntax: ```javascript -const uuidv4 = require('uuid').v4 -uuidv4(); // ⇨ '9b1deb4d-3b7d-4bad-9bdd-2b0d7b3dcb6d' +const { v4: uuidv4 } = require('uuid'); +uuidv4(); // ⇨ '1b9d6bcd-bbfd-4b2d-9b5d-ab8dfbbd4bed' ``` -### Create Version 1 (Timestamp) UUIDs (ESM) +### Create Version 1 (Timestamp) UUIDs ```javascript import { v1 as uuidv1 } from 'uuid'; -uuidv1(); // ⇨ '2c5ea4c0-4067-11e9-8b2d-1b9d6bcdbbfd' +uuidv1(); // ⇨ '2c5ea4c0-4067-11e9-8bad-9b1deb4d3b7d' ``` ### Create Version 3 or Version 5 (Namespace) UUIDs @@ -140,17 +142,17 @@ Example: Generate two IDs in a single buffer const buffer = new Array(); uuidv4(null, buffer, 0); // ⇨ // [ - // 155, 29, 235, 77, 59, - // 125, 75, 173, 155, 221, - // 43, 13, 123, 61, 203, - // 109 + // 27, 157, 107, 205, 187, + // 253, 75, 45, 155, 93, + // 171, 141, 251, 189, 75, + // 237 // ] uuidv4(null, buffer, 16); // ⇨ // [ - // 155, 29, 235, 77, 59, 125, 75, 173, - // 155, 221, 43, 13, 123, 61, 203, 109, // 27, 157, 107, 205, 187, 253, 75, 45, - // 155, 93, 171, 141, 251, 189, 75, 237 + // 155, 93, 171, 141, 251, 189, 75, 237, + // 155, 29, 235, 77, 59, 125, 75, 173, + // 155, 221, 43, 13, 123, 61, 203, 109 // ] ``` @@ -200,17 +202,16 @@ Example: In-place generation of two binary IDs const arr = new Array(); uuidv1(null, arr, 0); // ⇨ // [ - // 44, 94, 164, 192, 64, - // 103, 17, 233, 146, 52, - // 27, 157, 107, 205, 187, - // 253 + // 44, 94, 164, 192, 64, 103, + // 17, 233, 146, 52, 155, 29, + // 235, 77, 59, 125 // ] uuidv1(null, arr, 16); // ⇨ // [ - // 44, 94, 164, 192, 64, 103, 17, 233, - // 146, 52, 27, 157, 107, 205, 187, 253, - // 44, 94, 164, 193, 64, 103, 17, 233, - // 146, 52, 27, 157, 107, 205, 187, 253 + // 44, 94, 164, 192, 64, 103, 17, 233, + // 146, 52, 155, 29, 235, 77, 59, 125, + // 44, 94, 164, 193, 64, 103, 17, 233, + // 146, 52, 155, 29, 235, 77, 59, 125 // ] ``` @@ -410,4 +411,4 @@ const uuid = require('uuid'); // <== REMOVED! This usage pattern was already discouraged in uuid\@3 and has been removed in uuid\@7. ---- -Markdown generated from [README_js.md](README_js.md) by [![RunMD Logo](http://i.imgur.com/h0FVyzU.png)](https://github.com/broofa/runmd) +Markdown generated from [README_js.md](README_js.md) by [![RunMD Logo](http://i.imgur.com/h0FVyzU.png)](https://github.com/broofa/runmd) \ No newline at end of file diff --git a/README_js.md b/README_js.md index c5e3f248..345b53d4 100644 --- a/README_js.md +++ b/README_js.md @@ -33,7 +33,7 @@ For the creation of [RFC4122](http://www.ietf.org/rfc/rfc4122.txt) UUIDs **Upgrading from uuid\@3?** Your code is probably okay, but check out [Upgrading From uuid\@3](#upgrading-from-uuid3) for details. -## Quickstart - Node.js/CommonJS +## Quickstart ```shell npm install uuid @@ -51,11 +51,20 @@ versions, all of which are supported here. In order of popularity, they are: ### Create Version 4 (Random) UUIDs +ECMAScript Module syntax: + ```javascript --run v4 import { v4 as uuidv4 } from 'uuid'; uuidv4(); // RESULT ``` +CommonJS syntax: + +```javascript --run v4cjs +const { v4: uuidv4 } = require('uuid'); +uuidv4(); // RESULT +``` + ### Create Version 1 (Timestamp) UUIDs ```javascript --run v1