Skip to content

Commit e0ec840

Browse files
authoredApr 7, 2020
fix: add CommonJS syntax example to README quickstart section (#417)
1 parent ec3daf2 commit e0ec840

File tree

2 files changed

+35
-18
lines changed

2 files changed

+35
-18
lines changed
 

‎README.md

+25-17
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ For the creation of [RFC4122](http://www.ietf.org/rfc/rfc4122.txt) UUIDs
2020
**Upgrading from uuid\@3?** Your code is probably okay, but check out [Upgrading
2121
From uuid\@3](#upgrading-from-uuid3) for details.
2222

23-
## Quickstart - Node.js/CommonJS
23+
## Quickstart
2424

2525
```shell
2626
npm install uuid
@@ -38,16 +38,25 @@ versions, all of which are supported here. In order of popularity, they are:
3838

3939
### Create Version 4 (Random) UUIDs
4040

41+
ECMAScript Module syntax:
42+
4143
```javascript
4244
import { v4 as uuidv4 } from 'uuid';
4345
uuidv4(); // ⇨ '9b1deb4d-3b7d-4bad-9bdd-2b0d7b3dcb6d'
4446
```
4547

48+
CommonJS syntax:
49+
50+
```javascript
51+
const { v4: uuidv4 } = require('uuid');
52+
uuidv4(); // ⇨ '1b9d6bcd-bbfd-4b2d-9b5d-ab8dfbbd4bed'
53+
```
54+
4655
### Create Version 1 (Timestamp) UUIDs
4756

4857
```javascript
4958
import { v1 as uuidv1 } from 'uuid';
50-
uuidv1(); // ⇨ '2c5ea4c0-4067-11e9-8b2d-1b9d6bcdbbfd'
59+
uuidv1(); // ⇨ '2c5ea4c0-4067-11e9-8bad-9b1deb4d3b7d'
5160
```
5261

5362
### Create Version 3 or Version 5 (Namespace) UUIDs
@@ -133,17 +142,17 @@ Example: Generate two IDs in a single buffer
133142
const buffer = new Array();
134143
uuidv4(null, buffer, 0); //
135144
// [
136-
// 155, 29, 235, 77, 59,
137-
// 125, 75, 173, 155, 221,
138-
// 43, 13, 123, 61, 203,
139-
// 109
145+
// 27, 157, 107, 205, 187,
146+
// 253, 75, 45, 155, 93,
147+
// 171, 141, 251, 189, 75,
148+
// 237
140149
// ]
141150
uuidv4(null, buffer, 16); //
142151
// [
143-
// 155, 29, 235, 77, 59, 125, 75, 173,
144-
// 155, 221, 43, 13, 123, 61, 203, 109,
145152
// 27, 157, 107, 205, 187, 253, 75, 45,
146-
// 155, 93, 171, 141, 251, 189, 75, 237
153+
// 155, 93, 171, 141, 251, 189, 75, 237,
154+
// 155, 29, 235, 77, 59, 125, 75, 173,
155+
// 155, 221, 43, 13, 123, 61, 203, 109
147156
// ]
148157
```
149158

@@ -193,17 +202,16 @@ Example: In-place generation of two binary IDs
193202
const arr = new Array();
194203
uuidv1(null, arr, 0); //
195204
// [
196-
// 44, 94, 164, 192, 64,
197-
// 103, 17, 233, 146, 52,
198-
// 27, 157, 107, 205, 187,
199-
// 253
205+
// 44, 94, 164, 192, 64, 103,
206+
// 17, 233, 146, 52, 155, 29,
207+
// 235, 77, 59, 125
200208
// ]
201209
uuidv1(null, arr, 16); //
202210
// [
203-
// 44, 94, 164, 192, 64, 103, 17, 233,
204-
// 146, 52, 27, 157, 107, 205, 187, 253,
205-
// 44, 94, 164, 193, 64, 103, 17, 233,
206-
// 146, 52, 27, 157, 107, 205, 187, 253
211+
// 44, 94, 164, 192, 64, 103, 17, 233,
212+
// 146, 52, 155, 29, 235, 77, 59, 125,
213+
// 44, 94, 164, 193, 64, 103, 17, 233,
214+
// 146, 52, 155, 29, 235, 77, 59, 125
207215
// ]
208216
```
209217

‎README_js.md

+10-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ For the creation of [RFC4122](http://www.ietf.org/rfc/rfc4122.txt) UUIDs
3333
**Upgrading from uuid\@3?** Your code is probably okay, but check out [Upgrading
3434
From uuid\@3](#upgrading-from-uuid3) for details.
3535

36-
## Quickstart - Node.js/CommonJS
36+
## Quickstart
3737

3838
```shell
3939
npm install uuid
@@ -51,11 +51,20 @@ versions, all of which are supported here. In order of popularity, they are:
5151

5252
### Create Version 4 (Random) UUIDs
5353

54+
ECMAScript Module syntax:
55+
5456
```javascript --run v4
5557
import { v4 as uuidv4 } from 'uuid';
5658
uuidv4(); // RESULT
5759
```
5860

61+
CommonJS syntax:
62+
63+
```javascript --run v4cjs
64+
const { v4: uuidv4 } = require('uuid');
65+
uuidv4(); // RESULT
66+
```
67+
5968
### Create Version 1 (Timestamp) UUIDs
6069

6170
```javascript --run v1

0 commit comments

Comments
 (0)
Please sign in to comment.