Skip to content

Commit

Permalink
Merge pull request #335 from ctavan/prepare-for-esm
Browse files Browse the repository at this point in the history
Prepare for esm
  • Loading branch information
ctavan authored Oct 25, 2019
2 parents eea07e8 + d125e45 commit 60eb84a
Show file tree
Hide file tree
Showing 7 changed files with 190 additions and 225 deletions.
7 changes: 5 additions & 2 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@
"env": {
"browser": true,
"commonjs": true,
"node": true,
"mocha": true
"mocha": true,
"node": true
},
"extends": ["eslint:recommended"],
"globals": {
"msCrypto": true
},
"rules": {
"array-bracket-spacing": ["warn", "never"],
"arrow-body-style": ["warn", "as-needed"],
Expand Down
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
language: node_js
node_js:
- "6"
- "8"
- "10"
- "12"
41 changes: 14 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,23 +129,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, 155, 29,
// 235, 77, 59,
// 125
// 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, 155, 29,
// 235, 77, 59, 125,
// 44, 94, 164, 193,
// 64, 103, 17, 233,
// 146, 52, 155, 29,
// 235, 77, 59, 125
// 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
// ]

```
Expand Down Expand Up @@ -217,23 +210,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,
// 155, 29, 235, 77, 59,
// 125, 75, 173, 155, 221,
// 43, 13, 123, 61, 203,
// 109
// ]
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, 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
// ]

```
Expand Down
18 changes: 10 additions & 8 deletions lib/bytesToUuid.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,16 @@ function bytesToUuid(buf, offset) {
var i = offset || 0;
var bth = byteToHex;
// join used to fix memory issue caused by concatenation: https://bugs.chromium.org/p/v8/issues/detail?id=3175#c4
return ([bth[buf[i++]], bth[buf[i++]],
bth[buf[i++]], bth[buf[i++]], '-',
bth[buf[i++]], bth[buf[i++]], '-',
bth[buf[i++]], bth[buf[i++]], '-',
bth[buf[i++]], bth[buf[i++]], '-',
bth[buf[i++]], bth[buf[i++]],
bth[buf[i++]], bth[buf[i++]],
bth[buf[i++]], bth[buf[i++]]]).join('');
return ([
bth[buf[i++]], bth[buf[i++]],
bth[buf[i++]], bth[buf[i++]], '-',
bth[buf[i++]], bth[buf[i++]], '-',
bth[buf[i++]], bth[buf[i++]], '-',
bth[buf[i++]], bth[buf[i++]], '-',
bth[buf[i++]], bth[buf[i++]],
bth[buf[i++]], bth[buf[i++]],
bth[buf[i++]], bth[buf[i++]]
]).join('');
}

module.exports = bytesToUuid;
Loading

0 comments on commit 60eb84a

Please sign in to comment.