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