mirror of
https://github.com/hanzoai/uuid.git
synced 2026-09-24 17:04:02 +00:00
feat!: drop node@16 support (#883)
This commit is contained in:
@@ -27,7 +27,7 @@ jobs:
|
|||||||
strategy:
|
strategy:
|
||||||
fail-fast: false
|
fail-fast: false
|
||||||
matrix:
|
matrix:
|
||||||
node-version: [16.x, 18.x, 20.x, 22.x, 24.x]
|
node-version: [18.x, 20.x, 22.x, 24.x]
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
- name: Use Node.js ${{ matrix.node-version }}
|
- name: Use Node.js ${{ matrix.node-version }}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
*.tgz
|
*.tgz
|
||||||
browserstack.err
|
browserstack.err
|
||||||
dist/
|
dist/
|
||||||
|
dist-browser/
|
||||||
.build/
|
.build/
|
||||||
local.log
|
local.log
|
||||||
logs/
|
logs/
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ For the creation of [RFC9562](https://www.rfc-editor.org/rfc/rfc9562.html) (form
|
|||||||
|
|
||||||
- **Complete** - Support for all RFC9562 UUID versions
|
- **Complete** - Support for all RFC9562 UUID versions
|
||||||
- **Cross-platform** - Support for...
|
- **Cross-platform** - Support for...
|
||||||
- ESM & Common JS
|
|
||||||
- [Typescript](#support)
|
- [Typescript](#support)
|
||||||
- [Chrome, Safari, Firefox, and Edge](#support)
|
- [Chrome, Safari, Firefox, and Edge](#support)
|
||||||
- [NodeJS](#support)
|
- [NodeJS](#support)
|
||||||
@@ -19,10 +18,8 @@ For the creation of [RFC9562](https://www.rfc-editor.org/rfc/rfc9562.html) (form
|
|||||||
|
|
||||||
<!-- prettier-ignore -->
|
<!-- prettier-ignore -->
|
||||||
> [!NOTE]
|
> [!NOTE]
|
||||||
> `uuid@11` is now available: See the [CHANGELOG](./CHANGELOG.md) for details. TL;DR:
|
>
|
||||||
> * TypeScript support is now included (remove `@types/uuid` from your dependencies)
|
> As of `uuid@12` CommonJS is no longer supported. See [ESM Module FAQ](https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c).
|
||||||
> * Subtle changes to how the `options` arg is interpreted for `v1()`, `v6()`, and `v7()`. [See details](#options-handling-for-timestamp-uuids)
|
|
||||||
> * Binary UUIDs are now `Uint8Array`s. (May impact callers of `parse()`, `stringify()`, or that pass an `option#buf` argument to `v1()`-`v7()`.)
|
|
||||||
|
|
||||||
## Quickstart
|
## Quickstart
|
||||||
|
|
||||||
@@ -34,20 +31,12 @@ npm install uuid
|
|||||||
|
|
||||||
**2. Create a UUID**
|
**2. Create a UUID**
|
||||||
|
|
||||||
ESM-syntax (must use named exports):
|
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
import { v4 as uuidv4 } from 'uuid';
|
import { v4 as uuidv4 } from 'uuid';
|
||||||
|
|
||||||
uuidv4(); // ⇨ '9b1deb4d-3b7d-4bad-9bdd-2b0d7b3dcb6d'
|
uuidv4(); // ⇨ '9b1deb4d-3b7d-4bad-9bdd-2b0d7b3dcb6d'
|
||||||
```
|
```
|
||||||
|
|
||||||
... CommonJS:
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
const { v4: uuidv4 } = require('uuid');
|
|
||||||
uuidv4(); // ⇨ '1b9d6bcd-bbfd-4b2d-9b5d-ab8dfbbd4bed'
|
|
||||||
```
|
|
||||||
|
|
||||||
For timestamp UUIDs, namespace UUIDs, and other options read on ...
|
For timestamp UUIDs, namespace UUIDs, and other options read on ...
|
||||||
|
|
||||||
## API Summary
|
## API Summary
|
||||||
@@ -198,7 +187,7 @@ Example:
|
|||||||
```javascript
|
```javascript
|
||||||
import { v1 as uuidv1 } from 'uuid';
|
import { v1 as uuidv1 } from 'uuid';
|
||||||
|
|
||||||
uuidv1(); // ⇨ '2c5ea4c0-4067-11e9-9bdd-2b0d7b3dcb6d'
|
uuidv1(); // ⇨ '2c5ea4c0-4067-11e9-9b5d-ab8dfbbd4bed'
|
||||||
```
|
```
|
||||||
|
|
||||||
Example using `options`:
|
Example using `options`:
|
||||||
@@ -253,7 +242,7 @@ Example:
|
|||||||
```javascript
|
```javascript
|
||||||
import { v4 as uuidv4 } from 'uuid';
|
import { v4 as uuidv4 } from 'uuid';
|
||||||
|
|
||||||
uuidv4(); // ⇨ '9b1deb4d-3b7d-4bad-9bdd-2b0d7b3dcb6d'
|
uuidv4(); // ⇨ '1b9d6bcd-bbfd-4b2d-9b5d-ab8dfbbd4bed'
|
||||||
```
|
```
|
||||||
|
|
||||||
Example using predefined `random` values:
|
Example using predefined `random` values:
|
||||||
@@ -329,7 +318,7 @@ This method takes the same arguments as uuid.v1().
|
|||||||
```javascript
|
```javascript
|
||||||
import { v6 as uuidv6 } from 'uuid';
|
import { v6 as uuidv6 } from 'uuid';
|
||||||
|
|
||||||
uuidv6(); // ⇨ '1e940672-c5ea-64c0-9b5d-ab8dfbbd4bed'
|
uuidv6(); // ⇨ '1e940672-c5ea-64c1-9bdd-2b0d7b3dcb6d'
|
||||||
```
|
```
|
||||||
|
|
||||||
Example using `options`:
|
Example using `options`:
|
||||||
@@ -376,7 +365,7 @@ Example:
|
|||||||
```javascript
|
```javascript
|
||||||
import { v7 as uuidv7 } from 'uuid';
|
import { v7 as uuidv7 } from 'uuid';
|
||||||
|
|
||||||
uuidv7(); // ⇨ '01695553-c90c-705a-b56d-778dfbbd4bed'
|
uuidv7(); // ⇨ '01695553-c90c-745a-b76f-770d7b3dcb6d'
|
||||||
```
|
```
|
||||||
|
|
||||||
### ~~uuid.v8()~~
|
### ~~uuid.v8()~~
|
||||||
@@ -483,7 +472,7 @@ Prior to `uuid@11`, it was possible for `options` state to interfere with the in
|
|||||||
|
|
||||||
**Browsers**: `uuid` [builds are tested](/uuidjs/uuid/blob/main/wdio.conf.js) against the latest version of desktop Chrome, Safari, Firefox, and Edge. Mobile versions of these same browsers are expected to work but aren't currently tested.
|
**Browsers**: `uuid` [builds are tested](/uuidjs/uuid/blob/main/wdio.conf.js) against the latest version of desktop Chrome, Safari, Firefox, and Edge. Mobile versions of these same browsers are expected to work but aren't currently tested.
|
||||||
|
|
||||||
**Node**: `uuid` [builds are tested](https://github.com/uuidjs/uuid/blob/main/.github/workflows/ci.yml#L26-L27) against node ([LTS releases](https://github.com/nodejs/Release)), plus one prior. E.g. `node@18` is in maintainence mode, and `node@22` is the current LTS release. So `uuid` supports `node@16`-`node@22`.
|
**Node**: `uuid` [builds are tested](https://github.com/uuidjs/uuid/blob/main/.github/workflows/ci.yml#L26-L27) against node ([LTS releases](https://github.com/nodejs/Release)), plus one prior. E.g. At the time of this writing `node@20` is the "maintenance" release and `node@24` is the "current" release, so `uuid` supports `node@18`-`node@24`.
|
||||||
|
|
||||||
**Typescript**: TS versions released within the past two years are supported. [source](https://github.com/microsoft/TypeScript/issues/49088#issuecomment-2468723715)
|
**Typescript**: TS versions released within the past two years are supported. [source](https://github.com/microsoft/TypeScript/issues/49088#issuecomment-2468723715)
|
||||||
|
|
||||||
|
|||||||
+9
-18
@@ -1,20 +1,22 @@
|
|||||||
```javascript --hide
|
```javascript --hide
|
||||||
|
import crypto from 'crypto';
|
||||||
|
|
||||||
runmd.onRequire = (path) => {
|
runmd.onRequire = (path) => {
|
||||||
if (path == 'rng') return fun;
|
if (path == 'rng') return fun;
|
||||||
return path.replace(/^uuid/, './dist/cjs/');
|
return path.replace(/^uuid/, './dist/');
|
||||||
};
|
};
|
||||||
|
|
||||||
// Shim Date and crypto so generated ids are consistent across doc revisions
|
// Shim Date and crypto so generated ids are consistent across doc revisions
|
||||||
runmd.Date.now = () => 1551914748172;
|
runmd.Date.now = () => 1551914748172;
|
||||||
|
|
||||||
let seed = 0xdefaced;
|
let seed = 0xdefaced;
|
||||||
require('crypto').randomFillSync = function (a) {
|
crypto.randomFillSync = function (a) {
|
||||||
for (let i = 0; i < 16; i++) a[i] = (seed = (seed * 0x41a7) & 0x7fffffff) & 0xff;
|
for (let i = 0; i < a.length; i++) a[i] = (seed = (seed * 0x41a7) & 0x7fffffff) & 0xff;
|
||||||
return a;
|
return a;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Prevent usage of native randomUUID implementation to ensure deterministic UUIDs
|
// Prevent usage of native randomUUID implementation to ensure deterministic UUIDs
|
||||||
require('crypto').randomUUID = undefined;
|
crypto.randomUUID = undefined;
|
||||||
```
|
```
|
||||||
|
|
||||||
# uuid [](https://github.com/uuidjs/uuid/actions?query=workflow%3ACI) [](https://github.com/uuidjs/uuid/actions/workflows/browser.yml)
|
# uuid [](https://github.com/uuidjs/uuid/actions?query=workflow%3ACI) [](https://github.com/uuidjs/uuid/actions/workflows/browser.yml)
|
||||||
@@ -23,7 +25,6 @@ For the creation of [RFC9562](https://www.rfc-editor.org/rfc/rfc9562.html) (form
|
|||||||
|
|
||||||
- **Complete** - Support for all RFC9562 UUID versions
|
- **Complete** - Support for all RFC9562 UUID versions
|
||||||
- **Cross-platform** - Support for...
|
- **Cross-platform** - Support for...
|
||||||
- ESM & Common JS
|
|
||||||
- [Typescript](#support)
|
- [Typescript](#support)
|
||||||
- [Chrome, Safari, Firefox, and Edge](#support)
|
- [Chrome, Safari, Firefox, and Edge](#support)
|
||||||
- [NodeJS](#support)
|
- [NodeJS](#support)
|
||||||
@@ -34,10 +35,8 @@ For the creation of [RFC9562](https://www.rfc-editor.org/rfc/rfc9562.html) (form
|
|||||||
|
|
||||||
<!-- prettier-ignore -->
|
<!-- prettier-ignore -->
|
||||||
> [!NOTE]
|
> [!NOTE]
|
||||||
> `uuid@11` is now available: See the [CHANGELOG](./CHANGELOG.md) for details. TL;DR:
|
>
|
||||||
> * TypeScript support is now included (remove `@types/uuid` from your dependencies)
|
> As of `uuid@12` CommonJS is no longer supported. See [ESM Module FAQ](https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c).
|
||||||
> * Subtle changes to how the `options` arg is interpreted for `v1()`, `v6()`, and `v7()`. [See details](#options-handling-for-timestamp-uuids)
|
|
||||||
> * Binary UUIDs are now `Uint8Array`s. (May impact callers of `parse()`, `stringify()`, or that pass an `option#buf` argument to `v1()`-`v7()`.)
|
|
||||||
|
|
||||||
## Quickstart
|
## Quickstart
|
||||||
|
|
||||||
@@ -49,17 +48,9 @@ npm install uuid
|
|||||||
|
|
||||||
**2. Create a UUID**
|
**2. Create a UUID**
|
||||||
|
|
||||||
ESM-syntax (must use named exports):
|
|
||||||
|
|
||||||
```javascript --run
|
```javascript --run
|
||||||
import { v4 as uuidv4 } from 'uuid';
|
import { v4 as uuidv4 } from 'uuid';
|
||||||
uuidv4(); // RESULT
|
|
||||||
```
|
|
||||||
|
|
||||||
... CommonJS:
|
|
||||||
|
|
||||||
```javascript --run
|
|
||||||
const { v4: uuidv4 } = require('uuid');
|
|
||||||
uuidv4(); // RESULT
|
uuidv4(); // RESULT
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -492,7 +483,7 @@ Prior to `uuid@11`, it was possible for `options` state to interfere with the in
|
|||||||
|
|
||||||
**Browsers**: `uuid` [builds are tested](/uuidjs/uuid/blob/main/wdio.conf.js) against the latest version of desktop Chrome, Safari, Firefox, and Edge. Mobile versions of these same browsers are expected to work but aren't currently tested.
|
**Browsers**: `uuid` [builds are tested](/uuidjs/uuid/blob/main/wdio.conf.js) against the latest version of desktop Chrome, Safari, Firefox, and Edge. Mobile versions of these same browsers are expected to work but aren't currently tested.
|
||||||
|
|
||||||
**Node**: `uuid` [builds are tested](https://github.com/uuidjs/uuid/blob/main/.github/workflows/ci.yml#L26-L27) against node ([LTS releases](https://github.com/nodejs/Release)), plus one prior. E.g. `node@18` is in maintainence mode, and `node@22` is the current LTS release. So `uuid` supports `node@16`-`node@22`.
|
**Node**: `uuid` [builds are tested](https://github.com/uuidjs/uuid/blob/main/.github/workflows/ci.yml#L26-L27) against node ([LTS releases](https://github.com/nodejs/Release)), plus one prior. E.g. At the time of this writing `node@20` is the "maintenance" release and `node@24` is the "current" release, so `uuid` supports `node@18`-`node@24`.
|
||||||
|
|
||||||
**Typescript**: TS versions released within the past two years are supported. [source](https://github.com/microsoft/TypeScript/issues/49088#issuecomment-2468723715)
|
**Typescript**: TS versions released within the past two years are supported. [source](https://github.com/microsoft/TypeScript/issues/49088#issuecomment-2468723715)
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
const { nodeResolve } = require('@rollup/plugin-node-resolve');
|
import { nodeResolve } from '@rollup/plugin-node-resolve';
|
||||||
const terser = require('@rollup/plugin-terser');
|
import terser from '@rollup/plugin-terser';
|
||||||
|
|
||||||
const plugins = [nodeResolve({ browser: true }), terser()];
|
const plugins = [nodeResolve({ browser: true }), terser()];
|
||||||
module.exports = [
|
export default [
|
||||||
{
|
{
|
||||||
input: './example-all.js',
|
input: './example-all.js',
|
||||||
output: {
|
output: {
|
||||||
@@ -44,7 +44,7 @@ module.exports = [
|
|||||||
input: './size-v1.js',
|
input: './size-v1.js',
|
||||||
output: {
|
output: {
|
||||||
file: 'dist/v1-size.js',
|
file: 'dist/v1-size.js',
|
||||||
format: 'cjs',
|
format: 'es',
|
||||||
},
|
},
|
||||||
plugins,
|
plugins,
|
||||||
},
|
},
|
||||||
@@ -52,7 +52,7 @@ module.exports = [
|
|||||||
input: './size-v3.js',
|
input: './size-v3.js',
|
||||||
output: {
|
output: {
|
||||||
file: 'dist/v3-size.js',
|
file: 'dist/v3-size.js',
|
||||||
format: 'cjs',
|
format: 'es',
|
||||||
},
|
},
|
||||||
plugins,
|
plugins,
|
||||||
},
|
},
|
||||||
@@ -60,7 +60,7 @@ module.exports = [
|
|||||||
input: './size-v4.js',
|
input: './size-v4.js',
|
||||||
output: {
|
output: {
|
||||||
file: 'dist/v4-size.js',
|
file: 'dist/v4-size.js',
|
||||||
format: 'cjs',
|
format: 'es',
|
||||||
},
|
},
|
||||||
plugins,
|
plugins,
|
||||||
},
|
},
|
||||||
@@ -68,7 +68,7 @@ module.exports = [
|
|||||||
input: './size-v5.js',
|
input: './size-v5.js',
|
||||||
output: {
|
output: {
|
||||||
file: 'dist/v5-size.js',
|
file: 'dist/v5-size.js',
|
||||||
format: 'cjs',
|
format: 'es',
|
||||||
},
|
},
|
||||||
plugins,
|
plugins,
|
||||||
},
|
},
|
||||||
@@ -76,7 +76,7 @@ module.exports = [
|
|||||||
input: './size-v6.js',
|
input: './size-v6.js',
|
||||||
output: {
|
output: {
|
||||||
file: 'dist/v6-size.js',
|
file: 'dist/v6-size.js',
|
||||||
format: 'cjs',
|
format: 'es',
|
||||||
},
|
},
|
||||||
plugins,
|
plugins,
|
||||||
},
|
},
|
||||||
@@ -84,7 +84,7 @@ module.exports = [
|
|||||||
input: './size-v7.js',
|
input: './size-v7.js',
|
||||||
output: {
|
output: {
|
||||||
file: 'dist/v7-size.js',
|
file: 'dist/v7-size.js',
|
||||||
format: 'cjs',
|
format: 'es',
|
||||||
},
|
},
|
||||||
plugins,
|
plugins,
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,9 +0,0 @@
|
|||||||
<!doctype html>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<title>UUID esmodule webpack example</title>
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<script type="text/javascript" src="./dist/allRequire.js"></script>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
@@ -1,96 +0,0 @@
|
|||||||
const uuid = require('uuid');
|
|
||||||
const {
|
|
||||||
NIL: NIL_UUID,
|
|
||||||
MAX: MAX_UUID,
|
|
||||||
parse: uuidParse,
|
|
||||||
stringify: uuidStringify,
|
|
||||||
v1: uuidv1,
|
|
||||||
v1ToV6: uuidv1ToV6,
|
|
||||||
v3: uuidv3,
|
|
||||||
v4: uuidv4,
|
|
||||||
v5: uuidv5,
|
|
||||||
v6: uuidv6,
|
|
||||||
v6ToV1: uuidv6ToV1,
|
|
||||||
v7: uuidv7,
|
|
||||||
validate: uuidValidate,
|
|
||||||
version: uuidVersion,
|
|
||||||
} = uuid;
|
|
||||||
|
|
||||||
const { default: testpage } = require('../utils/testpage');
|
|
||||||
|
|
||||||
testpage(function (addTest, done) {
|
|
||||||
addTest('Named exports');
|
|
||||||
|
|
||||||
addTest('uuidv1()', uuidv1());
|
|
||||||
|
|
||||||
addTest('uuidv4()', uuidv4());
|
|
||||||
|
|
||||||
addTest('uuidv7()', uuidv7());
|
|
||||||
|
|
||||||
// ... 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));
|
|
||||||
|
|
||||||
// v6 <-> v1 conversion
|
|
||||||
const V1_ID = 'f1207660-21d2-11ef-8c4f-419efbd44d48';
|
|
||||||
const V6_ID = '1ef21d2f-1207-6660-8c4f-419efbd44d48';
|
|
||||||
addTest('uuidv1ToV6()', uuidv1ToV6(V1_ID));
|
|
||||||
addTest('uuidv6ToV1()', uuidv6ToV1(V6_ID));
|
|
||||||
|
|
||||||
// ... 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));
|
|
||||||
|
|
||||||
addTest('uuidv6()', uuidv6());
|
|
||||||
|
|
||||||
// Utility functions
|
|
||||||
addTest('NIL_UUID', NIL_UUID);
|
|
||||||
addTest('MAX_UUID', MAX_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.v7()', uuid.v7());
|
|
||||||
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.v6()', uuid.v6());
|
|
||||||
|
|
||||||
addTest('uuid.v1ToV6()', uuid.v1ToV6(V1_ID));
|
|
||||||
addTest('uuid.v6ToV1()', uuid.v6ToV1(V6_ID));
|
|
||||||
|
|
||||||
addTest('uuid.NIL', uuid.NIL);
|
|
||||||
addTest('uuid.MAX', uuid.MAX);
|
|
||||||
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();
|
|
||||||
});
|
|
||||||
@@ -5,7 +5,6 @@ module.exports = {
|
|||||||
},
|
},
|
||||||
entry: {
|
entry: {
|
||||||
all: './example-all.js',
|
all: './example-all.js',
|
||||||
allRequire: './example-all-require.js',
|
|
||||||
v1: './example-v1.js',
|
v1: './example-v1.js',
|
||||||
v4: './example-v4.js',
|
v4: './example-v4.js',
|
||||||
v7: './example-v7.js',
|
v7: './example-v7.js',
|
||||||
|
|||||||
@@ -1,6 +0,0 @@
|
|||||||
# uuid example Node.js CommonJS
|
|
||||||
|
|
||||||
```
|
|
||||||
npm install
|
|
||||||
npm test
|
|
||||||
```
|
|
||||||
@@ -1,92 +0,0 @@
|
|||||||
const {
|
|
||||||
NIL: NIL_UUID,
|
|
||||||
MAX: MAX_UUID,
|
|
||||||
parse: uuidParse,
|
|
||||||
stringify: uuidStringify,
|
|
||||||
v1: uuidv1,
|
|
||||||
v1ToV6: uuidv1ToV6,
|
|
||||||
v3: uuidv3,
|
|
||||||
v4: uuidv4,
|
|
||||||
v5: uuidv5,
|
|
||||||
v6: uuidv6,
|
|
||||||
v6ToV1: uuidv6ToV1,
|
|
||||||
v7: uuidv7,
|
|
||||||
validate: uuidValidate,
|
|
||||||
version: uuidVersion,
|
|
||||||
} = require('uuid');
|
|
||||||
const uuid = require('uuid');
|
|
||||||
const pkg = require('uuid/package.json');
|
|
||||||
|
|
||||||
console.log('uuidv1()', uuidv1());
|
|
||||||
|
|
||||||
console.log('uuidv4()', uuidv4());
|
|
||||||
|
|
||||||
console.log('uuidv7()', uuidv7());
|
|
||||||
|
|
||||||
// ... 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('uuidv6()', uuidv6());
|
|
||||||
|
|
||||||
// v6 <-> v1 conversion
|
|
||||||
const V1_ID = 'f1207660-21d2-11ef-8c4f-419efbd44d48';
|
|
||||||
const V6_ID = '1ef21d2f-1207-6660-8c4f-419efbd44d48';
|
|
||||||
console.log('uuidv1ToV6()', uuidv1ToV6(V1_ID));
|
|
||||||
console.log('uuidv6ToV1()', uuidv6ToV1(V6_ID));
|
|
||||||
|
|
||||||
// Utility functions
|
|
||||||
console.log('NIL_UUID', NIL_UUID);
|
|
||||||
console.log('MAX_UUID', MAX_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.v7()', uuid.v7());
|
|
||||||
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.v6()', uuid.v6());
|
|
||||||
|
|
||||||
console.log('uuid.v1ToV6()', uuid.v1ToV6(V1_ID));
|
|
||||||
console.log('uuid.v6ToV1()', uuid.v6ToV1(V6_ID));
|
|
||||||
|
|
||||||
console.log('uuid.NIL', uuid.NIL);
|
|
||||||
console.log('uuid.MAX', uuid.MAX);
|
|
||||||
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);
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
{
|
|
||||||
"name": "uuid-example-node-commonjs",
|
|
||||||
"version": "0.0.0",
|
|
||||||
"private": true,
|
|
||||||
"scripts": {
|
|
||||||
"pretest": "rm -fr node_modules && npm install --no-package-lock",
|
|
||||||
"test": "node example.js"
|
|
||||||
},
|
|
||||||
"dependencies": {
|
|
||||||
"uuid": "file:../../.build/uuid.tgz"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -3,7 +3,7 @@
|
|||||||
"version": "0.0.0",
|
"version": "0.0.0",
|
||||||
"private": true,
|
"private": true,
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test:package": "( node --version | grep -vq 'v16' ) || ( node --experimental-json-modules package.mjs )",
|
"test:package": "( node --version | grep -vq 'v18' ) || ( node package.mjs )",
|
||||||
"test:example": "node example.mjs",
|
"test:example": "node example.mjs",
|
||||||
"pretest": "rm -fr node_modules && npm install --no-package-lock",
|
"pretest": "rm -fr node_modules && npm install --no-package-lock",
|
||||||
"test": "npm-run-all test:*"
|
"test": "npm-run-all test:*"
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
/** @jest-environment jsdom */
|
/** @jest-environment jsdom */
|
||||||
|
import * as uuid from 'uuid';
|
||||||
const uuid = require('uuid');
|
|
||||||
|
|
||||||
test('uuidv4()', () => {
|
test('uuidv4()', () => {
|
||||||
const val = uuid.v4();
|
const val = uuid.v4();
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
const uuid = require('uuid');
|
import * as uuid from 'uuid';
|
||||||
|
|
||||||
test('uuidv4()', () => {
|
test('uuidv4()', () => {
|
||||||
const val = uuid.v4();
|
const val = uuid.v4();
|
||||||
|
|||||||
@@ -2,15 +2,16 @@
|
|||||||
"name": "uuid-example-node-jest",
|
"name": "uuid-example-node-jest",
|
||||||
"version": "0.0.0",
|
"version": "0.0.0",
|
||||||
"private": true,
|
"private": true,
|
||||||
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"pretest": "rm -fr node_modules && npm install --no-package-lock",
|
"pretest": "rm -fr node_modules && npm install --no-package-lock",
|
||||||
"test": "jest"
|
"test": "NODE_OPTIONS=\"--experimental-vm-modules\" jest"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"uuid": "file:../../.build/uuid.tgz"
|
"uuid": "file:../../.build/uuid.tgz"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"jest": "^29.7.0",
|
"jest": "30.0.2",
|
||||||
"jest-environment-jsdom": "^29.7.0"
|
"jest-environment-jsdom": "30.0.2"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+9
-21
@@ -20,32 +20,21 @@
|
|||||||
],
|
],
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"bin": {
|
"bin": {
|
||||||
"uuid": "./dist/esm/bin/uuid"
|
"uuid": "./dist/bin/uuid"
|
||||||
},
|
},
|
||||||
"sideEffects": false,
|
"sideEffects": false,
|
||||||
"main": "./dist/cjs/index.js",
|
"types": "./dist/index.d.ts",
|
||||||
"exports": {
|
"exports": {
|
||||||
".": {
|
".": {
|
||||||
"node": {
|
"browser": "./dist-browser/index.js",
|
||||||
"import": "./dist/esm/index.js",
|
"default": "./dist/index.js"
|
||||||
"require": "./dist/cjs/index.js"
|
|
||||||
},
|
|
||||||
"browser": {
|
|
||||||
"import": "./dist/esm-browser/index.js",
|
|
||||||
"require": "./dist/cjs-browser/index.js"
|
|
||||||
},
|
|
||||||
"default": "./dist/esm-browser/index.js"
|
|
||||||
},
|
},
|
||||||
"./package.json": "./package.json"
|
"./package.json": "./package.json"
|
||||||
},
|
},
|
||||||
"module": "./dist/esm/index.js",
|
|
||||||
"browser": {
|
|
||||||
"./dist/esm/index.js": "./dist/esm-browser/index.js",
|
|
||||||
"./dist/cjs/index.js": "./dist/cjs-browser/index.js"
|
|
||||||
},
|
|
||||||
"files": [
|
"files": [
|
||||||
"dist",
|
"dist",
|
||||||
"!dist/**/test"
|
"dist-browser",
|
||||||
|
"!**/test"
|
||||||
],
|
],
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@babel/eslint-parser": "7.27.1",
|
"@babel/eslint-parser": "7.27.1",
|
||||||
@@ -80,7 +69,7 @@
|
|||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "./scripts/build.sh",
|
"build": "./scripts/build.sh",
|
||||||
"build:watch": "tsc --watch -p tsconfig.esm.json",
|
"build:watch": "tsc --watch -p tsconfig.json",
|
||||||
"bundlewatch": "npm run pretest:browser && bundlewatch --config bundlewatch.config.json",
|
"bundlewatch": "npm run pretest:browser && bundlewatch --config bundlewatch.config.json",
|
||||||
"docs:diff": "npm run docs && git diff --quiet README.md",
|
"docs:diff": "npm run docs && git diff --quiet README.md",
|
||||||
"docs": "npm run build && npx runmd --output=README.md README_js.md",
|
"docs": "npm run build && npx runmd --output=README.md README_js.md",
|
||||||
@@ -88,7 +77,6 @@
|
|||||||
"eslint:fix": "eslint --fix src/ test/ examples/ *.[jt]s",
|
"eslint:fix": "eslint --fix src/ test/ examples/ *.[jt]s",
|
||||||
"examples:browser:rollup:build": "cd examples/browser-rollup && npm run build",
|
"examples:browser:rollup:build": "cd examples/browser-rollup && npm run build",
|
||||||
"examples:browser:webpack:build": "cd examples/browser-webpack && npm run build",
|
"examples:browser:webpack:build": "cd examples/browser-webpack && npm run build",
|
||||||
"examples:node:commonjs:test": "cd examples/node-commonjs && npm test",
|
|
||||||
"examples:node:esmodules:test": "cd examples/node-esmodules && npm test",
|
"examples:node:esmodules:test": "cd examples/node-esmodules && npm test",
|
||||||
"examples:node:jest:test": "cd examples/node-jest && npm test",
|
"examples:node:jest:test": "cd examples/node-jest && npm test",
|
||||||
"examples:node:typescript:test": "cd examples/typescript && npm test",
|
"examples:node:typescript:test": "cd examples/typescript && npm test",
|
||||||
@@ -107,8 +95,8 @@
|
|||||||
"test:benchmark": "cd examples/benchmark && npm test",
|
"test:benchmark": "cd examples/benchmark && npm test",
|
||||||
"test:browser": "wdio run ./wdio.conf.js",
|
"test:browser": "wdio run ./wdio.conf.js",
|
||||||
"test:node": "npm-run-all --parallel examples:node:**",
|
"test:node": "npm-run-all --parallel examples:node:**",
|
||||||
"test:watch": "node --test --enable-source-maps --watch dist/esm/test/*.js",
|
"test:watch": "node --test --enable-source-maps --watch dist/test/*.js",
|
||||||
"test": "node --test --enable-source-maps dist/esm/test/*.js"
|
"test": "node --test --enable-source-maps dist/test/*.js"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
|
|||||||
+21
-28
@@ -1,10 +1,8 @@
|
|||||||
#!/bin/bash -eu
|
#!/bin/bash -eu
|
||||||
|
|
||||||
# This script generates 4 builds, as follows:
|
# This script generates 4 builds, as follows:
|
||||||
# - dist/esm: ESM build for Node.js
|
# - dist: ESM build for Node.js
|
||||||
# - dist/esm-browser: ESM build for the Browser
|
# - dist-browser: ESM build for the Browser
|
||||||
# - dist/cjs: CommonJS build for Node.js
|
|
||||||
# - dist/cjs-browser: CommonJS build for the Browser
|
|
||||||
#
|
#
|
||||||
# Note: that the "preferred" build for testing (local and CI) is the ESM build,
|
# Note: that the "preferred" build for testing (local and CI) is the ESM build,
|
||||||
# except where we specifically test the other builds
|
# except where we specifically test the other builds
|
||||||
@@ -12,25 +10,25 @@
|
|||||||
set -e # exit on error
|
set -e # exit on error
|
||||||
|
|
||||||
# Change to project root
|
# Change to project root
|
||||||
ROOT="$(pwd)/$(dirname "$0")/.."
|
ROOT=$(builtin cd $(pwd)/$(dirname "$0")/..; pwd)
|
||||||
cd "$ROOT" || exit 1
|
|
||||||
|
|
||||||
# Prep TS output dir
|
# Prep TS output dir
|
||||||
DIST_DIR="$ROOT/dist"
|
NODE_DIST_DIR="$ROOT/dist"
|
||||||
rm -rf "$DIST_DIR"
|
BROWSER_DIST_DIR="$ROOT/dist-browser"
|
||||||
mkdir -p "$DIST_DIR"
|
echo "Building in $NODE_DIST_DIR and $BROWSER_DIST_DIR"
|
||||||
|
|
||||||
|
cd "$ROOT" || exit 1
|
||||||
|
|
||||||
|
rm -rf "$NODE_DIST_DIR" "$BROWSER_DIST_DIR"
|
||||||
|
mkdir -p "$NODE_DIST_DIR"
|
||||||
|
|
||||||
# Build each module type
|
# Build each module type
|
||||||
for MODULE_TYPE in esm cjs; do
|
echo "Compiling TypeScript files to $NODE_DIST_DIR"
|
||||||
echo "Building ${MODULE_TYPE}"
|
|
||||||
|
|
||||||
NODE_DIST_DIR="$DIST_DIR/${MODULE_TYPE}"
|
tsc -p tsconfig.json
|
||||||
BROWSER_DIST_DIR="$DIST_DIR/${MODULE_TYPE}-browser"
|
|
||||||
|
|
||||||
tsc -p tsconfig.${MODULE_TYPE}.json
|
|
||||||
|
|
||||||
# Clone files for browser builds
|
# Clone files for browser builds
|
||||||
cp -pr ${NODE_DIST_DIR} ${BROWSER_DIST_DIR}
|
cp -pr "$NODE_DIST_DIR" "$BROWSER_DIST_DIR"
|
||||||
|
|
||||||
# Remove browser files from non-browser builds
|
# Remove browser files from non-browser builds
|
||||||
for FILE in ${NODE_DIST_DIR}/*-browser*; do
|
for FILE in ${NODE_DIST_DIR}/*-browser*; do
|
||||||
@@ -42,23 +40,18 @@ for MODULE_TYPE in esm cjs; do
|
|||||||
# Temporarily cd into BROWSER_DIST_DIR to avoid having to deal with
|
# Temporarily cd into BROWSER_DIST_DIR to avoid having to deal with
|
||||||
# "-browser" appearing in both the dir name and file name of FILE's full
|
# "-browser" appearing in both the dir name and file name of FILE's full
|
||||||
# path
|
# path
|
||||||
cd ${BROWSER_DIST_DIR}
|
cd "$BROWSER_DIST_DIR"
|
||||||
|
|
||||||
for FILE in *-browser*;do
|
for FILE in *-browser*;do
|
||||||
mv $FILE ${FILE/-browser/}
|
mv "$FILE" "${FILE/-browser/}"
|
||||||
done
|
done
|
||||||
|
|
||||||
|
# Remove type definitions
|
||||||
|
find . -name '*.d.ts' -exec rm -f {} \;
|
||||||
)
|
)
|
||||||
|
|
||||||
# esm/cjs-specific logic
|
# Copy bin files to dist
|
||||||
if [ "$MODULE_TYPE" = "esm" ]; then
|
cp -pr "$NODE_DIST_DIR/../src/bin" "$NODE_DIST_DIR"
|
||||||
# ESM: copy bin files to dist
|
|
||||||
cp -pr "$DIST_DIR/../src/bin" "$NODE_DIST_DIR"
|
|
||||||
else
|
|
||||||
# CJS: Add package.json that specifies type: commonjs
|
|
||||||
echo "{\"type\":\"commonjs\"}" > "$NODE_DIST_DIR/package.json"
|
|
||||||
echo "{\"type\":\"commonjs\"}" > "$BROWSER_DIST_DIR/package.json"
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
|
|
||||||
if [ "${1-}" != "--no-pack" ]; then
|
if [ "${1-}" != "--no-pack" ]; then
|
||||||
# Prep tarball dir
|
# Prep tarball dir
|
||||||
|
|||||||
@@ -1,10 +0,0 @@
|
|||||||
{
|
|
||||||
"compilerOptions": {
|
|
||||||
"declaration": true,
|
|
||||||
"removeComments": true,
|
|
||||||
"skipLibCheck": true,
|
|
||||||
"strict": true,
|
|
||||||
"target": "ES2022"
|
|
||||||
},
|
|
||||||
"exclude": ["dist", "examples"]
|
|
||||||
}
|
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
{
|
|
||||||
"extends": "./tsconfig.base.json",
|
|
||||||
"compilerOptions": {
|
|
||||||
"module": "CommonJS",
|
|
||||||
"moduleResolution": "Node",
|
|
||||||
"outDir": "./dist/cjs"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
{
|
|
||||||
"extends": "./tsconfig.base.json",
|
|
||||||
"compilerOptions": {
|
|
||||||
"module": "NodeNext",
|
|
||||||
"moduleResolution": "NodeNext",
|
|
||||||
"outDir": "./dist/esm"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+13
-4
@@ -1,4 +1,13 @@
|
|||||||
// NOTE: Do not extend or alter this file. This file is only here to point
|
{
|
||||||
// VSCode to the correct config file. (There's no way of configuring the path
|
"compilerOptions": {
|
||||||
// VSCode uses for the tsconfig.json file)
|
"declaration": true,
|
||||||
{ "extends": "./tsconfig.esm.json" }
|
"module": "NodeNext",
|
||||||
|
"moduleResolution": "NodeNext",
|
||||||
|
"outDir": "./dist",
|
||||||
|
"removeComments": true,
|
||||||
|
"skipLibCheck": true,
|
||||||
|
"strict": true,
|
||||||
|
"target": "ES2022"
|
||||||
|
},
|
||||||
|
"exclude": ["dist", "examples"]
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user