Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: uuidjs/uuid
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: ab33c8a77df180de1a12fede423490b3c2de9d07
Choose a base ref
...
head repository: uuidjs/uuid
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 4cf24c018cead5ebe48cb4da232b57a2345d9fb5
Choose a head ref

Commits on Sep 1, 2019

  1. Remove wzrd.in from README (#323)

    * chore(doc): re-generate README
    
    * fix(doc): remove wzrd.in instruction from README
    
    The service wzrd.in seems to be unmaintained for over a year now, see
    browserify/wzrd.in@2f7ea69
    
    It currently throws 502 errors on all packages as reported in
    #302 or
    https://talk.observablehq.com/t/wzrd-in-alternatives/571
    
    As stated in
    #293 (comment)
    there are no plans to support legacy bundlers.
    
    Instead, we may consider to go for properly standardized ES6 modules in
    the future as has been teased in #317
    
    However for the time being let's at least remove these broken
    instructions from the README.
    
    Closes #176, #302
    ctavan authored and broofa committed Sep 1, 2019
    Copy the full SHA
    eea07e8 View commit details

Commits on Sep 23, 2019

  1. docs: re-generate README

    ctavan committed Sep 23, 2019
    Copy the full SHA
    b9fd85b View commit details

Commits on Oct 13, 2019

  1. test: remove tests on Node.js 6

    Node.js 6 has reached end-of-life at 2019-04-30 so there's little use of
    supporting this for future releases of uuid, see
    https://github.com/nodejs/Release#end-of-life-releases
    ctavan committed Oct 13, 2019
    Copy the full SHA
    edf430a View commit details
  2. Copy the full SHA
    b82ed2d View commit details
  3. Copy the full SHA
    bb2f9ae View commit details
  4. Copy the full SHA
    3bf178d View commit details
  5. Copy the full SHA
    2e9341f View commit details
  6. style: convert tabs to spaces

    ctavan committed Oct 13, 2019
    Copy the full SHA
    0c4638b View commit details
  7. Copy the full SHA
    b22219f View commit details
  8. Copy the full SHA
    acd26d6 View commit details
  9. Copy the full SHA
    d125e45 View commit details

Commits on Oct 25, 2019

  1. Merge pull request #335 from ctavan/prepare-for-esm

    Prepare for esm
    ctavan authored Oct 25, 2019
    Copy the full SHA
    60eb84a View commit details
  2. feat: hybrid CommonJS & ECMAScript modules build

    BREAKING CHANGE: Convert code base to ECMAScript Modules (ESM) and
    release CommonJS build for node and ESM build for browser bundlers.
    broofa authored and ctavan committed Oct 25, 2019
    Copy the full SHA
    a3f078f View commit details
  3. Copy the full SHA
    b238510 View commit details
  4. docs: document esm features

    ctavan committed Oct 25, 2019
    Copy the full SHA
    4f93fc8 View commit details
  5. Copy the full SHA
    ee5e77d View commit details

Commits on Dec 3, 2019

  1. Merge pull request #337 from ctavan/esm

    ES-Module support (next)
    ctavan authored Dec 3, 2019
    Copy the full SHA
    e6c9e44 View commit details
  2. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    d3a0c06 View commit details
  3. Copy the full SHA
    8da6bf7 View commit details
  4. Copy the full SHA
    929aa35 View commit details
  5. chore: install prettier

    It's tedious to maintain a consistent formatting style in an open source
    project and prettier does a pretty good job at enforcing a consistent
    style. So let's make use of that!
    ctavan committed Dec 3, 2019
    Copy the full SHA
    e8cb0a0 View commit details
  6. Copy the full SHA
    9312740 View commit details
  7. Copy the full SHA
    becc3fd View commit details
  8. Copy the full SHA
    2364d5c View commit details

Commits on Dec 4, 2019

  1. Merge pull request #341 from kelektiv/modernize-test-tooling

    Modernize test tooling
    ctavan authored Dec 4, 2019
    Copy the full SHA
    2857dba View commit details
  2. Bump eslint-utils from 1.4.0 to 1.4.2 (#324)

    Bumps [eslint-utils](https://github.com/mysticatea/eslint-utils) from 1.4.0 to 1.4.2.
    - [Release notes](https://github.com/mysticatea/eslint-utils/releases)
    - [Commits](mysticatea/eslint-utils@v1.4.0...v1.4.2)
    
    Signed-off-by: dependabot[bot] <support@github.com>
    dependabot[bot] authored and broofa committed Dec 4, 2019
    Copy the full SHA
    0b141e1 View commit details
  3. Copy the full SHA
    76fb0e8 View commit details

Commits on Dec 26, 2019

  1. Copy the full SHA
    ac7a3f4 View commit details

Commits on Dec 28, 2019

  1. Merge pull request #349 from kelektiv/dependabot/npm_and_yarn/handleb…

    …ars-4.5.3
    
    chore(deps): bump handlebars from 4.1.2 to 4.5.3
    ctavan authored Dec 28, 2019
    Copy the full SHA
    e444323 View commit details

Commits on Jan 8, 2020

  1. Copy the full SHA
    d0df05e View commit details

Commits on Jan 15, 2020

  1. Copy the full SHA
    62cf034 View commit details
  2. Copy the full SHA
    67be5ac View commit details
  3. Merge pull request #348 from uuidjs/browser-testing

    Browser testing
    ctavan authored Jan 15, 2020
    Copy the full SHA
    172d43d View commit details

Commits on Jan 16, 2020

  1. Copy the full SHA
    e2d7314 View commit details
  2. chore(release): 3.4.0

    ctavan committed Jan 16, 2020
    Copy the full SHA
    3df73a9 View commit details
  3. Copy the full SHA
    c37a518 View commit details
  4. chore(release): 3.4.0

    ctavan committed Jan 16, 2020
    Copy the full SHA
    fb47a9d View commit details

Commits on Jan 20, 2020

  1. docs: fix changelog

    Apparently the changelog for v3.3.3 was edited manually and had a bad
    heading level
    ctavan committed Jan 20, 2020
    Copy the full SHA
    26987bc View commit details
  2. chore: rename package script to build

    "build" seems to be the more appropriate term for what we're doing here.
    
    Part of #343.
    ctavan committed Jan 20, 2020
    Copy the full SHA
    4244b9e View commit details

Commits on Jan 21, 2020

  1. chore: transition dev dependencies to exact versions

    Since the devDependencies are pinned in the package-lock.json anyways
    there's no real use in leaving a version range open for the
    devDependencies in package.json.
    
    Instead, we simply keep our toolchain up-to-date with tools like ncu.
    
    With this commit I also re-generate package-lock.json from scratch.
    ctavan committed Jan 21, 2020
    Copy the full SHA
    4bd4fd7 View commit details
  2. Copy the full SHA
    f2c361d View commit details
  3. chore: upgrade lint-staged

    ctavan committed Jan 21, 2020
    Copy the full SHA
    06436a7 View commit details
  4. build: set up and document build and release scripts

    Since we have a build step now we must point the package.json file
    reference to the dist folder and must explicitly list all files that we
    want to be included in the npm tarball.
    
    The initial idea was to prepare the contents of the final npm tarball
    all in the dist directory (including a copy of the package.json) but
    that turns out not to work particularly well with standard-version which
    is used to manage the version numbers and changelog.
    
    Unfortunately this change also required a small workaround to allow
    local installation of the uuid module in the examples (see .local/).
    
    Also instructions for relasing a new version have not yet been
    documented which is finally done here.
    
    Since we now explicitly list all files to be included in the tarball
    through the files property of package.json we no longer need the
    .npmignore file.
    ctavan committed Jan 21, 2020
    Copy the full SHA
    53ca9d4 View commit details
  5. Merge pull request #352 from uuidjs/prepare-for-alpha-release

    Prepare for canary release
    ctavan authored Jan 21, 2020
    Copy the full SHA
    380fe28 View commit details

Commits on Jan 23, 2020

  1. Add bundlesize (#353)

    * test: add bundlesize
    
    This will let us prevent regressions in bundlesize.
    
    I chose to monitor the bundlesize of webpack and rollup build because
    this is what ultimately matters to the user. If we break something in
    our library that would e.g. break tree shaking in one of these bundlers
    we would want to notice.
    
    Co-authored-by: Robert Kieffer <robert@broofa.com>
    ctavan and broofa authored Jan 23, 2020
    Copy the full SHA
    4acaea4 View commit details
  2. feat: remove support for pre Node.js v4 Buffer API (#356)

    BREAKING CHANGE: Remove support for generating v3 and v5 UUIDs in
    Node.js<4.x
    ctavan authored Jan 23, 2020
    Copy the full SHA
    b59b5c5 View commit details

Commits on Jan 27, 2020

  1. Copy the full SHA
    15b080d View commit details
  2. docs: fix badge url

    ctavan committed Jan 27, 2020
    Copy the full SHA
    f842a23 View commit details
  3. Copy the full SHA
    8e7e111 View commit details
  4. Copy the full SHA
    50b0969 View commit details
Showing with 38,568 additions and 4,247 deletions.
  1. +4 −0 .eslintignore
  2. +9 −38 .eslintrc.json
  3. +39 −0 .github/ISSUE_TEMPLATE/bug_report.yml
  4. +13 −0 .github/ISSUE_TEMPLATE/feature_request.yml
  5. +10 −0 .github/PULL_REQUEST_TEMPLATE.md
  6. +25 −0 .github/workflows/browser.yml
  7. +44 −0 .github/workflows/ci.yml
  8. +22 −0 .github/workflows/stale-issues.yml
  9. +6 −4 .gitignore
  10. +4 −0 .husky/commit-msg
  11. +4 −0 .husky/pre-commit
  12. +9 −0 .local/README.md
  13. +1 −0 .local/uuid/dist
  14. +1 −0 .local/uuid/package.json
  15. +1 −0 .local/uuid/v1.js
  16. +1 −0 .local/uuid/v3.js
  17. +1 −0 .local/uuid/v4.js
  18. +1 −0 .local/uuid/v5.js
  19. +1 −0 .local/uuid/wrapper.mjs
  20. +0 −7 .npmignore
  21. +1 −1 .npmrc
  22. +4 −0 .prettierignore
  23. +0 −5 .travis.yml
  24. +199 −43 CHANGELOG.md
  25. +18 −0 CONTRIBUTING.md
  26. +4 −16 LICENSE.md
  27. +337 −168 README.md
  28. +357 −182 README_js.md
  29. +66 −0 babel.config.json
  30. +0 −65 bin/uuid
  31. +13 −0 bundlewatch.config.json
  32. +26 −0 examples/benchmark/README.md
  33. +4 −0 examples/benchmark/benchmark.html
  34. +77 −0 examples/benchmark/benchmark.js
  35. +7 −0 examples/benchmark/browser.js
  36. +6 −0 examples/benchmark/node.js
  37. +128 −0 examples/benchmark/package-lock.json
  38. +17 −0 examples/benchmark/package.json
  39. +8 −0 examples/browser-esmodules/README.md
  40. +4 −0 examples/browser-esmodules/example.html
  41. +66 −0 examples/browser-esmodules/example.js
  42. +87 −0 examples/browser-esmodules/package-lock.json
  43. +12 −0 examples/browser-esmodules/package.json
  44. +1 −0 examples/browser-rollup/.gitignore
  45. +17 −0 examples/browser-rollup/README.md
  46. +9 −0 examples/browser-rollup/example-all.html
  47. +74 −0 examples/browser-rollup/example-all.js
  48. +9 −0 examples/browser-rollup/example-v1.html
  49. +8 −0 examples/browser-rollup/example-v1.js
  50. +9 −0 examples/browser-rollup/example-v4.html
  51. +8 −0 examples/browser-rollup/example-v4.js
  52. +6 −0 examples/browser-rollup/example.html
  53. +1,003 −0 examples/browser-rollup/package-lock.json
  54. +17 −0 examples/browser-rollup/package.json
  55. +63 −0 examples/browser-rollup/rollup.config.js
  56. +3 −0 examples/browser-rollup/size-v1.js
  57. +3 −0 examples/browser-rollup/size-v3.js
  58. +3 −0 examples/browser-rollup/size-v4.js
  59. +3 −0 examples/browser-rollup/size-v5.js
  60. +1 −0 examples/browser-webpack/.gitignore
  61. +17 −0 examples/browser-webpack/README.md
  62. +9 −0 examples/browser-webpack/example-all-require.html
  63. +74 −0 examples/browser-webpack/example-all-require.js
  64. +9 −0 examples/browser-webpack/example-all.html
  65. +74 −0 examples/browser-webpack/example-all.js
  66. +9 −0 examples/browser-webpack/example-v1.html
  67. +9 −0 examples/browser-webpack/example-v1.js
  68. +9 −0 examples/browser-webpack/example-v4.html
  69. +9 −0 examples/browser-webpack/example-v4.js
  70. +6 −0 examples/browser-webpack/example.html
  71. +2,280 −0 examples/browser-webpack/package-lock.json
  72. +16 −0 examples/browser-webpack/package.json
  73. +3 −0 examples/browser-webpack/size-v1.js
  74. +3 −0 examples/browser-webpack/size-v3.js
  75. +3 −0 examples/browser-webpack/size-v4.js
  76. +3 −0 examples/browser-webpack/size-v5.js
  77. +23 −0 examples/browser-webpack/webpack.config.js
  78. +6 −0 examples/node-commonjs/README.md
  79. +70 −0 examples/node-commonjs/example.js
  80. +87 −0 examples/node-commonjs/package-lock.json
  81. +11 −0 examples/node-commonjs/package.json
  82. +6 −0 examples/node-esmodules/README.md
  83. +66 −0 examples/node-esmodules/example.mjs
  84. +87 −0 examples/node-esmodules/package-lock.json
  85. +13 −0 examples/node-esmodules/package.json
  86. +4 −0 examples/node-esmodules/package.mjs
  87. +6 −0 examples/node-jest/README.md
  88. +8 −0 examples/node-jest/jsdom.test.js
  89. +6 −0 examples/node-jest/node.test.js
  90. +7,227 −0 examples/node-jest/package-lock.json
  91. +15 −0 examples/node-jest/package.json
  92. +1 −0 examples/node-webpack/.gitignore
  93. +8 −0 examples/node-webpack/README.md
  94. +42 −0 examples/node-webpack/example-all.js
  95. +3 −0 examples/node-webpack/example-v1.js
  96. +3 −0 examples/node-webpack/example-v4.js
  97. +2,280 −0 examples/node-webpack/package-lock.json
  98. +16 −0 examples/node-webpack/package.json
  99. +15 −0 examples/node-webpack/webpack.config.js
  100. +42 −0 examples/utils/testpage.js
  101. +0 −8 index.js
  102. +0 −24 lib/bytesToUuid.js
  103. +0 −25 lib/md5.js
  104. +0 −34 lib/rng-browser.js
  105. +0 −8 lib/rng.js
  106. +0 −89 lib/sha1-browser.js
  107. +0 −25 lib/sha1.js
  108. +0 −57 lib/v35.js
  109. +21,349 −3,030 package-lock.json
  110. +106 −19 package.json
  111. +7 −0 prettier.config.js
  112. +62 −0 scripts/build.sh
  113. +27 −0 scripts/testpack.sh
  114. +2 −0 src/bin/uuid
  115. +9 −0 src/index.js
  116. +70 −69 {lib → src}/md5-browser.js
  117. +13 −0 src/md5.js
  118. +4 −0 src/native-browser.js
  119. +3 −0 src/native.js
  120. +1 −0 src/nil.js
  121. +41 −0 src/parse.js
  122. +1 −0 src/regex.js
  123. +25 −0 src/rng-browser.js
  124. +12 −0 src/rng.js
  125. +119 −0 src/sha1-browser.js
  126. +13 −0 src/sha1.js
  127. +54 −0 src/stringify.js
  128. +80 −0 src/uuid-bin.js
  129. +37 −31 { → src}/v1.js
  130. +5 −0 src/v3.js
  131. +68 −0 src/v35.js
  132. +32 −0 src/v4.js
  133. +5 −0 src/v5.js
  134. +7 −0 src/validate.js
  135. +11 −0 src/version.js
  136. +106 −0 test/browser/browser.spec.js
  137. +0 −3 test/mocha.opts
  138. +0 −260 test/test.js
  139. +54 −0 test/unit/parse.test.js
  140. +23 −0 test/unit/rng.test.js
  141. +48 −0 test/unit/stringify.test.js
  142. +19 −0 test/unit/v1-random.test.js
  143. +19 −0 test/unit/v1-rng.test.js
  144. +109 −0 test/unit/v1.test.js
  145. +274 −0 test/unit/v35.test.js
  146. +61 −0 test/unit/v4.test.js
  147. +45 −0 test/unit/validate.test.js
  148. +33 −0 test/unit/version.test.js
  149. +0 −4 v3.js
  150. +0 −29 v4.js
  151. +0 −3 v5.js
  152. +152 −0 wdio.conf.js
  153. +10 −0 wrapper.mjs
4 changes: 4 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
!.babelrc.js
.local/
dist/
node_modules/
47 changes: 9 additions & 38 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -3,45 +3,16 @@
"env": {
"browser": true,
"commonjs": true,
"node": true,
"mocha": true
"es6": true,
"jest": true,
"node": true
},
"extends": ["eslint:recommended"],
"extends": ["eslint:recommended", "standard", "plugin:prettier/recommended"],
"globals": {
"msCrypto": true
},
"parser": "@babel/eslint-parser",
"rules": {
"array-bracket-spacing": ["warn", "never"],
"arrow-body-style": ["warn", "as-needed"],
"arrow-parens": ["warn", "as-needed"],
"arrow-spacing": "warn",
"brace-style": ["warn", "1tbs"],
"camelcase": "warn",
"comma-spacing": ["warn", {"after": true}],
"dot-notation": "warn",
"eqeqeq": ["warn", "smart"],
"indent": ["warn", 2, {
"SwitchCase": 1,
"FunctionDeclaration": {"parameters": 1},
"MemberExpression": 1,
"CallExpression": {"arguments": 1}
}],
"key-spacing": ["warn", {"beforeColon": false, "afterColon": true, "mode": "minimum"}],
"keyword-spacing": "warn",
"no-console": "off",
"no-empty": "off",
"no-multi-spaces": "warn",
"no-redeclare": "off",
"no-restricted-globals": ["warn", "Promise"],
"no-trailing-spaces": "warn",
"no-undef": "error",
"no-unused-vars": ["warn", {"args": "none"}],
"one-var": ["warn", "never"],
"padded-blocks": ["warn", "never"],
"object-curly-spacing": ["warn", "never"],
"quotes": ["warn", "single"],
"react/prop-types": "off",
"react/jsx-no-bind": "off",
"semi": ["warn", "always"],
"space-before-blocks": ["warn", "always"],
"space-before-function-paren": ["warn", "never"],
"space-in-parens": ["warn", "never"]
"no-var": ["error"]
}
}
39 changes: 39 additions & 0 deletions .github/ISSUE_TEMPLATE/bug_report.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: Bug report
description: File a bug against the `uuid` project
labels: ["bug"]
title: "[BUG] <title>"

body:
- type: checkboxes
attributes:
label: Before you begin...
options:
- label: I have searched the existing issues
required: true
- label: I am not using version 13.x of node (if so, please upgrade)
required: true

- type: textarea
attributes:
label: Description of the problem
validations:
required: false

- type: textarea
attributes:
label: Recipe for reproducing
description: "**IMPORTANT**: Failure to provide a [Minimal, Complete, and Verifiable](https://stackoverflow.com/help/minimal-reproducible-example) example will result in this issue being closed without further review."
render: bash
validations:
required: false

- type: textarea
attributes:
label: Additional information

- type: textarea
attributes:
label: Environment
description: "Output of `npx envinfo --system --browsers --npmPackages --binaries` goes here:"
validations:
required: false
13 changes: 13 additions & 0 deletions .github/ISSUE_TEMPLATE/feature_request.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
name: Feature request
description: Suggest an idea for this project
labels: ["feature"]

body:
- type: textarea
attributes:
label: Feature description

- type: textarea
attributes:
label: Additional information
description: E.g. alternatives you've considered, examples, screenshots, or anything else that may be helpful
10 changes: 10 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!--
Thank you for your contribution!
If your pull request contains considerable changes please run the benchmark before and after your
changes and include the results in the pull request description. To run the benchmark execute:
npm run test:benchmark
from the root of this repository.
-->
25 changes: 25 additions & 0 deletions .github/workflows/browser.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Browser

on: [push]

jobs:
browser:

runs-on: ubuntu-latest
timeout-minutes: 30

steps:
- uses: actions/checkout@v1
with:
fetch-depth: 10
- name: Use Node.js 16.x
uses: actions/setup-node@v1
with:
node-version: 16.x
- run: npm install
- name: Test Browser
run: npm run test:browser
env:
CI: true
BROWSERSTACK_USER: ${{ secrets.BROWSERSTACK_USER }}
BROWSERSTACK_ACCESS_KEY: ${{ secrets.BROWSERSTACK_ACCESS_KEY }}
44 changes: 44 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: CI

on: [push, pull_request]

jobs:
ci:

runs-on: ubuntu-latest

strategy:
matrix:
node-version: [12.x, 14.x, 16.x, 18.x]

steps:
- uses: actions/checkout@v1
with:
fetch-depth: 10
- name: Use Node.js 16.x to build
uses: actions/setup-node@v1
with:
node-version: 16.x
- run: npm install
- run: npm run build
- run: rm -rf node_modules
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- run: npm install
- run: npm run test
env:
CI: true
- run: npm run lint
if: matrix.node-version == '16.x'
- run: npm run docs:diff
if: matrix.node-version == '16.x'
- run: npm run bundlewatch
if: matrix.node-version == '16.x'
env:
BUNDLEWATCH_GITHUB_TOKEN: ${{ secrets.BUNDLEWATCH_GITHUB_TOKEN }}
- run: npm run test:node
if: matrix.node-version >= '16.x'
- run: npm run test:pack
if: matrix.node-version >= '16.x'
22 changes: 22 additions & 0 deletions .github/workflows/stale-issues.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Close inactive issues
on:
schedule:
- cron: "45 2 * * *"

jobs:
close-issues:
runs-on: ubuntu-latest
permissions:
issues: write
pull-requests: write
steps:
- uses: actions/stale@v5
with:
days-before-issue-stale: 90
days-before-issue-close: 30
stale-issue-label: "stale"
stale-issue-message: "Marking as stale due to 90 days with no activity."
close-issue-message: "Closing issue due to 30 days since being marked as stale."
days-before-pr-stale: -1
days-before-pr-close: -1
repo-token: ${{ secrets.GITHUB_TOKEN }}
10 changes: 6 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
*.sw*
.idea/**
.DS_Store
node_modules
node_modules/
dist/
# Browserstack
browserstack.err
local.log
*.tgz
4 changes: 4 additions & 0 deletions .husky/commit-msg
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

npx --no-install commitlint --edit $1
4 changes: 4 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

npx --no-install lint-staged
9 changes: 9 additions & 0 deletions .local/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Local Fake Module for Testing

This is a local fake module for use in the [examples](../examples) and browser tests (that are
based on the examples) where we reference the `uuid` module with a local `file:` path in the
respective `package.json` files.

We must ensure that the local module does not contain locally installed dev dependencies in a
`node_modules` hence this "fake module" that just consists of symbolic links and imitates the final
contents of the npm tarball.
1 change: 1 addition & 0 deletions .local/uuid/dist
1 change: 1 addition & 0 deletions .local/uuid/package.json
1 change: 1 addition & 0 deletions .local/uuid/v1.js
1 change: 1 addition & 0 deletions .local/uuid/v3.js
1 change: 1 addition & 0 deletions .local/uuid/v4.js
1 change: 1 addition & 0 deletions .local/uuid/v5.js
1 change: 1 addition & 0 deletions .local/uuid/wrapper.mjs
7 changes: 0 additions & 7 deletions .npmignore

This file was deleted.

2 changes: 1 addition & 1 deletion .npmrc
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
tag-version-prefix="v"
save-prefix="~"
save-prefix=""
4 changes: 4 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.local/
dist/
node_modules/
README.md
5 changes: 0 additions & 5 deletions .travis.yml

This file was deleted.

242 changes: 199 additions & 43 deletions CHANGELOG.md

Large diffs are not rendered by default.

18 changes: 18 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Contributing

Please feel free to file GitHub Issues or propose Pull Requests. We're always happy to discuss improvements to this library!

## Testing

```shell
npm test
```

## Releasing

Releases are supposed to be done from master, version bumping is automated through [`standard-version`](https://github.com/conventional-changelog/standard-version):

```shell
npm run release -- --dry-run # verify output manually
npm run release # follow the instructions from the output of this command
```
20 changes: 4 additions & 16 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,9 @@
The MIT License (MIT)

Copyright (c) 2010-2016 Robert Kieffer and other contributors
Copyright (c) 2010-2020 Robert Kieffer and other contributors

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
505 changes: 337 additions & 168 deletions README.md

Large diffs are not rendered by default.

539 changes: 357 additions & 182 deletions README_js.md

Large diffs are not rendered by default.

66 changes: 66 additions & 0 deletions babel.config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
{
"presets": [],
"plugins": [],
"env": {
"commonjsNode": {
"presets": [
[
"@babel/preset-env",
{
"targets": {
"node": "10"
},
"modules": "commonjs"
}
]
]
},
"esmNode": {
"presets": [
[
"@babel/preset-env",
{
"targets": {
"node": "10"
},
"modules": false
}
]
]
},
"commonjsBrowser": {
"presets": [
[
"@babel/preset-env",
{
"targets": {
"chrome": "49",
"edge": "15",
"firefox": "53",
"safari": "11"
},
"bugfixes": true,
"modules": "commonjs"
}
]
]
},
"esmBrowser": {
"presets": [
[
"@babel/preset-env",
{
"targets": {
"chrome": "49",
"edge": "15",
"firefox": "53",
"safari": "11"
},
"bugfixes": true,
"modules": false
}
]
]
}
}
}
65 changes: 0 additions & 65 deletions bin/uuid

This file was deleted.

13 changes: 13 additions & 0 deletions bundlewatch.config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"files": [
{ "path": "./examples/browser-rollup/dist/v1-size.js", "maxSize": "1.0 kB" },
{ "path": "./examples/browser-rollup/dist/v3-size.js", "maxSize": "2.1 kB" },
{ "path": "./examples/browser-rollup/dist/v4-size.js", "maxSize": "0.7 kB" },
{ "path": "./examples/browser-rollup/dist/v5-size.js", "maxSize": "1.5 kB" },

{ "path": "./examples/browser-webpack/dist/v1-size.js", "maxSize": "1.0 kB" },
{ "path": "./examples/browser-webpack/dist/v3-size.js", "maxSize": "2.1 kB" },
{ "path": "./examples/browser-webpack/dist/v4-size.js", "maxSize": "0.7 kB" },
{ "path": "./examples/browser-webpack/dist/v5-size.js", "maxSize": "1.5 kB" }
]
}
26 changes: 26 additions & 0 deletions examples/benchmark/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# uuid Benchmark

```
npm install
```

## Node.js

To run the benchmark in Node.js, run `npm test`.

## Browser

To run the benchmark in the browser run `npm run start`, open `benchmark.html`, and check the console.

Example output (`uuid@8.0.0`, MacBook Pro (Retina, 13-inch, Early 2015), 3.1 GHz Dual-Core Intel Core i7):

```
Starting. Tests take ~1 minute to run ...
uuidv1() x 1,306,861 ops/sec ±2.62% (85 runs sampled)
uuidv1() fill existing array x 4,750,515 ops/sec ±2.76% (88 runs sampled)
uuidv4() x 302,174 ops/sec ±3.06% (81 runs sampled)
uuidv4() fill existing array x 359,703 ops/sec ±3.67% (82 runs sampled)
uuidv3() x 105,667 ops/sec ±3.84% (79 runs sampled)
uuidv5() x 110,886 ops/sec ±2.55% (81 runs sampled)
Fastest is uuidv1() fill existing array
```
4 changes: 4 additions & 0 deletions examples/benchmark/benchmark.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<!DOCTYPE html>
<title>UUID Benchmark</title>
<p>Please open the Developer Console to view output</p>
<script type="module" src="./browser.js"></script>
77 changes: 77 additions & 0 deletions examples/benchmark/benchmark.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
export default function benchmark(uuid, Benchmark) {
console.log('Starting. Tests take ~1 minute to run ...');

function testParseAndStringify() {
const suite = new Benchmark.Suite({
onError(event) {
console.error(event.target.error);
},
});

const BYTES = [
0x0f, 0x5a, 0xbc, 0xd1, 0xc1, 0x94, 0x47, 0xf3, 0x90, 0x5b, 0x2d, 0xf7, 0x26, 0x3a, 0x08,
0x4b,
];

suite
.add('uuid.stringify()', function () {
uuid.stringify(BYTES);
})
.add('uuid.parse()', function () {
uuid.parse('0f5abcd1-c194-47f3-905b-2df7263a084b');
})
.on('cycle', function (event) {
console.log(event.target.toString());
})
.on('complete', function () {
console.log('---\n');
})
.run();
}

function testGeneration() {
const array = new Array(16);

const suite = new Benchmark.Suite({
onError(event) {
console.error(event.target.error);
},
});

suite
.add('uuid.v1()', function () {
uuid.v1();
})
.add('uuid.v1() fill existing array', function () {
try {
uuid.v1(null, array, 0);
} catch (err) {
// The spec (https://tools.ietf.org/html/rfc4122#section-4.2.1.2) defines that only 10M/s v1
// UUIDs can be generated on a single node. This library throws an error if we hit that limit
// (which can happen on modern hardware and modern Node.js versions).
}
})
.add('uuid.v4()', function () {
uuid.v4();
})
.add('uuid.v4() fill existing array', function () {
uuid.v4(null, array, 0);
})
.add('uuid.v3()', function () {
uuid.v3('hello.example.com', uuid.v3.DNS);
})
.add('uuid.v5()', function () {
uuid.v5('hello.example.com', uuid.v5.DNS);
})
.on('cycle', function (event) {
console.log(event.target.toString());
})
.on('complete', function () {
console.log('Fastest is ' + this.filter('fastest').map('name'));
})
.run();
}

testParseAndStringify();
testGeneration();
}
7 changes: 7 additions & 0 deletions examples/benchmark/browser.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import * as uuid from './node_modules/uuid/dist/esm-browser/index.js';
import './node_modules/lodash/lodash.js';
import './node_modules/benchmark/benchmark.js';

import benchmark from './benchmark.js';

benchmark(uuid, window.Benchmark);
6 changes: 6 additions & 0 deletions examples/benchmark/node.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import * as uuid from 'uuid';
import Benchmark from 'benchmark';

import benchmark from './benchmark.js';

benchmark(uuid, Benchmark);
128 changes: 128 additions & 0 deletions examples/benchmark/package-lock.json
17 changes: 17 additions & 0 deletions examples/benchmark/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"name": "uuid-benchmark",
"version": "0.0.0",
"private": true,
"scripts": {
"build": "true",
"start": "npm run build && npx http-server . -o",
"test": "node node.js"
},
"dependencies": {
"uuid": "file:../../.local/uuid"
},
"devDependencies": {
"benchmark": "^2.1.4"
},
"type": "module"
}
8 changes: 8 additions & 0 deletions examples/browser-esmodules/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# uuid example Browser with native ECMAScript Modules

```
npm install
npm start
```

Then navigate to `example.html`.
4 changes: 4 additions & 0 deletions examples/browser-esmodules/example.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<!DOCTYPE html>
<title>UUID esmodule native example</title>
<p>Please open the Developer Console to view output</p>
<script type="module" src="example.js"></script>
66 changes: 66 additions & 0 deletions examples/browser-esmodules/example.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import {
NIL as NIL_UUID,
parse as uuidParse,
stringify as uuidStringify,
v1 as uuidv1,
v3 as uuidv3,
v4 as uuidv4,
v5 as uuidv5,
validate as uuidValidate,
version as uuidVersion,
} from './node_modules/uuid/dist/esm-browser/index.js';
import * as uuid from './node_modules/uuid/dist/esm-browser/index.js';

console.log('uuidv1()', uuidv1());

console.log('uuidv4()', uuidv4());

// ... using predefined DNS namespace (for domain names)
console.log('uuidv3() DNS', uuidv3('hello.example.com', uuidv3.DNS));

// ... using predefined URL namespace (for, well, URLs)
console.log('uuidv3() URL', uuidv3('http://example.com/hello', uuidv3.URL));

// ... using a custom namespace
//
// Note: Custom namespaces should be a UUID string specific to your application!
// E.g. the one here was generated using this modules `uuid` CLI.
const MY_NAMESPACE = '55238d15-c926-4598-b49d-cf4e913ba13c';
console.log('uuidv3() MY_NAMESPACE', uuidv3('Hello, World!', MY_NAMESPACE));

// ... using predefined DNS namespace (for domain names)
console.log('uuidv5() DNS', uuidv5('hello.example.com', uuidv5.DNS));

// ... using predefined URL namespace (for, well, URLs)
console.log('uuidv5() URL', uuidv5('http://example.com/hello', uuidv5.URL));

// ... using a custom namespace
//
// Note: Custom namespaces should be a UUID string specific to your application!
// E.g. the one here was generated using this modules `uuid` CLI.
// const MY_NAMESPACE = '1b671a64-40d5-491e-99b0-da01ff1f3341';
console.log('uuidv5() MY_NAMESPACE', uuidv5('Hello, World!', MY_NAMESPACE));

// Utility functions
console.log('NIL_UUID', NIL_UUID);
console.log('uuidParse()', uuidParse(MY_NAMESPACE));
console.log('uuidStringify()', uuidStringify(uuidParse(MY_NAMESPACE)));
console.log('uuidValidate()', uuidValidate(MY_NAMESPACE));
console.log('uuidVersion()', uuidVersion(MY_NAMESPACE));

console.log('Same with default export');

console.log('uuid.v1()', uuid.v1());
console.log('uuid.v4()', uuid.v4());
console.log('uuid.v3() DNS', uuid.v3('hello.example.com', uuid.v3.DNS));
console.log('uuid.v3() URL', uuid.v3('http://example.com/hello', uuid.v3.URL));
console.log('uuid.v3() MY_NAMESPACE', uuid.v3('Hello, World!', MY_NAMESPACE));
console.log('uuid.v5() DNS', uuid.v5('hello.example.com', uuid.v5.DNS));
console.log('uuid.v5() URL', uuid.v5('http://example.com/hello', uuid.v5.URL));
console.log('uuid.v5() MY_NAMESPACE', uuid.v5('Hello, World!', MY_NAMESPACE));

console.log('uuid.NIL', uuid.NIL);
console.log('uuid.parse()', uuid.parse(MY_NAMESPACE));
console.log('uuid.stringify()', uuid.stringify(uuid.parse(MY_NAMESPACE)));
console.log('uuid.validate()', uuid.validate(MY_NAMESPACE));
console.log('uuid.version()', uuid.version(MY_NAMESPACE));
87 changes: 87 additions & 0 deletions examples/browser-esmodules/package-lock.json
12 changes: 12 additions & 0 deletions examples/browser-esmodules/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"name": "uuid-example-browser-esmodules",
"version": "0.0.0",
"private": true,
"scripts": {
"build": "true",
"start": "npm run build && npx http-server . -o"
},
"dependencies": {
"uuid": "file:../../.local/uuid"
}
}
1 change: 1 addition & 0 deletions examples/browser-rollup/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dist/
17 changes: 17 additions & 0 deletions examples/browser-rollup/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# uuid example Browser with rollup.js

```
npm install
npm start
```

Then navigate to `example-*.html`.

The `example-v{1,4}.js` demonstrate that treeshaking works as expected:

```
$ du -sh dist/*
20K dist/all.js
8.0K dist/v1.js
4.0K dist/v4.js
```
9 changes: 9 additions & 0 deletions examples/browser-rollup/example-all.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<!DOCTYPE html>
<html>
<head>
<title>UUID esmodule webpack example</title>
</head>
<body>
<script type="text/javascript" src="./dist/all.js"></script>
</body>
</html>
74 changes: 74 additions & 0 deletions examples/browser-rollup/example-all.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import {
NIL as NIL_UUID,
parse as uuidParse,
stringify as uuidStringify,
v1 as uuidv1,
v3 as uuidv3,
v4 as uuidv4,
v5 as uuidv5,
validate as uuidValidate,
version as uuidVersion,
} from 'uuid';
import * as uuid from 'uuid';

import testpage from '../utils/testpage';

testpage(function (addTest, done) {
addTest('Named exports');

addTest('uuidv1()', uuidv1());

addTest('uuidv4()', uuidv4());

// ... using predefined DNS namespace (for domain names)
addTest('uuidv3() DNS', uuidv3('hello.example.com', uuidv3.DNS));

// ... using predefined URL namespace (for, well, URLs)
addTest('uuidv3() URL', uuidv3('http://example.com/hello', uuidv3.URL));

// ... using a custom namespace
//
// Note: Custom namespaces should be a UUID string specific to your application!
// E.g. the one here was generated using this modules `uuid` CLI.
const MY_NAMESPACE = '55238d15-c926-4598-b49d-cf4e913ba13c';
addTest('uuidv3() MY_NAMESPACE', uuidv3('Hello, World!', MY_NAMESPACE));

// ... using predefined DNS namespace (for domain names)
addTest('uuidv5() DNS', uuidv5('hello.example.com', uuidv5.DNS));

// ... using predefined URL namespace (for, well, URLs)
addTest('uuidv5() URL', uuidv5('http://example.com/hello', uuidv5.URL));

// ... using a custom namespace
//
// Note: Custom namespaces should be a UUID string specific to your application!
// E.g. the one here was generated using this modules `uuid` CLI.
// const MY_NAMESPACE = '1b671a64-40d5-491e-99b0-da01ff1f3341';
addTest('uuidv5() MY_NAMESPACE', uuidv5('Hello, World!', MY_NAMESPACE));

// Utility functions
addTest('NIL_UUID', NIL_UUID);
addTest('uuidParse()', uuidParse(MY_NAMESPACE));
addTest('uuidStringify()', uuidStringify(uuidParse(MY_NAMESPACE)));
addTest('uuidValidate()', uuidValidate(MY_NAMESPACE));
addTest('uuidVersion()', uuidVersion(MY_NAMESPACE));

addTest('Default export');

addTest('uuid.v1()', uuid.v1());
addTest('uuid.v4()', uuid.v4());
addTest('uuid.v3() DNS', uuid.v3('hello.example.com', uuid.v3.DNS));
addTest('uuid.v3() URL', uuid.v3('http://example.com/hello', uuid.v3.URL));
addTest('uuid.v3() MY_NAMESPACE', uuid.v3('Hello, World!', MY_NAMESPACE));
addTest('uuid.v5() DNS', uuid.v5('hello.example.com', uuid.v5.DNS));
addTest('uuid.v5() URL', uuid.v5('http://example.com/hello', uuid.v5.URL));
addTest('uuid.v5() MY_NAMESPACE', uuid.v5('Hello, World!', MY_NAMESPACE));

addTest('uuid.NIL', uuid.NIL);
addTest('uuid.parse()', uuid.parse(MY_NAMESPACE));
addTest('uuid.stringify()', uuid.stringify(uuid.parse(MY_NAMESPACE)));
addTest('uuid.validate()', uuid.validate(MY_NAMESPACE));
addTest('uuid.version()', uuid.version(MY_NAMESPACE));

done();
});
9 changes: 9 additions & 0 deletions examples/browser-rollup/example-v1.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<!DOCTYPE html>
<html>
<head>
<title>UUID esmodule webpack example</title>
</head>
<body>
<script type="text/javascript" src="./dist/v1.js"></script>
</body>
</html>
8 changes: 8 additions & 0 deletions examples/browser-rollup/example-v1.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { v1 as uuidv1 } from 'uuid';

import testpage from '../utils/testpage';

testpage(function (addTest, done) {
addTest('uuidv1()', uuidv1());
done();
});
9 changes: 9 additions & 0 deletions examples/browser-rollup/example-v4.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<!DOCTYPE html>
<html>
<head>
<title>UUID esmodule webpack example</title>
</head>
<body>
<script type="text/javascript" src="./dist/v4.js"></script>
</body>
</html>
8 changes: 8 additions & 0 deletions examples/browser-rollup/example-v4.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { v4 as uuidv4 } from 'uuid';

import testpage from '../utils/testpage';

testpage(function (addTest, done) {
addTest('uuidv4()', uuidv4());
done();
});
6 changes: 6 additions & 0 deletions examples/browser-rollup/example.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<!DOCTYPE html>
<title>UUID esmodule webpack example</title>
<p>Please open the Developer Console to view output</p>
<script type="text/javascript" src="./dist/v1.js"></script>
<script type="text/javascript" src="./dist/v4.js"></script>
<script type="text/javascript" src="./dist/all.js"></script>
1,003 changes: 1,003 additions & 0 deletions examples/browser-rollup/package-lock.json

Large diffs are not rendered by default.

17 changes: 17 additions & 0 deletions examples/browser-rollup/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"name": "uuid-example-browser-rollup",
"version": "0.0.0",
"private": true,
"scripts": {
"build": "rm -rf dist && rollup -c",
"start": "npm run build && npx http-server . -o"
},
"dependencies": {
"uuid": "file:../../.local/uuid"
},
"devDependencies": {
"@rollup/plugin-node-resolve": "^13.3.0",
"rollup": "^2.77.2",
"rollup-plugin-terser": "^7.0.2"
}
}
63 changes: 63 additions & 0 deletions examples/browser-rollup/rollup.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
const { nodeResolve } = require('@rollup/plugin-node-resolve');
const { terser } = require('rollup-plugin-terser');

const plugins = [nodeResolve({ browser: true }), terser()];
module.exports = [
{
input: './example-all.js',
output: {
file: 'dist/all.js',
format: 'iife',
},
plugins,
},
{
input: './example-v1.js',
output: {
file: 'dist/v1.js',
format: 'iife',
},
plugins,
},
{
input: './example-v4.js',
output: {
file: 'dist/v4.js',
format: 'iife',
},
plugins,
},

{
input: './size-v1.js',
output: {
file: 'dist/v1-size.js',
format: 'cjs',
},
plugins,
},
{
input: './size-v3.js',
output: {
file: 'dist/v3-size.js',
format: 'cjs',
},
plugins,
},
{
input: './size-v4.js',
output: {
file: 'dist/v4-size.js',
format: 'cjs',
},
plugins,
},
{
input: './size-v5.js',
output: {
file: 'dist/v5-size.js',
format: 'cjs',
},
plugins,
},
];
3 changes: 3 additions & 0 deletions examples/browser-rollup/size-v1.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { v1 as uuidv1 } from 'uuid';

uuidv1();
3 changes: 3 additions & 0 deletions examples/browser-rollup/size-v3.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { v3 as uuidv3 } from 'uuid';

uuidv3();
3 changes: 3 additions & 0 deletions examples/browser-rollup/size-v4.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { v4 as uuidv4 } from 'uuid';

uuidv4();
3 changes: 3 additions & 0 deletions examples/browser-rollup/size-v5.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { v5 as uuidv5 } from 'uuid';

uuidv5();
1 change: 1 addition & 0 deletions examples/browser-webpack/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dist/
17 changes: 17 additions & 0 deletions examples/browser-webpack/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# uuid example Browser with Webpack

```
npm install
npm start
```

Then navigate to `example-*.html`.

The `example-v{1,4}.js` demonstrate that treeshaking works as expected (webpack output below):

```
Asset Size Chunks Chunk Names
all.js 8.54 KiB 0 [emitted] all
v1.js 2.6 KiB 1 [emitted] v1
v4.js 2 KiB 2 [emitted] v4
```
9 changes: 9 additions & 0 deletions examples/browser-webpack/example-all-require.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<!DOCTYPE html>
<html>
<head>
<title>UUID esmodule webpack example</title>
</head>
<body>
<script type="text/javascript" src="./dist/allRequire.js"></script>
</body>
</html>
74 changes: 74 additions & 0 deletions examples/browser-webpack/example-all-require.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
const uuid = require('uuid');
const {
NIL: NIL_UUID,
parse: uuidParse,
stringify: uuidStringify,
v1: uuidv1,
v3: uuidv3,
v4: uuidv4,
v5: uuidv5,
validate: uuidValidate,
version: uuidVersion,
} = uuid;

const { default: testpage } = require('../utils/testpage');

testpage(function (addTest, done) {
addTest('Named exports');

addTest('uuidv1()', uuidv1());

addTest('uuidv4()', uuidv4());

// ... using predefined DNS namespace (for domain names)
addTest('uuidv3() DNS', uuidv3('hello.example.com', uuidv3.DNS));

// ... using predefined URL namespace (for, well, URLs)
addTest('uuidv3() URL', uuidv3('http://example.com/hello', uuidv3.URL));

// ... using a custom namespace
//
// Note: Custom namespaces should be a UUID string specific to your application!
// E.g. the one here was generated using this modules `uuid` CLI.
const MY_NAMESPACE = '55238d15-c926-4598-b49d-cf4e913ba13c';
addTest('uuidv3() MY_NAMESPACE', uuidv3('Hello, World!', MY_NAMESPACE));

// ... using predefined DNS namespace (for domain names)
addTest('uuidv5() DNS', uuidv5('hello.example.com', uuidv5.DNS));

// ... using predefined URL namespace (for, well, URLs)
addTest('uuidv5() URL', uuidv5('http://example.com/hello', uuidv5.URL));

// ... using a custom namespace
//
// Note: Custom namespaces should be a UUID string specific to your application!
// E.g. the one here was generated using this modules `uuid` CLI.
// const MY_NAMESPACE = '1b671a64-40d5-491e-99b0-da01ff1f3341';
addTest('uuidv5() MY_NAMESPACE', uuidv5('Hello, World!', MY_NAMESPACE));

// Utility functions
addTest('NIL_UUID', NIL_UUID);
addTest('uuidParse()', uuidParse(MY_NAMESPACE));
addTest('uuidStringify()', uuidStringify(uuidParse(MY_NAMESPACE)));
addTest('uuidValidate()', uuidValidate(MY_NAMESPACE));
addTest('uuidVersion()', uuidVersion(MY_NAMESPACE));

addTest('Default export');

addTest('uuid.v1()', uuid.v1());
addTest('uuid.v4()', uuid.v4());
addTest('uuid.v3() DNS', uuid.v3('hello.example.com', uuid.v3.DNS));
addTest('uuid.v3() URL', uuid.v3('http://example.com/hello', uuid.v3.URL));
addTest('uuid.v3() MY_NAMESPACE', uuid.v3('Hello, World!', MY_NAMESPACE));
addTest('uuid.v5() DNS', uuid.v5('hello.example.com', uuid.v5.DNS));
addTest('uuid.v5() URL', uuid.v5('http://example.com/hello', uuid.v5.URL));
addTest('uuid.v5() MY_NAMESPACE', uuid.v5('Hello, World!', MY_NAMESPACE));

addTest('uuid.NIL', uuid.NIL);
addTest('uuid.parse()', uuid.parse(MY_NAMESPACE));
addTest('uuid.stringify()', uuid.stringify(uuid.parse(MY_NAMESPACE)));
addTest('uuid.validate()', uuid.validate(MY_NAMESPACE));
addTest('uuid.version()', uuid.version(MY_NAMESPACE));

done();
});
9 changes: 9 additions & 0 deletions examples/browser-webpack/example-all.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<!DOCTYPE html>
<html>
<head>
<title>UUID esmodule webpack example</title>
</head>
<body>
<script type="text/javascript" src="./dist/all.js"></script>
</body>
</html>
74 changes: 74 additions & 0 deletions examples/browser-webpack/example-all.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import {
NIL as NIL_UUID,
parse as uuidParse,
stringify as uuidStringify,
v1 as uuidv1,
v3 as uuidv3,
v4 as uuidv4,
v5 as uuidv5,
validate as uuidValidate,
version as uuidVersion,
} from 'uuid';
import * as uuid from 'uuid';

import testpage from '../utils/testpage';

testpage(function (addTest, done) {
addTest('Named exports');

addTest('uuidv1()', uuidv1());

addTest('uuidv4()', uuidv4());

// ... using predefined DNS namespace (for domain names)
addTest('uuidv3() DNS', uuidv3('hello.example.com', uuidv3.DNS));

// ... using predefined URL namespace (for, well, URLs)
addTest('uuidv3() URL', uuidv3('http://example.com/hello', uuidv3.URL));

// ... using a custom namespace
//
// Note: Custom namespaces should be a UUID string specific to your application!
// E.g. the one here was generated using this modules `uuid` CLI.
const MY_NAMESPACE = '55238d15-c926-4598-b49d-cf4e913ba13c';
addTest('uuidv3() MY_NAMESPACE', uuidv3('Hello, World!', MY_NAMESPACE));

// ... using predefined DNS namespace (for domain names)
addTest('uuidv5() DNS', uuidv5('hello.example.com', uuidv5.DNS));

// ... using predefined URL namespace (for, well, URLs)
addTest('uuidv5() URL', uuidv5('http://example.com/hello', uuidv5.URL));

// ... using a custom namespace
//
// Note: Custom namespaces should be a UUID string specific to your application!
// E.g. the one here was generated using this modules `uuid` CLI.
// const MY_NAMESPACE = '1b671a64-40d5-491e-99b0-da01ff1f3341';
addTest('uuidv5() MY_NAMESPACE', uuidv5('Hello, World!', MY_NAMESPACE));

// Utility functions
addTest('NIL_UUID', NIL_UUID);
addTest('uuidParse()', uuidParse(MY_NAMESPACE));
addTest('uuidStringify()', uuidStringify(uuidParse(MY_NAMESPACE)));
addTest('uuidValidate()', uuidValidate(MY_NAMESPACE));
addTest('uuidVersion()', uuidVersion(MY_NAMESPACE));

addTest('Default export');

addTest('uuid.v1()', uuid.v1());
addTest('uuid.v4()', uuid.v4());
addTest('uuid.v3() DNS', uuid.v3('hello.example.com', uuid.v3.DNS));
addTest('uuid.v3() URL', uuid.v3('http://example.com/hello', uuid.v3.URL));
addTest('uuid.v3() MY_NAMESPACE', uuid.v3('Hello, World!', MY_NAMESPACE));
addTest('uuid.v5() DNS', uuid.v5('hello.example.com', uuid.v5.DNS));
addTest('uuid.v5() URL', uuid.v5('http://example.com/hello', uuid.v5.URL));
addTest('uuid.v5() MY_NAMESPACE', uuid.v5('Hello, World!', MY_NAMESPACE));

addTest('uuid.NIL', uuid.NIL);
addTest('uuid.parse()', uuid.parse(MY_NAMESPACE));
addTest('uuid.stringify()', uuid.stringify(uuid.parse(MY_NAMESPACE)));
addTest('uuid.validate()', uuid.validate(MY_NAMESPACE));
addTest('uuid.version()', uuid.version(MY_NAMESPACE));

done();
});
9 changes: 9 additions & 0 deletions examples/browser-webpack/example-v1.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<!DOCTYPE html>
<html>
<head>
<title>UUID esmodule webpack example</title>
</head>
<body>
<script type="text/javascript" src="./dist/v1.js"></script>
</body>
</html>
9 changes: 9 additions & 0 deletions examples/browser-webpack/example-v1.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { v1 as uuidv1 } from 'uuid';

import testpage from '../utils/testpage';

testpage(function (addTest, done) {
addTest('uuidv1()', uuidv1());

done();
});
9 changes: 9 additions & 0 deletions examples/browser-webpack/example-v4.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<!DOCTYPE html>
<html>
<head>
<title>UUID esmodule webpack example</title>
</head>
<body>
<script type="text/javascript" src="./dist/v4.js"></script>
</body>
</html>
9 changes: 9 additions & 0 deletions examples/browser-webpack/example-v4.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { v4 as uuidv4 } from 'uuid';

import testpage from '../utils/testpage';

testpage(function (addTest, done) {
addTest('uuidv4()', uuidv4());

done();
});
6 changes: 6 additions & 0 deletions examples/browser-webpack/example.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<!DOCTYPE html>
<title>UUID esmodule webpack example</title>
<p>Please open the Developer Console to view output</p>
<script type="text/javascript" src="./dist/v1.js"></script>
<script type="text/javascript" src="./dist/v4.js"></script>
<script type="text/javascript" src="./dist/all.js"></script>
2,280 changes: 2,280 additions & 0 deletions examples/browser-webpack/package-lock.json

Large diffs are not rendered by default.

16 changes: 16 additions & 0 deletions examples/browser-webpack/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "uuid-example-browser-webpack",
"version": "0.0.0",
"private": true,
"scripts": {
"build": "rm -rf dist && webpack",
"start": "npm run build && npx http-server . -o"
},
"dependencies": {
"uuid": "file:../../.local/uuid"
},
"devDependencies": {
"webpack": "^5.74.0",
"webpack-cli": "^4.10.0"
}
}
3 changes: 3 additions & 0 deletions examples/browser-webpack/size-v1.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { v1 as uuidv1 } from 'uuid';

uuidv1();
3 changes: 3 additions & 0 deletions examples/browser-webpack/size-v3.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { v3 as uuidv3 } from 'uuid';

uuidv3();
3 changes: 3 additions & 0 deletions examples/browser-webpack/size-v4.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { v4 as uuidv4 } from 'uuid';

uuidv4();
3 changes: 3 additions & 0 deletions examples/browser-webpack/size-v5.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { v5 as uuidv5 } from 'uuid';

uuidv5();
23 changes: 23 additions & 0 deletions examples/browser-webpack/webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
module.exports = {
resolve: {
extensions: ['*', '.js'],
},
entry: {
all: './example-all.js',
allRequire: './example-all-require.js',
v1: './example-v1.js',
v4: './example-v4.js',

'v1-size': './size-v1.js',
'v3-size': './size-v3.js',
'v4-size': './size-v4.js',
'v5-size': './size-v5.js',
},
// Webpack now produces builds that are incompatible with IE11:
// https://webpack.js.org/migrate/5/#turn-off-es2015-syntax-in-runtime-code-if-necessary
target: ['web', 'es5'],
output: {
filename: '[name].js',
},
mode: 'production',
};
6 changes: 6 additions & 0 deletions examples/node-commonjs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# uuid example Node.js CommonJS

```
npm install
npm test
```
70 changes: 70 additions & 0 deletions examples/node-commonjs/example.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
const {
NIL: NIL_UUID,
parse: uuidParse,
stringify: uuidStringify,
v1: uuidv1,
v3: uuidv3,
v4: uuidv4,
v5: uuidv5,
validate: uuidValidate,
version: uuidVersion,
} = require('uuid');
const uuid = require('uuid');
const pkg = require('uuid/package.json');

console.log('uuidv1()', uuidv1());

console.log('uuidv4()', uuidv4());

// ... using predefined DNS namespace (for domain names)
console.log('uuidv3() DNS', uuidv3('hello.example.com', uuidv3.DNS));

// ... using predefined URL namespace (for, well, URLs)
console.log('uuidv3() URL', uuidv3('http://example.com/hello', uuidv3.URL));

// ... using a custom namespace
//
// Note: Custom namespaces should be a UUID string specific to your application!
// E.g. the one here was generated using this modules `uuid` CLI.
const MY_NAMESPACE = '55238d15-c926-4598-b49d-cf4e913ba13c';
console.log('uuidv3() MY_NAMESPACE', uuidv3('Hello, World!', MY_NAMESPACE));

// ... using predefined DNS namespace (for domain names)
console.log('uuidv5() DNS', uuidv5('hello.example.com', uuidv5.DNS));

// ... using predefined URL namespace (for, well, URLs)
console.log('uuidv5() URL', uuidv5('http://example.com/hello', uuidv5.URL));

// ... using a custom namespace
//
// Note: Custom namespaces should be a UUID string specific to your application!
// E.g. the one here was generated using this modules `uuid` CLI.
// const MY_NAMESPACE = '1b671a64-40d5-491e-99b0-da01ff1f3341';
console.log('uuidv5() MY_NAMESPACE', uuidv5('Hello, World!', MY_NAMESPACE));

// Utility functions
console.log('NIL_UUID', NIL_UUID);
console.log('uuidParse()', uuidParse(MY_NAMESPACE));
console.log('uuidStringify()', uuidStringify(uuidParse(MY_NAMESPACE)));
console.log('uuidValidate()', uuidValidate(MY_NAMESPACE));
console.log('uuidVersion()', uuidVersion(MY_NAMESPACE));

console.log('Same with default export');

console.log('uuid.v1()', uuid.v1());
console.log('uuid.v4()', uuid.v4());
console.log('uuid.v3() DNS', uuid.v3('hello.example.com', uuid.v3.DNS));
console.log('uuid.v3() URL', uuid.v3('http://example.com/hello', uuid.v3.URL));
console.log('uuid.v3() MY_NAMESPACE', uuid.v3('Hello, World!', MY_NAMESPACE));
console.log('uuid.v5() DNS', uuid.v5('hello.example.com', uuid.v5.DNS));
console.log('uuid.v5() URL', uuid.v5('http://example.com/hello', uuid.v5.URL));
console.log('uuid.v5() MY_NAMESPACE', uuid.v5('Hello, World!', MY_NAMESPACE));

console.log('uuid.NIL', uuid.NIL);
console.log('uuid.parse()', uuid.parse(MY_NAMESPACE));
console.log('uuid.stringify()', uuid.stringify(uuid.parse(MY_NAMESPACE)));
console.log('uuid.validate()', uuid.validate(MY_NAMESPACE));
console.log('uuid.version()', uuid.version(MY_NAMESPACE));

// Some tools like react-native need to introspect the package.json file
console.log('pkg.name', pkg.name);
87 changes: 87 additions & 0 deletions examples/node-commonjs/package-lock.json
11 changes: 11 additions & 0 deletions examples/node-commonjs/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"name": "uuid-example-node-commonjs",
"version": "0.0.0",
"private": true,
"scripts": {
"test": "node example.js"
},
"dependencies": {
"uuid": "file:../../.local/uuid"
}
}
6 changes: 6 additions & 0 deletions examples/node-esmodules/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# uuid example Node.js ESModules

```
npm install
npm test
```
66 changes: 66 additions & 0 deletions examples/node-esmodules/example.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import {
NIL as NIL_UUID,
parse as uuidParse,
stringify as uuidStringify,
v1 as uuidv1,
v3 as uuidv3,
v4 as uuidv4,
v5 as uuidv5,
validate as uuidValidate,
version as uuidVersion,
} from 'uuid';
import * as uuid from 'uuid';

console.log('uuidv1()', uuidv1());

console.log('uuidv4()', uuidv4());

// ... using predefined DNS namespace (for domain names)
console.log('uuidv3() DNS', uuidv3('hello.example.com', uuidv3.DNS));

// ... using predefined URL namespace (for, well, URLs)
console.log('uuidv3() URL', uuidv3('http://example.com/hello', uuidv3.URL));

// ... using a custom namespace
//
// Note: Custom namespaces should be a UUID string specific to your application!
// E.g. the one here was generated using this modules `uuid` CLI.
const MY_NAMESPACE = '55238d15-c926-4598-b49d-cf4e913ba13c';
console.log('uuidv3() MY_NAMESPACE', uuidv3('Hello, World!', MY_NAMESPACE));

// ... using predefined DNS namespace (for domain names)
console.log('uuidv5() DNS', uuidv5('hello.example.com', uuidv5.DNS));

// ... using predefined URL namespace (for, well, URLs)
console.log('uuidv5() URL', uuidv5('http://example.com/hello', uuidv5.URL));

// ... using a custom namespace
//
// Note: Custom namespaces should be a UUID string specific to your application!
// E.g. the one here was generated using this modules `uuid` CLI.
// const MY_NAMESPACE = '1b671a64-40d5-491e-99b0-da01ff1f3341';
console.log('uuidv5() MY_NAMESPACE', uuidv5('Hello, World!', MY_NAMESPACE));

// Utility functions
console.log('NIL_UUID', NIL_UUID);
console.log('uuidParse()', uuidParse(MY_NAMESPACE));
console.log('uuidStringify()', uuidStringify(uuidParse(MY_NAMESPACE)));
console.log('uuidValidate()', uuidValidate(MY_NAMESPACE));
console.log('uuidVersion()', uuidVersion(MY_NAMESPACE));

console.log('Same with default export');

console.log('uuid.v1()', uuid.v1());
console.log('uuid.v4()', uuid.v4());
console.log('uuid.v3() DNS', uuid.v3('hello.example.com', uuid.v3.DNS));
console.log('uuid.v3() URL', uuid.v3('http://example.com/hello', uuid.v3.URL));
console.log('uuid.v3() MY_NAMESPACE', uuid.v3('Hello, World!', MY_NAMESPACE));
console.log('uuid.v5() DNS', uuid.v5('hello.example.com', uuid.v5.DNS));
console.log('uuid.v5() URL', uuid.v5('http://example.com/hello', uuid.v5.URL));
console.log('uuid.v5() MY_NAMESPACE', uuid.v5('Hello, World!', MY_NAMESPACE));

console.log('uuid.NIL', uuid.NIL);
console.log('uuid.parse()', uuid.parse(MY_NAMESPACE));
console.log('uuid.stringify()', uuid.stringify(uuid.parse(MY_NAMESPACE)));
console.log('uuid.validate()', uuid.validate(MY_NAMESPACE));
console.log('uuid.version()', uuid.version(MY_NAMESPACE));
87 changes: 87 additions & 0 deletions examples/node-esmodules/package-lock.json
13 changes: 13 additions & 0 deletions examples/node-esmodules/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"name": "uuid-example-node-esmodules",
"version": "0.0.0",
"private": true,
"scripts": {
"test:package": "( node --version | grep -vq 'v16' ) || ( node --experimental-json-modules package.mjs )",
"test:example": "node example.mjs",
"test": "npm-run-all test:*"
},
"dependencies": {
"uuid": "file:../../.local/uuid"
}
}
4 changes: 4 additions & 0 deletions examples/node-esmodules/package.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import pkg from 'uuid/package.json' assert { type: 'json' };

// Some tools like react-native need to introspect the package.json file
console.log('pkg.name', pkg.name);
6 changes: 6 additions & 0 deletions examples/node-jest/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# uuid example Node.js Jest

```
npm install
npm test
```
8 changes: 8 additions & 0 deletions examples/node-jest/jsdom.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/** @jest-environment jsdom */

const uuid = require('uuid');

test('uuidv4()', () => {
const val = uuid.v4();
expect(uuid.version(val)).toBe(4);
});
6 changes: 6 additions & 0 deletions examples/node-jest/node.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
const uuid = require('uuid');

test('uuidv4()', () => {
const val = uuid.v4();
expect(uuid.version(val)).toBe(4);
});
7,227 changes: 7,227 additions & 0 deletions examples/node-jest/package-lock.json

Large diffs are not rendered by default.

15 changes: 15 additions & 0 deletions examples/node-jest/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "uuid-example-node-jest",
"version": "0.0.0",
"private": true,
"scripts": {
"test": "jest"
},
"dependencies": {
"uuid": "file:../../.local/uuid"
},
"devDependencies": {
"jest": "^29.0.0",
"jest-environment-jsdom": "^29.0.0"
}
}
1 change: 1 addition & 0 deletions examples/node-webpack/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dist/
8 changes: 8 additions & 0 deletions examples/node-webpack/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# uuid example Node.js with Webpack

```
npm install
npm test
```

This will run webpack and execute the resulting bundles in `./dist`.
42 changes: 42 additions & 0 deletions examples/node-webpack/example-all.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { v1 as uuidv1, v4 as uuidv4, v3 as uuidv3, v5 as uuidv5 } from 'uuid';
import * as uuid from 'uuid';

console.log('uuidv1()', uuidv1());
console.log('uuidv4()', uuidv4());

// ... using predefined DNS namespace (for domain names)
console.log('uuidv3() DNS', uuidv3('hello.example.com', uuidv3.DNS));

// ... using predefined URL namespace (for, well, URLs)
console.log('uuidv3() URL', uuidv3('http://example.com/hello', uuidv3.URL));

// ... using a custom namespace
//
// Note: Custom namespaces should be a UUID string specific to your application!
// E.g. the one here was generated using this modules `uuid` CLI.
const MY_NAMESPACE = '55238d15-c926-4598-b49d-cf4e913ba13c';
console.log('uuidv3() MY_NAMESPACE', uuidv3('Hello, World!', MY_NAMESPACE));

// ... using predefined DNS namespace (for domain names)
console.log('uuidv5() DNS', uuidv5('hello.example.com', uuidv5.DNS));

// ... using predefined URL namespace (for, well, URLs)
console.log('uuidv5() URL', uuidv5('http://example.com/hello', uuidv5.URL));

// ... using a custom namespace
//
// Note: Custom namespaces should be a UUID string specific to your application!
// E.g. the one here was generated using this modules `uuid` CLI.
// const MY_NAMESPACE = '1b671a64-40d5-491e-99b0-da01ff1f3341';
console.log('uuidv5() MY_NAMESPACE', uuidv5('Hello, World!', MY_NAMESPACE));

console.log('Same with default export');

console.log('uuid.v1()', uuid.v1());
console.log('uuid.v4()', uuid.v4());
console.log('uuid.v3() DNS', uuid.v3('hello.example.com', uuid.v3.DNS));
console.log('uuid.v3() URL', uuid.v3('http://example.com/hello', uuid.v3.URL));
console.log('uuid.v3() MY_NAMESPACE', uuid.v3('Hello, World!', MY_NAMESPACE));
console.log('uuid.v5() DNS', uuid.v5('hello.example.com', uuid.v5.DNS));
console.log('uuid.v5() URL', uuid.v5('http://example.com/hello', uuid.v5.URL));
console.log('uuid.v5() MY_NAMESPACE', uuid.v5('Hello, World!', MY_NAMESPACE));
3 changes: 3 additions & 0 deletions examples/node-webpack/example-v1.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { v1 as uuidv1 } from 'uuid';

console.log('uuidv1()', uuidv1());
3 changes: 3 additions & 0 deletions examples/node-webpack/example-v4.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { v4 as uuidv4 } from 'uuid';

console.log('uuidv4()', uuidv4());
2,280 changes: 2,280 additions & 0 deletions examples/node-webpack/package-lock.json

Large diffs are not rendered by default.

16 changes: 16 additions & 0 deletions examples/node-webpack/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "uuid-example-node-webpack",
"version": "0.0.0",
"private": true,
"scripts": {
"build": "rm -rf dist && webpack",
"test": "npm run build && node dist/v1.js && node dist/v4.js && node dist/all.js"
},
"dependencies": {
"uuid": "file:../../.local/uuid"
},
"devDependencies": {
"webpack": "^5.74.0",
"webpack-cli": "^4.10.0"
}
}
15 changes: 15 additions & 0 deletions examples/node-webpack/webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module.exports = {
resolve: {
extensions: ['*', '.js'],
},
entry: {
all: './example-all.js',
v1: './example-v1.js',
v4: './example-v4.js',
},
output: {
filename: '[name].js',
},
mode: 'production',
target: 'node',
};
42 changes: 42 additions & 0 deletions examples/utils/testpage.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
export default function test(callback) {
const style = document.createElement('style');
style.appendChild(
document.createTextNode(
[
'body {font-family: monospace;}',
'dt, dd {display: inline-block; margin: 0;}',
'dt {min-width: 15em;}',
].join('\n')
)
);
document.body.appendChild(style);

function addTest(title, result) {
// join() result if it's array-like
if (result instanceof Uint8Array || Array.isArray(result)) {
result = Array.prototype.join.apply(result);
}

let el;
if (result === undefined) {
el = document.createElement('h2');
el.innerHTML = title;
} else {
el = document.createElement('div');
el.className = 'test_result';
el.innerHTML = '<dt>' + title + '</dt>: <dd>' + result + '</dd>';
}

document.body.appendChild(el);
}

function done() {
const div = document.createElement('h2');
div.id = 'done';
document.body.appendChild(div);
}

window.onload = function () {
callback(addTest, done);
};
}
8 changes: 0 additions & 8 deletions index.js

This file was deleted.

24 changes: 0 additions & 24 deletions lib/bytesToUuid.js

This file was deleted.

25 changes: 0 additions & 25 deletions lib/md5.js

This file was deleted.

34 changes: 0 additions & 34 deletions lib/rng-browser.js

This file was deleted.

8 changes: 0 additions & 8 deletions lib/rng.js

This file was deleted.

89 changes: 0 additions & 89 deletions lib/sha1-browser.js

This file was deleted.

25 changes: 0 additions & 25 deletions lib/sha1.js

This file was deleted.

57 changes: 0 additions & 57 deletions lib/v35.js

This file was deleted.

24,379 changes: 21,349 additions & 3,030 deletions package-lock.json

Large diffs are not rendered by default.

125 changes: 106 additions & 19 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "uuid",
"version": "3.3.3",
"version": "9.0.0",
"description": "RFC4122 (v1, v4, and v5) UUIDs",
"commitlint": {
"extends": [
@@ -14,31 +14,118 @@
],
"license": "MIT",
"bin": {
"uuid": "./bin/uuid"
"uuid": "./dist/bin/uuid"
},
"sideEffects": false,
"main": "./dist/index.js",
"exports": {
".": {
"node": {
"module": "./dist/esm-node/index.js",
"require": "./dist/index.js",
"import": "./wrapper.mjs"
},
"browser": {
"import": "./dist/esm-browser/index.js",
"require": "./dist/commonjs-browser/index.js"
},
"default": "./dist/esm-browser/index.js"
},
"./package.json": "./package.json"
},
"module": "./dist/esm-node/index.js",
"browser": {
"./dist/md5.js": "./dist/md5-browser.js",
"./dist/native.js": "./dist/native-browser.js",
"./dist/rng.js": "./dist/rng-browser.js",
"./dist/sha1.js": "./dist/sha1-browser.js",
"./dist/esm-node/index.js": "./dist/esm-browser/index.js"
},
"files": [
"CHANGELOG.md",
"CONTRIBUTING.md",
"LICENSE.md",
"README.md",
"dist",
"wrapper.mjs"
],
"devDependencies": {
"@commitlint/cli": "8.1.0",
"@commitlint/config-conventional": "8.1.0",
"eslint": "6.2.0",
"husky": "3.0.4",
"mocha": "6.2.0",
"runmd": "1.2.1",
"standard-version": "7.0.0"
"@babel/cli": "7.18.10",
"@babel/core": "7.18.10",
"@babel/eslint-parser": "7.18.9",
"@babel/preset-env": "7.18.10",
"@commitlint/cli": "17.0.3",
"@commitlint/config-conventional": "17.0.3",
"bundlewatch": "0.3.3",
"eslint": "8.21.0",
"eslint-config-prettier": "8.5.0",
"eslint-config-standard": "17.0.0",
"eslint-plugin-import": "2.26.0",
"eslint-plugin-node": "11.1.0",
"eslint-plugin-prettier": "4.2.1",
"eslint-plugin-promise": "6.0.0",
"husky": "8.0.1",
"jest": "28.1.3",
"lint-staged": "13.0.3",
"npm-run-all": "4.1.5",
"optional-dev-dependency": "2.0.1",
"prettier": "2.7.1",
"random-seed": "0.3.0",
"runmd": "1.3.6",
"standard-version": "9.5.0"
},
"optionalDevDependencies": {
"@wdio/browserstack-service": "7.16.10",
"@wdio/cli": "7.16.10",
"@wdio/jasmine-framework": "7.16.6",
"@wdio/local-runner": "7.16.10",
"@wdio/spec-reporter": "7.16.9",
"@wdio/static-server-service": "7.16.6"
},
"scripts": {
"commitmsg": "commitlint -E HUSKY_GIT_PARAMS",
"test": "mocha test/test.js",
"examples:browser:webpack:build": "cd examples/browser-webpack && npm install && npm run build",
"examples:browser:rollup:build": "cd examples/browser-rollup && npm install && npm run build",
"examples:node:commonjs:test": "cd examples/node-commonjs && npm install && npm test",
"examples:node:esmodules:test": "cd examples/node-esmodules && npm install && npm test",
"examples:node:jest:test": "cd examples/node-jest && npm install && npm test",
"prepare": "cd $( git rev-parse --show-toplevel ) && husky install",
"lint": "npm run eslint:check && npm run prettier:check",
"eslint:check": "eslint src/ test/ examples/ *.js",
"eslint:fix": "eslint --fix src/ test/ examples/ *.js",
"pretest": "[ -n $CI ] || npm run build",
"test": "BABEL_ENV=commonjsNode node --throw-deprecation node_modules/.bin/jest test/unit/",
"pretest:browser": "optional-dev-dependency && npm run build && npm-run-all --parallel examples:browser:**",
"test:browser": "wdio run ./wdio.conf.js",
"pretest:node": "npm run build",
"test:node": "npm-run-all --parallel examples:node:**",
"test:pack": "./scripts/testpack.sh",
"pretest:benchmark": "npm run build",
"test:benchmark": "cd examples/benchmark && npm install && npm test",
"prettier:check": "prettier --check '**/*.{js,jsx,json,md}'",
"prettier:fix": "prettier --write '**/*.{js,jsx,json,md}'",
"bundlewatch": "npm run pretest:browser && bundlewatch --config bundlewatch.config.json",
"md": "runmd --watch --output=README.md README_js.md",
"release": "standard-version",
"prepare": "runmd --output=README.md README_js.md"
},
"browser": {
"./lib/rng.js": "./lib/rng-browser.js",
"./lib/sha1.js": "./lib/sha1-browser.js",
"./lib/md5.js": "./lib/md5-browser.js"
"docs": "( node --version | grep -q 'v16' ) && ( npm run build && runmd --output=README.md README_js.md )",
"docs:diff": "npm run docs && git diff --quiet README.md",
"build": "./scripts/build.sh",
"prepack": "npm run build",
"release": "standard-version --no-verify"
},
"repository": {
"type": "git",
"url": "https://github.com/kelektiv/node-uuid.git"
"url": "https://github.com/uuidjs/uuid.git"
},
"lint-staged": {
"*.{js,jsx,json,md}": [
"prettier --write"
],
"*.{js,jsx}": [
"eslint --fix"
]
},
"standard-version": {
"scripts": {
"postchangelog": "prettier --write CHANGELOG.md"
}
}
}
7 changes: 7 additions & 0 deletions prettier.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module.exports = {
arrowParens: 'always',
printWidth: 100,
proseWrap: 'never',
singleQuote: true,
trailingComma: 'es5',
};
62 changes: 62 additions & 0 deletions scripts/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#!/bin/bash -eu

# cd to the root dir
ROOT="$(pwd)/$(dirname "$0")/.."
cd "$ROOT" || exit 1

PATH="$(npm bin):$PATH"
DIR="$ROOT/dist"

# Clean up output dir
rm -rf "$DIR"
mkdir -p "$DIR"

# We ship 4 builds of this library: ESM and CommonJS, each for Node.js and the Browser.
# In ./src, code that uses browser APIs lives in `-browser.js` files, while code for node APIs
# lives in files without suffix.
# For historical reasons, the Node.js CommonJS build lives in the top level ./dist directory while
# the other 3 builds live in their respective ./dist/{commonjs,esm}-{node,browser}/ subdirectories.
#
# The code below produces this layout:
#
# dist (<-- the commonjs-node build)
# ├── commonjs-browser
# ├── esm-node
# ├── esm-node
# └── bin (<-- Node.js CLI)

# Transpile CommonJS versions of files for node
babel --env-name commonjsNode src --source-root src --out-dir "$DIR" --copy-files --quiet

# Transpile CommonJS versions of files for the browser
babel --env-name commonjsBrowser src --source-root src --out-dir "$DIR/commonjs-browser" \
--copy-files --quiet

# Transpile ESM versions of files for the browser
babel --env-name esmBrowser src --source-root src --out-dir "$DIR/esm-browser" --copy-files --quiet

# Transpile ESM versions of files for node
babel --env-name esmNode src --source-root src --out-dir "$DIR/esm-node" --copy-files --quiet

# No need to have the CLI files in the esm build
rm -rf "$DIR/commonjs-browser/bin"
rm -rf "$DIR/commonjs-browser/uuid-bin.js"
rm -rf "$DIR/esm-browser/bin"
rm -rf "$DIR/esm-browser/uuid-bin.js"
rm -rf "$DIR/esm-node/bin"
rm -rf "$DIR/esm-node/uuid-bin.js"

for FILE in "$DIR"/commonjs-browser/*-browser.js
do
echo "Replacing node-specific file for commonjs-browser: $FILE"
mv "$FILE" "${FILE/-browser.js/.js}"
done

for FILE in "$DIR"/esm-browser/*-browser.js
do
echo "Replacing node-specific file for esm-browser: $FILE"
mv "$FILE" "${FILE/-browser.js/.js}"
done

echo "Removing browser-specific files from esm-node"
rm -f "$DIR"/esm-node/*-browser.js
27 changes: 27 additions & 0 deletions scripts/testpack.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/bin/bash -eu

# cd to the root dir
ROOT="$(pwd)/$(dirname "$0")/.."
cd "$ROOT" || exit 1

npm pack

mkdir -p ../test-pack

cp examples/node-commonjs/example.js ../test-pack/commonjs.js
cp examples/node-esmodules/example.mjs ../test-pack/esmodules.mjs
cp examples/node-esmodules/package.mjs ../test-pack/esmodules-package.mjs

cd ../test-pack

npm init -y

npm install ../uuid/uuid-*.tgz

node commonjs.js
node esmodules.mjs

# Support for json esm imports requires import assertions starting in Node.js v16.14.0 which were
# not supported in earlier versions. Therefore we restrict the ESM test to more recent versions of
# Node.js:
( node --version | grep -vq 'v16' ) || ( node --experimental-json-modules esmodules-package.mjs )
2 changes: 2 additions & 0 deletions src/bin/uuid
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/usr/bin/env node
require('../uuid-bin');
9 changes: 9 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export { default as v1 } from './v1.js';
export { default as v3 } from './v3.js';
export { default as v4 } from './v4.js';
export { default as v5 } from './v5.js';
export { default as NIL } from './nil.js';
export { default as version } from './version.js';
export { default as validate } from './validate.js';
export { default as stringify } from './stringify.js';
export { default as parse } from './parse.js';
139 changes: 70 additions & 69 deletions lib/md5-browser.js → src/md5-browser.js
Original file line number Diff line number Diff line change
@@ -18,69 +18,64 @@
* Distributed under the BSD License
* See http://pajhome.org.uk/crypt/md5 for more info.
*/
function md5(bytes) {
if (typeof bytes === 'string') {
const msg = unescape(encodeURIComponent(bytes)); // UTF8 escape

'use strict';
bytes = new Uint8Array(msg.length);

function md5(bytes) {
if (typeof(bytes) == 'string') {
var msg = unescape(encodeURIComponent(bytes)); // UTF8 escape
bytes = new Array(msg.length);
for (var i = 0; i < msg.length; i++) bytes[i] = msg.charCodeAt(i);
for (let i = 0; i < msg.length; ++i) {
bytes[i] = msg.charCodeAt(i);
}
}

return md5ToHexEncodedArray(
wordsToMd5(
bytesToWords(bytes)
, bytes.length * 8)
);
return md5ToHexEncodedArray(wordsToMd5(bytesToWords(bytes), bytes.length * 8));
}


/*
* Convert an array of little-endian words to an array of bytes
*/
* Convert an array of little-endian words to an array of bytes
*/
function md5ToHexEncodedArray(input) {
var i;
var x;
var output = [];
var length32 = input.length * 32;
var hexTab = '0123456789abcdef';
var hex;
const output = [];
const length32 = input.length * 32;
const hexTab = '0123456789abcdef';

for (i = 0; i < length32; i += 8) {
x = (input[i >> 5] >>> (i % 32)) & 0xFF;
for (let i = 0; i < length32; i += 8) {
const x = (input[i >> 5] >>> i % 32) & 0xff;

hex = parseInt(hexTab.charAt((x >>> 4) & 0x0F) + hexTab.charAt(x & 0x0F), 16);
const hex = parseInt(hexTab.charAt((x >>> 4) & 0x0f) + hexTab.charAt(x & 0x0f), 16);

output.push(hex);
}

return output;
}

/**
* Calculate output length with padding and bit length
*/
function getOutputLength(inputLength8) {
return (((inputLength8 + 64) >>> 9) << 4) + 14 + 1;
}

/*
* Calculate the MD5 of an array of little-endian words, and a bit length.
*/
* Calculate the MD5 of an array of little-endian words, and a bit length.
*/
function wordsToMd5(x, len) {
/* append padding */
x[len >> 5] |= 0x80 << (len % 32);
x[(((len + 64) >>> 9) << 4) + 14] = len;

var i;
var olda;
var oldb;
var oldc;
var oldd;
var a = 1732584193;
var b = -271733879;
var c = -1732584194;

var d = 271733878;

for (i = 0; i < x.length; i += 16) {
olda = a;
oldb = b;
oldc = c;
oldd = d;
x[len >> 5] |= 0x80 << len % 32;
x[getOutputLength(len) - 1] = len;

let a = 1732584193;
let b = -271733879;
let c = -1732584194;
let d = 271733878;

for (let i = 0; i < x.length; i += 16) {
const olda = a;
const oldb = b;
const oldc = c;
const oldd = d;

a = md5ff(a, b, c, d, x[i], 7, -680876936);
d = md5ff(d, a, b, c, x[i + 1], 12, -389564586);
@@ -155,62 +150,68 @@ function wordsToMd5(x, len) {
c = safeAdd(c, oldc);
d = safeAdd(d, oldd);
}

return [a, b, c, d];
}

/*
* Convert an array bytes to an array of little-endian words
* Characters >255 have their high-byte silently ignored.
*/
* Convert an array bytes to an array of little-endian words
* Characters >255 have their high-byte silently ignored.
*/
function bytesToWords(input) {
var i;
var output = [];
output[(input.length >> 2) - 1] = undefined;
for (i = 0; i < output.length; i += 1) {
output[i] = 0;
if (input.length === 0) {
return [];
}
var length8 = input.length * 8;
for (i = 0; i < length8; i += 8) {
output[i >> 5] |= (input[(i / 8)] & 0xFF) << (i % 32);

const length8 = input.length * 8;

const output = new Uint32Array(getOutputLength(length8));

for (let i = 0; i < length8; i += 8) {
output[i >> 5] |= (input[i / 8] & 0xff) << i % 32;
}

return output;
}

/*
* Add integers, wrapping at 2^32. This uses 16-bit operations internally
* to work around bugs in some JS interpreters.
*/
* Add integers, wrapping at 2^32. This uses 16-bit operations internally
* to work around bugs in some JS interpreters.
*/
function safeAdd(x, y) {
var lsw = (x & 0xFFFF) + (y & 0xFFFF);
var msw = (x >> 16) + (y >> 16) + (lsw >> 16);
return (msw << 16) | (lsw & 0xFFFF);
const lsw = (x & 0xffff) + (y & 0xffff);
const msw = (x >> 16) + (y >> 16) + (lsw >> 16);
return (msw << 16) | (lsw & 0xffff);
}

/*
* Bitwise rotate a 32-bit number to the left.
*/
* Bitwise rotate a 32-bit number to the left.
*/
function bitRotateLeft(num, cnt) {
return (num << cnt) | (num >>> (32 - cnt));
}

/*
* These functions implement the four basic operations the algorithm uses.
*/
* These functions implement the four basic operations the algorithm uses.
*/
function md5cmn(q, a, b, x, s, t) {
return safeAdd(bitRotateLeft(safeAdd(safeAdd(a, q), safeAdd(x, t)), s), b);
}

function md5ff(a, b, c, d, x, s, t) {
return md5cmn((b & c) | ((~b) & d), a, b, x, s, t);
return md5cmn((b & c) | (~b & d), a, b, x, s, t);
}

function md5gg(a, b, c, d, x, s, t) {
return md5cmn((b & d) | (c & (~d)), a, b, x, s, t);
return md5cmn((b & d) | (c & ~d), a, b, x, s, t);
}

function md5hh(a, b, c, d, x, s, t) {
return md5cmn(b ^ c ^ d, a, b, x, s, t);
}

function md5ii(a, b, c, d, x, s, t) {
return md5cmn(c ^ (b | (~d)), a, b, x, s, t);
return md5cmn(c ^ (b | ~d), a, b, x, s, t);
}

module.exports = md5;
export default md5;
13 changes: 13 additions & 0 deletions src/md5.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import crypto from 'crypto';

function md5(bytes) {
if (Array.isArray(bytes)) {
bytes = Buffer.from(bytes);
} else if (typeof bytes === 'string') {
bytes = Buffer.from(bytes, 'utf8');
}

return crypto.createHash('md5').update(bytes).digest();
}

export default md5;
4 changes: 4 additions & 0 deletions src/native-browser.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
const randomUUID =
typeof crypto !== 'undefined' && crypto.randomUUID && crypto.randomUUID.bind(crypto);

export default { randomUUID };
3 changes: 3 additions & 0 deletions src/native.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import crypto from 'crypto';

export default { randomUUID: crypto.randomUUID };
1 change: 1 addition & 0 deletions src/nil.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default '00000000-0000-0000-0000-000000000000';
41 changes: 41 additions & 0 deletions src/parse.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import validate from './validate.js';

function parse(uuid) {
if (!validate(uuid)) {
throw TypeError('Invalid UUID');
}

let v;
const arr = new Uint8Array(16);

// Parse ########-....-....-....-............
arr[0] = (v = parseInt(uuid.slice(0, 8), 16)) >>> 24;
arr[1] = (v >>> 16) & 0xff;
arr[2] = (v >>> 8) & 0xff;
arr[3] = v & 0xff;

// Parse ........-####-....-....-............
arr[4] = (v = parseInt(uuid.slice(9, 13), 16)) >>> 8;
arr[5] = v & 0xff;

// Parse ........-....-####-....-............
arr[6] = (v = parseInt(uuid.slice(14, 18), 16)) >>> 8;
arr[7] = v & 0xff;

// Parse ........-....-....-####-............
arr[8] = (v = parseInt(uuid.slice(19, 23), 16)) >>> 8;
arr[9] = v & 0xff;

// Parse ........-....-....-....-############
// (Use "/" to avoid 32-bit truncation when bit-shifting high-order bytes)
arr[10] = ((v = parseInt(uuid.slice(24, 36), 16)) / 0x10000000000) & 0xff;
arr[11] = (v / 0x100000000) & 0xff;
arr[12] = (v >>> 24) & 0xff;
arr[13] = (v >>> 16) & 0xff;
arr[14] = (v >>> 8) & 0xff;
arr[15] = v & 0xff;

return arr;
}

export default parse;
1 change: 1 addition & 0 deletions src/regex.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default /^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000)$/i;
25 changes: 25 additions & 0 deletions src/rng-browser.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Unique ID creation requires a high quality random # generator. In the browser we therefore
// require the crypto API and do not support built-in fallback to lower quality random number
// generators (like Math.random()).

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) {
// getRandomValues needs to be invoked in a context where "this" is a Crypto implementation.
getRandomValues =
typeof crypto !== 'undefined' &&
crypto.getRandomValues &&
crypto.getRandomValues.bind(crypto);
if (!getRandomValues) {
throw new Error(
'crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported'
);
}
}

return getRandomValues(rnds8);
}
12 changes: 12 additions & 0 deletions src/rng.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import crypto from 'crypto';

const rnds8Pool = new Uint8Array(256); // # of random values to pre-allocate
let poolPtr = rnds8Pool.length;

export default function rng() {
if (poolPtr > rnds8Pool.length - 16) {
crypto.randomFillSync(rnds8Pool);
poolPtr = 0;
}
return rnds8Pool.slice(poolPtr, (poolPtr += 16));
}
119 changes: 119 additions & 0 deletions src/sha1-browser.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
// Adapted from Chris Veness' SHA1 code at
// http://www.movable-type.co.uk/scripts/sha1.html
function f(s, x, y, z) {
switch (s) {
case 0:
return (x & y) ^ (~x & z);
case 1:
return x ^ y ^ z;
case 2:
return (x & y) ^ (x & z) ^ (y & z);
case 3:
return x ^ y ^ z;
}
}

function ROTL(x, n) {
return (x << n) | (x >>> (32 - n));
}

function sha1(bytes) {
const K = [0x5a827999, 0x6ed9eba1, 0x8f1bbcdc, 0xca62c1d6];
const H = [0x67452301, 0xefcdab89, 0x98badcfe, 0x10325476, 0xc3d2e1f0];

if (typeof bytes === 'string') {
const msg = unescape(encodeURIComponent(bytes)); // UTF8 escape

bytes = [];

for (let i = 0; i < msg.length; ++i) {
bytes.push(msg.charCodeAt(i));
}
} else if (!Array.isArray(bytes)) {
// Convert Array-like to Array
bytes = Array.prototype.slice.call(bytes);
}

bytes.push(0x80);

const l = bytes.length / 4 + 2;
const N = Math.ceil(l / 16);
const M = new Array(N);

for (let i = 0; i < N; ++i) {
const arr = new Uint32Array(16);

for (let j = 0; j < 16; ++j) {
arr[j] =
(bytes[i * 64 + j * 4] << 24) |
(bytes[i * 64 + j * 4 + 1] << 16) |
(bytes[i * 64 + j * 4 + 2] << 8) |
bytes[i * 64 + j * 4 + 3];
}

M[i] = arr;
}

M[N - 1][14] = ((bytes.length - 1) * 8) / Math.pow(2, 32);
M[N - 1][14] = Math.floor(M[N - 1][14]);
M[N - 1][15] = ((bytes.length - 1) * 8) & 0xffffffff;

for (let i = 0; i < N; ++i) {
const W = new Uint32Array(80);

for (let t = 0; t < 16; ++t) {
W[t] = M[i][t];
}

for (let t = 16; t < 80; ++t) {
W[t] = ROTL(W[t - 3] ^ W[t - 8] ^ W[t - 14] ^ W[t - 16], 1);
}

let a = H[0];
let b = H[1];
let c = H[2];
let d = H[3];
let e = H[4];

for (let t = 0; t < 80; ++t) {
const s = Math.floor(t / 20);
const T = (ROTL(a, 5) + f(s, b, c, d) + e + K[s] + W[t]) >>> 0;
e = d;
d = c;
c = ROTL(b, 30) >>> 0;
b = a;
a = T;
}

H[0] = (H[0] + a) >>> 0;
H[1] = (H[1] + b) >>> 0;
H[2] = (H[2] + c) >>> 0;
H[3] = (H[3] + d) >>> 0;
H[4] = (H[4] + e) >>> 0;
}

return [
(H[0] >> 24) & 0xff,
(H[0] >> 16) & 0xff,
(H[0] >> 8) & 0xff,
H[0] & 0xff,
(H[1] >> 24) & 0xff,
(H[1] >> 16) & 0xff,
(H[1] >> 8) & 0xff,
H[1] & 0xff,
(H[2] >> 24) & 0xff,
(H[2] >> 16) & 0xff,
(H[2] >> 8) & 0xff,
H[2] & 0xff,
(H[3] >> 24) & 0xff,
(H[3] >> 16) & 0xff,
(H[3] >> 8) & 0xff,
H[3] & 0xff,
(H[4] >> 24) & 0xff,
(H[4] >> 16) & 0xff,
(H[4] >> 8) & 0xff,
H[4] & 0xff,
];
}

export default sha1;
13 changes: 13 additions & 0 deletions src/sha1.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import crypto from 'crypto';

function sha1(bytes) {
if (Array.isArray(bytes)) {
bytes = Buffer.from(bytes);
} else if (typeof bytes === 'string') {
bytes = Buffer.from(bytes, 'utf8');
}

return crypto.createHash('sha1').update(bytes).digest();
}

export default sha1;
54 changes: 54 additions & 0 deletions src/stringify.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import validate from './validate.js';

/**
* Convert array of 16 byte values to UUID string format of the form:
* XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
*/
const byteToHex = [];

for (let i = 0; i < 256; ++i) {
byteToHex.push((i + 0x100).toString(16).slice(1));
}

export function unsafeStringify(arr, offset = 0) {
// Note: Be careful editing this code! It's been tuned for performance
// and works in ways you may not expect. See https://github.com/uuidjs/uuid/pull/434
return (
byteToHex[arr[offset + 0]] +
byteToHex[arr[offset + 1]] +
byteToHex[arr[offset + 2]] +
byteToHex[arr[offset + 3]] +
'-' +
byteToHex[arr[offset + 4]] +
byteToHex[arr[offset + 5]] +
'-' +
byteToHex[arr[offset + 6]] +
byteToHex[arr[offset + 7]] +
'-' +
byteToHex[arr[offset + 8]] +
byteToHex[arr[offset + 9]] +
'-' +
byteToHex[arr[offset + 10]] +
byteToHex[arr[offset + 11]] +
byteToHex[arr[offset + 12]] +
byteToHex[arr[offset + 13]] +
byteToHex[arr[offset + 14]] +
byteToHex[arr[offset + 15]]
).toLowerCase();
}

function stringify(arr, offset = 0) {
const uuid = unsafeStringify(arr, offset);
// Consistency check for valid UUID. If this throws, it's likely due to one
// of the following:
// - One or more input array values don't map to a hex octet (leading to
// "undefined" in the uuid)
// - Invalid input values for the RFC `version` or `variant` fields
if (!validate(uuid)) {
throw TypeError('Stringified UUID is invalid');
}

return uuid;
}

export default stringify;
80 changes: 80 additions & 0 deletions src/uuid-bin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import assert from 'assert';

import v1 from './v1.js';
import v3 from './v3.js';
import v4 from './v4.js';
import v5 from './v5.js';

function usage() {
console.log('Usage:');
console.log(' uuid');
console.log(' uuid v1');
console.log(' uuid v3 <name> <namespace uuid>');
console.log(' uuid v4');
console.log(' uuid v5 <name> <namespace uuid>');
console.log(' uuid --help');
console.log(
'\nNote: <namespace uuid> may be "URL" or "DNS" to use the corresponding UUIDs defined by RFC4122'
);
}

const args = process.argv.slice(2);

if (args.indexOf('--help') >= 0) {
usage();
process.exit(0);
}

const version = args.shift() || 'v4';

switch (version) {
case 'v1':
console.log(v1());
break;

case 'v3': {
const name = args.shift();
let namespace = args.shift();

assert(name != null, 'v3 name not specified');
assert(namespace != null, 'v3 namespace not specified');

if (namespace === 'URL') {
namespace = v3.URL;
}

if (namespace === 'DNS') {
namespace = v3.DNS;
}

console.log(v3(name, namespace));
break;
}

case 'v4':
console.log(v4());
break;

case 'v5': {
const name = args.shift();
let namespace = args.shift();

assert(name != null, 'v5 name not specified');
assert(namespace != null, 'v5 namespace not specified');

if (namespace === 'URL') {
namespace = v5.URL;
}

if (namespace === 'DNS') {
namespace = v5.DNS;
}

console.log(v5(name, namespace));
break;
}

default:
usage();
process.exit(1);
}
68 changes: 37 additions & 31 deletions v1.js → src/v1.js
Original file line number Diff line number Diff line change
@@ -1,61 +1,67 @@
var rng = require('./lib/rng');
var bytesToUuid = require('./lib/bytesToUuid');
import rng from './rng.js';
import { unsafeStringify } from './stringify.js';

// **`v1()` - Generate time-based UUID**
//
// Inspired by https://github.com/LiosK/UUID.js
// and http://docs.python.org/library/uuid.html

var _nodeId;
var _clockseq;
let _nodeId;
let _clockseq;

// Previous uuid creation time
var _lastMSecs = 0;
var _lastNSecs = 0;
let _lastMSecs = 0;
let _lastNSecs = 0;

// See https://github.com/broofa/node-uuid for API details
// See https://github.com/uuidjs/uuid for API details
function v1(options, buf, offset) {
var i = buf && offset || 0;
var b = buf || [];
let i = (buf && offset) || 0;
const b = buf || new Array(16);

options = options || {};
var node = options.node || _nodeId;
var clockseq = options.clockseq !== undefined ? options.clockseq : _clockseq;
let node = options.node || _nodeId;
let clockseq = options.clockseq !== undefined ? options.clockseq : _clockseq;

// node and clockseq need to be initialized to random values if they're not
// specified. We do this lazily to minimize issues related to insufficient
// system entropy. See #189
if (node == null || clockseq == null) {
var seedBytes = rng();
const seedBytes = options.random || (options.rng || rng)();

if (node == null) {
// Per 4.5, create and 48-bit node id, (47 random bits + multicast bit = 1)
node = _nodeId = [
seedBytes[0] | 0x01,
seedBytes[1], seedBytes[2], seedBytes[3], seedBytes[4], seedBytes[5]
seedBytes[1],
seedBytes[2],
seedBytes[3],
seedBytes[4],
seedBytes[5],
];
}

if (clockseq == null) {
// Per 4.2.2, randomize (14 bit) clockseq
clockseq = _clockseq = (seedBytes[6] << 8 | seedBytes[7]) & 0x3fff;
clockseq = _clockseq = ((seedBytes[6] << 8) | seedBytes[7]) & 0x3fff;
}
}

// UUID timestamps are 100 nano-second units since the Gregorian epoch,
// (1582-10-15 00:00). JSNumbers aren't precise enough for this, so
// time is handled internally as 'msecs' (integer milliseconds) and 'nsecs'
// (100-nanoseconds offset from msecs) since unix epoch, 1970-01-01 00:00.
var msecs = options.msecs !== undefined ? options.msecs : new Date().getTime();
let msecs = options.msecs !== undefined ? options.msecs : Date.now();

// Per 4.2.1.2, use count of uuid's generated during the current clock
// cycle to simulate higher resolution clock
var nsecs = options.nsecs !== undefined ? options.nsecs : _lastNSecs + 1;
let nsecs = options.nsecs !== undefined ? options.nsecs : _lastNSecs + 1;

// Time since last uuid creation (in msecs)
var dt = (msecs - _lastMSecs) + (nsecs - _lastNSecs)/10000;
const dt = msecs - _lastMSecs + (nsecs - _lastNSecs) / 10000;

// Per 4.2.1.2, Bump clockseq on clock regression
if (dt < 0 && options.clockseq === undefined) {
clockseq = clockseq + 1 & 0x3fff;
clockseq = (clockseq + 1) & 0x3fff;
}

// Reset nsecs if clock regresses (new clockseq) or we've moved onto a new
@@ -66,7 +72,7 @@ function v1(options, buf, offset) {

// Per 4.2.1.2 Throw error if too many uuids are requested
if (nsecs >= 10000) {
throw new Error('uuid.v1(): Can\'t create more than 10M uuids/sec');
throw new Error("uuid.v1(): Can't create more than 10M uuids/sec");
}

_lastMSecs = msecs;
@@ -77,33 +83,33 @@ function v1(options, buf, offset) {
msecs += 12219292800000;

// `time_low`
var tl = ((msecs & 0xfffffff) * 10000 + nsecs) % 0x100000000;
b[i++] = tl >>> 24 & 0xff;
b[i++] = tl >>> 16 & 0xff;
b[i++] = tl >>> 8 & 0xff;
const tl = ((msecs & 0xfffffff) * 10000 + nsecs) % 0x100000000;
b[i++] = (tl >>> 24) & 0xff;
b[i++] = (tl >>> 16) & 0xff;
b[i++] = (tl >>> 8) & 0xff;
b[i++] = tl & 0xff;

// `time_mid`
var tmh = (msecs / 0x100000000 * 10000) & 0xfffffff;
b[i++] = tmh >>> 8 & 0xff;
const tmh = ((msecs / 0x100000000) * 10000) & 0xfffffff;
b[i++] = (tmh >>> 8) & 0xff;
b[i++] = tmh & 0xff;

// `time_high_and_version`
b[i++] = tmh >>> 24 & 0xf | 0x10; // include version
b[i++] = tmh >>> 16 & 0xff;
b[i++] = ((tmh >>> 24) & 0xf) | 0x10; // include version
b[i++] = (tmh >>> 16) & 0xff;

// `clock_seq_hi_and_reserved` (Per 4.2.2 - include variant)
b[i++] = clockseq >>> 8 | 0x80;
b[i++] = (clockseq >>> 8) | 0x80;

// `clock_seq_low`
b[i++] = clockseq & 0xff;

// `node`
for (var n = 0; n < 6; ++n) {
for (let n = 0; n < 6; ++n) {
b[i + n] = node[n];
}

return buf ? buf : bytesToUuid(b);
return buf || unsafeStringify(b);
}

module.exports = v1;
export default v1;
5 changes: 5 additions & 0 deletions src/v3.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import v35 from './v35.js';
import md5 from './md5.js';

const v3 = v35('v3', 0x30, md5);
export default v3;
Loading