|
| 1 | +import {v1 as uuidv1, v4 as uuidv4, v3 as uuidv3, v5 as uuidv5} from './node_modules/uuid/esm-browser/index.js'; |
| 2 | +import * as uuid from './node_modules/uuid/esm-browser/index.js'; |
| 3 | + |
| 4 | +console.log('uuidv1()', uuidv1()); |
| 5 | + |
| 6 | +console.log('uuidv4()', uuidv4()); |
| 7 | + |
| 8 | +// ... using predefined DNS namespace (for domain names) |
| 9 | +console.log('uuidv3() DNS', uuidv3('hello.example.com', uuidv3.DNS)); |
| 10 | + |
| 11 | +// ... using predefined URL namespace (for, well, URLs) |
| 12 | +console.log('uuidv3() URL', uuidv3('http://example.com/hello', uuidv3.URL)); |
| 13 | + |
| 14 | +// ... using a custom namespace |
| 15 | +// |
| 16 | +// Note: Custom namespaces should be a UUID string specific to your application! |
| 17 | +// E.g. the one here was generated using this modules `uuid` CLI. |
| 18 | +const MY_NAMESPACE = '55238d15-c926-4598-b49d-cf4e913ba13c'; |
| 19 | +console.log('uuidv3() MY_NAMESPACE', uuidv3('Hello, World!', MY_NAMESPACE)); |
| 20 | + |
| 21 | +// ... using predefined DNS namespace (for domain names) |
| 22 | +console.log('uuidv5() DNS', uuidv5('hello.example.com', uuidv5.DNS)); |
| 23 | + |
| 24 | +// ... using predefined URL namespace (for, well, URLs) |
| 25 | +console.log('uuidv5() URL', uuidv5('http://example.com/hello', uuidv5.URL)); |
| 26 | + |
| 27 | +// ... using a custom namespace |
| 28 | +// |
| 29 | +// Note: Custom namespaces should be a UUID string specific to your application! |
| 30 | +// E.g. the one here was generated using this modules `uuid` CLI. |
| 31 | +// const MY_NAMESPACE = '1b671a64-40d5-491e-99b0-da01ff1f3341'; |
| 32 | +console.log('uuidv5() MY_NAMESPACE', uuidv5('Hello, World!', MY_NAMESPACE)); |
| 33 | + |
| 34 | +console.log('Same with default export'); |
| 35 | + |
| 36 | +console.log('uuid.v1()', uuid.v1()); |
| 37 | +console.log('uuid.v4()', uuid.v4()); |
| 38 | +console.log('uuid.v3() DNS', uuid.v3('hello.example.com', uuid.v3.DNS)); |
| 39 | +console.log('uuid.v3() URL', uuid.v3('http://example.com/hello', uuid.v3.URL)); |
| 40 | +console.log('uuid.v3() MY_NAMESPACE', uuid.v3('Hello, World!', MY_NAMESPACE)); |
| 41 | +console.log('uuid.v5() DNS', uuid.v5('hello.example.com', uuid.v5.DNS)); |
| 42 | +console.log('uuid.v5() URL', uuid.v5('http://example.com/hello', uuid.v5.URL)); |
| 43 | +console.log('uuid.v5() MY_NAMESPACE', uuid.v5('Hello, World!', MY_NAMESPACE)); |
0 commit comments