### Theme Setting Example
Source: https://github.com/simplyhexagonal/short-unique-id/blob/main/docs/variables/DEFAULT_OPTIONS.html
This JavaScript snippet demonstrates how to set the theme for the document based on local storage, with a fallback to 'os'. It also includes a timeout to show the application page after a short delay.
```javascript
document.documentElement.dataset.theme = localStorage.getItem("tsd-theme") || "os";
document.body.style.display="none";
setTimeout(() => app?.showPage() ?? document.body.style.removeProperty("display"), 500);
```
--------------------------------
### CLI Usage
Source: https://github.com/simplyhexagonal/short-unique-id/blob/main/README.md
Provides instructions for installing and using the short-unique-id package globally via npm, along with a help command to display available options.
```sh
$ npm install --global short-unique-id
$ suid -h
# Usage:
# node short-unique-id [OPTION]
#
# Options:
# -l, --length=ARG character length of the uid to generate.
# -s, --stamp include timestamp in uid (must be used with --length (-l) of 10 or more).
# -t, --timestamp=ARG custom timestamp to parse (must be used along with -s, --stamp, -f, or --format).
# -f, --format=ARG string representing custom format to generate id with.
# -p, --parse=ARG extract timestamp from stamped uid (ARG).
# -d, --dictionaryJson=ARG json file with dictionary array.
# -h, --help display this help
```
--------------------------------
### CLI Usage
Source: https://github.com/simplyhexagonal/short-unique-id/blob/main/docs/index.html
Provides examples of how to use the short-unique-id library from the command line interface (CLI) for quick ID generation.
```bash
# Generate a default UUID
short-unique-id
# Generate a UUID with a specific alphabet and length
short-unique-id --alphabet "base58" --length 12
# Generate a UUID with a timestamp
short-unique-id --with-timestamp
```
--------------------------------
### ShortUniqueIdOptions Example Usage
Source: https://github.com/simplyhexagonal/short-unique-id/blob/main/docs/interfaces/ShortUniqueIdOptions.html
An example of how to define ShortUniqueIdOptions with a custom dictionary, shuffle enabled, debug mode on, and a specific length.
```javascript
const options = {
dictionary: ['a', 'b', 'c', 'd', 'e', 'f'],
shuffle: true,
debug: true,
length: 8
};
```
--------------------------------
### ShortUniqueId Module Usage (Node.js/Deno)
Source: https://github.com/simplyhexagonal/short-unique-id/blob/main/docs/index.html
Provides examples of how to import and use the ShortUniqueId library as a module in Node.js and Deno environments. It covers instantiation and generating random or sequential UUIDs.
```javascript
// ES6 / TypeScript Import
import ShortUniqueId from 'short-unique-id';
// Node.js require
// const ShortUniqueId = require('short-unique-id');
// Deno (web module) Import
// import ShortUniqueId from 'https://esm.sh/short-unique-id';
// Instantiate
const uid = new ShortUniqueId();
// Random UUID
console.log(uid.rnd());
// Sequential UUID
console.log(uid.seq());
// Instantiate and destructure (long method name recommended for code readability)
const { randomUUID, sequentialUUID } = new ShortUniqueId();
// Random UUID
console.log(randomUUID());
// Sequential UUID
console.log(sequentialUUID());
// NOTE: we made sure to use `bind()` on all ShortUniqueId methods to ensure that any options passed when creating the instance will be respected by the destructured methods.
```
--------------------------------
### Usage Examples for short-unique-id
Source: https://github.com/simplyhexagonal/short-unique-id/blob/main/docs/classes/shortUniqueIdV532.html
Demonstrates how to import and use the ShortUniqueId class in various JavaScript environments including Deno, ES6/TypeScript, Node.js, and in the browser. It shows instantiation and basic usage for generating random and sequential UUIDs.
```typescript
import ShortUniqueId from 'short-unique-id';
// Instantiate
const uid = new ShortUniqueId();
// Random UUID
console.log(uid.rnd());
// Sequential UUID
console.log(uid.seq());
```
```javascript
const ShortUniqueId = require('short-unique-id');
// Instantiate
var uid = new ShortUniqueId();
// Random UUID
document.write(uid.rnd());
// Sequential UUID
document.write(uid.seq());
```
```typescript
import ShortUniqueId from 'https://cdn.jsdelivr.net/npm/short-unique-id@latest/src/index.ts';
```
```html
```
--------------------------------
### ShortUniqueId CLI Usage
Source: https://github.com/simplyhexagonal/short-unique-id/blob/main/docs/index.html
Shows how to install and use the ShortUniqueId library from the command line interface. It outlines various options for generating unique IDs with custom lengths, timestamps, and formats.
```bash
$ npm install --global short-unique-id
$ suid -h
# Usage:
# node short-unique-id [OPTION]
#
# Options:
# -l, --length=ARG character length of the uid to generate.
# -s, --stamp include timestamp in uid (must be used with --length (-l) of 10 or more).
# -t, --timestamp=ARG custom timestamp to parse (must be used along with -s, --stamp, -f, or --format).
# -f, --format=ARG string representing custom format to generate id with.
# -p, --parse=ARG extract timestamp from stamped uid (ARG).
# -d, --dictionaryJson=ARG json file with dictionary array.
# -h, --help display this help
```
--------------------------------
### Random Color Generator Example
Source: https://github.com/simplyhexagonal/short-unique-id/blob/main/docs/index.html
Demonstrates how to use ShortUniqueId to generate random hexadecimal color codes. It shows instantiation with a custom dictionary and generating IDs of a specific length.
```javascript
var uid = new ShortUniqueId({
dictionary: [
'0', '1', '2', '3',
'4', '5', '6', '7',
'8', '9', 'A', 'B',
'C', 'D', 'E', 'F',
],
});
// or using default dictionaries available since v4.3+
var uid = new ShortUniqueId({ dictionary: 'hex' });
// then taste the rainbow 🌈
var color = '#' + uid.randomUUID(6) + ';'
```
--------------------------------
### Random Color Generator Example
Source: https://github.com/simplyhexagonal/short-unique-id/blob/main/docs/assets/generator.html
Demonstrates how to use the ShortUniqueId library to generate random hexadecimal color codes. It shows instantiation with a custom hex dictionary and generating a 6-character hex string.
```javascript
var uid = new ShortUniqueId({
dictionary: [
'0', '1', '2', '3',
'4', '5', '6', '7',
'8', '9', 'A', 'B',
'C', 'D', 'E', 'F',
],
});
var uid = new ShortUniqueId({ dictionary: 'hex' });
var color = '#' + uid.randomUUID(6) + ';'
```
--------------------------------
### Random Color Generator Example
Source: https://github.com/simplyhexagonal/short-unique-id/blob/main/assets/generator.html
Demonstrates how to use the ShortUniqueId library to generate random hexadecimal color codes. It shows instantiation with a custom hex dictionary and generating a 6-character hex string.
```javascript
var uid = new ShortUniqueId({
dictionary: [
'0', '1', '2', '3',
'4', '5', '6', '7',
'8', '9', 'A', 'B',
'C', 'D', 'E', 'F',
],
});
var uid = new ShortUniqueId({ dictionary: 'hex' });
var color = '#' + uid.randomUUID(6) + ';'
```
--------------------------------
### Event Listener for UUID Generation
Source: https://github.com/simplyhexagonal/short-unique-id/blob/main/docs/index.html
Provides an example of integrating ShortUniqueId with DOM event listeners to generate random UUIDs, sequential UUIDs, and random colors upon button clicks. It also includes setting the color of the generated color code.
```javascript
window.onload = function() {
var uid = new ShortUniqueId({ debug: true });
var colorUid = new ShortUniqueId({ dictionary: 'hex' });
$('#genRandom').click(function(e){
e.preventDefault();
$('#randomResult').html(uid.randomUUID(parseInt($('#uuidLen')[0].value)));
});
$('#genSequential').click(function(e){
e.preventDefault();
$('#sequentialResult').html(uid.sequentialUUID());
});
$('#genColor').click(function(e){
e.preventDefault();
var color = colorUid.randomUUID(6);
$('#colorResult').html('#' + color);
$('#colorResult').attr('style', 'color: #' + color + ';');
});
};
```
--------------------------------
### Theme Initialization Script
Source: https://github.com/simplyhexagonal/short-unique-id/blob/main/docs/types/ShortUniqueIdDefaultDictionaries.html
This JavaScript snippet initializes the theme for the documentation page by reading from local storage and applying it to the document element. It also includes a timeout to ensure the application is ready before displaying the body.
```javascript
document.documentElement.dataset.theme = localStorage.getItem("tsd-theme") || "os";
document.body.style.display="none";
setTimeout(() => app?app.showPage():document.body.style.removeProperty("display"),500)
```
--------------------------------
### Theme Initialization
Source: https://github.com/simplyhexagonal/short-unique-id/blob/main/docs/interfaces/ShortUniqueIdRanges.html
Initializes the theme based on local storage or OS preference and handles the initial display of the application.
```JavaScript
document.documentElement.dataset.theme = localStorage.getItem("tsd-theme") || "os";
document.body.style.display="none";
setTimeout(() => app?app.showPage():document.body.style.removeProperty("display"),500)
```
--------------------------------
### Instantiation with Options
Source: https://github.com/simplyhexagonal/short-unique-id/blob/main/README.md
Explains how to pass configuration options during the instantiation of the ShortUniqueId class to customize its behavior, such as dictionary or length.
```js
const options = { ... };
const uid = new ShortUniqueId(options);
```
--------------------------------
### Run Tests
Source: https://github.com/simplyhexagonal/short-unique-id/blob/main/README.md
Command to execute the project's tests.
```sh
pnpm test
```
--------------------------------
### Instantiating ShortUniqueId with Options
Source: https://github.com/simplyhexagonal/short-unique-id/blob/main/docs/index.html
Demonstrates how to create an instance of the ShortUniqueId class with custom options. This is useful for configuring the ID generation process, such as specifying the dictionary or length.
```javascript
const options = { ... };
const uid = new ShortUniqueId(options);
```
--------------------------------
### Build Distribution Files
Source: https://github.com/simplyhexagonal/short-unique-id/blob/main/README.md
Command to build the distribution files required for publishing.
```sh
pnpm build
```
--------------------------------
### Instantiate and Use (Module)
Source: https://github.com/simplyhexagonal/short-unique-id/blob/main/README.md
Shows basic instantiation of ShortUniqueId and generating random or sequential UUIDs. It also covers using destructuring assignment for direct access to methods like randomUUID and sequentialUUID.
```js
//Instantiate
const uid = new ShortUniqueId();
// Random UUID
console.log(uid.rnd());
// Sequential UUID
console.log(uid.seq());
// Instantiate and destructure (long method name recommended for code readability)
const { randomUUID, sequentialUUID } = new ShortUniqueId();
// Random UUID
console.log(randomUUID());
// Sequential UUID
console.log(sequentialUUID());
// NOTE: we made sure to use bind() on all ShortUniqueId methods to ensure that any options
// passed when creating the instance will be respected by the destructured methods.
```
--------------------------------
### Theme and Display Initialization
Source: https://github.com/simplyhexagonal/short-unique-id/blob/main/docs/modules.html
Sets the theme based on local storage and controls the initial display of the body element, deferring the app's visibility.
```javascript
document.documentElement.dataset.theme = localStorage.getItem("tsd-theme") || "os";
document.body.style.display="none";
setTimeout(() => app?app.showPage():document.body.style.removeProperty("display"),500)
```
--------------------------------
### Clone Repository
Source: https://github.com/simplyhexagonal/short-unique-id/blob/main/README.md
Instructions for cloning the project repository using SSH or HTTPS.
```sh
# SSH
git clone git@github.com:jeanlescure/short-unique-id.git
# HTTPS
git clone https://github.com/jeanlescure/short-unique-id.git
```
--------------------------------
### Cloning the Repository
Source: https://github.com/simplyhexagonal/short-unique-id/blob/main/docs/index.html
Instructions for cloning the project repository using both SSH and HTTPS protocols. This is the first step for anyone wanting to contribute or work with the project's source code.
```bash
# SSH
git clone git@github.com:jeanlescure/short-unique-id.git
# HTTPS
git clone https://github.com/jeanlescure/short-unique-id.git
```
--------------------------------
### Building Distribution Files
Source: https://github.com/simplyhexagonal/short-unique-id/blob/main/docs/index.html
Command to build the necessary distribution files for the project. This step is required before publishing new changes or creating a release.
```bash
pnpm build
```
--------------------------------
### ShortUniqueId API - Instantiation and Methods
Source: https://github.com/simplyhexagonal/short-unique-id/blob/main/docs/index.html
Details the constructor for ShortUniqueId and its primary methods for generating unique identifiers. Covers instantiation with options and the core `rnd()` and `seq()` methods, as well as `stamp()` and `validate()`.
```APIDOC
ShortUniqueId:
__constructor(options?: object)
options:
dictionary (string | string[]): The dictionary to use for generating IDs. Can be a predefined string ('hex', 'numeric', 'alphanum', 'alphabet') or a custom array of characters.
shuffle (boolean): Whether to shuffle the dictionary before use. Defaults to false.
debug (boolean): Enable debug logging. Defaults to false.
rnd(): string
Generates a random UUID using the configured dictionary and options.
Returns: A randomly generated UUID string.
seq(): string
Generates a sequential UUID. The sequence is managed internally by the instance.
Returns: A sequentially generated UUID string.
stamp(length: number, timestamp?: number | string): string
Generates a UUID that includes a timestamp. The length parameter determines the total length of the UUID, with the timestamp occupying the first part.
Parameters:
length (number): The total desired length of the UUID.
timestamp (number | string, optional): A custom timestamp to encode. If not provided, the current timestamp is used.
Returns: A UUID string with an embedded timestamp.
validate(uuid: string, dictionary?: string | string[]): boolean
Validates a given UUID against the instance's dictionary or a provided custom dictionary.
Parameters:
uuid (string): The UUID string to validate.
dictionary (string | string[], optional): A custom dictionary to validate against. If not provided, the instance's dictionary is used.
Returns: true if the UUID is valid, false otherwise.
```
--------------------------------
### Running Tests
Source: https://github.com/simplyhexagonal/short-unique-id/blob/main/docs/index.html
Command to execute the project's test suite. This is essential for verifying the integrity of the code and ensuring that changes do not introduce regressions.
```bash
pnpm test
```
--------------------------------
### Theme Management and Page Display
Source: https://github.com/simplyhexagonal/short-unique-id/blob/main/docs/interfaces/ShortUniqueIdRangesMap.html
This snippet demonstrates how to manage the UI theme based on local storage settings and control the initial display of the page content. It sets the theme and then shows the page after a short delay.
```javascript
document.documentElement.dataset.theme = localStorage.getItem("tsd-theme") || "os";
document.body.style.display="none";
setTimeout(() => app?app.showPage():document.body.style.removeProperty("display"),500)
```
--------------------------------
### Release Script
Source: https://github.com/simplyhexagonal/short-unique-id/blob/main/README.md
Command to run the release script after committing changes.
```sh
pnpm release
```
--------------------------------
### shortUniqueIdV532 Class API Documentation
Source: https://github.com/simplyhexagonal/short-unique-id/blob/main/docs/classes/shortUniqueIdV532.html
API documentation for the shortUniqueIdV532 class, detailing its constructors, properties, and methods for generating and managing unique identifiers. Includes information on options, dictionary manipulation, and UUID generation logic.
```APIDOC
Class shortUniqueIdV532
=======================
Generate random or sequential UUID of any length.
Constructors
------------
### constructor
* new shortUniqueIdV532(argOptions?: Partial): shortUniqueIdV532
* Parameters:
* argOptions: Partial = {}
* Returns: shortUniqueIdV532
* Defined in index.ts:619
Properties
----------
### counter
counter: number
* Defined in index.ts:137
### debug
debug: boolean
* Defined in index.ts:138
### dict
dict: string[]
* Defined in index.ts:139
### dictIndex
dictIndex: number = 0
* Defined in index.ts:141
### dictLength
dictLength: number = 0
* Defined in index.ts:145
### dictRange
dictRange: number[] = []
* Defined in index.ts:142
### uuidLength
uuidLength: number
* Defined in index.ts:146
### version
version: string
* Defined in index.ts:147
### lowerBound
lowerBound: number
* Defined in index.ts:143
### upperBound
upperBound: number
* Defined in index.ts:144
Methods
-------
### rnd
rnd(): string
* Generates a random UUID.
* Defined in index.ts:778
### seq
seq(): string
* Generates a sequential UUID.
* Defined in index.ts:791
### getVersion
getVersion(): string
* Returns the current version of the library.
* Defined in index.ts:700
### setCounter
setCounter(counter: number): void
* Sets the internal counter for sequential UUID generation.
* Parameters:
* counter: The new counter value.
* Defined in index.ts:713
### setDictionary
setDictionary(dict: string[], dictRange?: number[]): void
* Sets a custom dictionary and optionally a range for UUID generation.
* Parameters:
* dict: An array of characters to use in the UUID.
* dictRange: An optional array specifying the start and end index for the dictionary.
* Defined in index.ts:727
### fmt
fmt(uuid: string): string
* Formats a UUID string according to predefined patterns.
* Parameters:
* uuid: The UUID string to format.
* Returns: The formatted UUID string.
* Defined in index.ts:740
### formattedUUID
formattedUUID(uuid: string): string
* Formats a UUID string with hyphens.
* Parameters:
* uuid: The UUID string to format.
* Returns: The hyphenated UUID string.
* Defined in index.ts:753
### randomUUID
randomUUID(): string
* Alias for `rnd()`.
* Defined in index.ts:765
### sequentialUUID
sequentialUUID(): string
* Alias for `seq()`.
* Defined in index.ts:771
### approxMaxBeforeCollision
approxMaxBeforeCollision(): number
* Calculates the approximate maximum number of UUIDs that can be generated before a collision is likely.
* Returns: The approximate maximum number of UUIDs.
* Defined in index.ts:804
### availableUUIDs
availableUUIDs(): number
* Calculates the total number of unique UUIDs that can be generated with the current configuration.
* Returns: The total number of available UUIDs.
* Defined in index.ts:817
### collisionProbability
collisionProbability(n: number): number
* Calculates the probability of a collision after generating `n` UUIDs.
* Parameters:
* n: The number of UUIDs generated.
* Returns: The collision probability (a value between 0 and 1).
* Defined in index.ts:831
### parseStamp
parseStamp(uuid: string): number
* Parses a UUID and extracts the timestamp component.
* Parameters:
* uuid: The UUID string to parse.
* Returns: The extracted timestamp as a number.
* Defined in index.ts:844
### stamp
stamp(uuid: string): string
* Extracts the timestamp component from a UUID and returns it as a string.
* Parameters:
* uuid: The UUID string to process.
* Returns: The timestamp string.
* Defined in index.ts:857
### uniqueness
uniqueness(uuid: string): number
* Calculates the uniqueness score of a given UUID based on its characters.
* Parameters:
* uuid: The UUID string.
* Returns: The uniqueness score.
* Defined in index.ts:870
### validate
validate(uuid: string): boolean
* Validates if a given string is a valid UUID generated by this library.
* Parameters:
* uuid: The UUID string to validate.
* Returns: True if the UUID is valid, false otherwise.
* Defined in index.ts:883
```
--------------------------------
### Module Usage (Node.js/Deno/TypeScript)
Source: https://github.com/simplyhexagonal/short-unique-id/blob/main/README.md
Demonstrates how to import and use the ShortUniqueId library in modern JavaScript environments like Node.js, Deno, and TypeScript using ES6 imports or Node.js require.
```js
// ES6 / TypeScript Import
import ShortUniqueId from 'short-unique-id';
// Node.js require
const ShortUniqueId = require('short-unique-id');
// Deno (web module) Import
import ShortUniqueId from 'https://esm.sh/short-unique-id';
```
--------------------------------
### ShortUniqueId API
Source: https://github.com/simplyhexagonal/short-unique-id/blob/main/docs/classes/shortUniqueIdV532.html
API documentation for the ShortUniqueId class, covering its constructor, methods for ID generation, validation, and configuration.
```APIDOC
ShortUniqueId:
__constructor(options?: object)
Initializes a new instance of ShortUniqueId.
Options can include:
- dictionary: string[] | ShortUniqueIdDefaultDictionaries
- shuffle: boolean
- debug: boolean
- uuidLength: number
- counter: number
- seed: number
validate(uid: string, dictionary?: string[] | ShortUniqueIdDefaultDictionaries): boolean[]
Validates a UID against a dictionary.
Parameters:
uid: The unique identifier string to validate.
dictionary: An optional array of characters or a predefined dictionary to use for validation.
Returns: An array of booleans, where each boolean corresponds to the validity of a character in the UID.
randomUUID(): string
Generates a random UUID.
sequentialUUID(): string
Generates a sequential UUID.
setDictionary(dictionary: string[] | ShortUniqueIdDefaultDictionaries): void
Sets a new dictionary for ID generation and validation.
dictLength(): number
Returns the length of the current dictionary.
version(): string
Returns the version of the library.
```
--------------------------------
### ShortUniqueId Browser Usage
Source: https://github.com/simplyhexagonal/short-unique-id/blob/main/docs/index.html
Illustrates how to include and use the ShortUniqueId library directly in a web browser using a CDN link. It shows basic instantiation and generation of random or sequential UUIDs.
```html
```
--------------------------------
### Releasing Changes
Source: https://github.com/simplyhexagonal/short-unique-id/blob/main/docs/index.html
Command to initiate the release process after building the distribution files. This typically involves committing changes and running a release script to publish the updated package.
```bash
pnpm release
```
--------------------------------
### short-unique-id API
Source: https://github.com/simplyhexagonal/short-unique-id/blob/main/docs/classes/shortUniqueIdV532.html
API documentation for the short-unique-id library, detailing available functions and their parameters.
```APIDOC
collisionProbability(rounds?, uuidLength?):
Calculates probability of generating duplicate UUIDs (a collision) in a given number of UUID generation rounds.
Given that:
* `r` is the maximum number of times that `randomUUID()` will be called, or better said the number of _rounds_
* `H` is the total number of possible UUIDs, or in terms of this library, the result of running `availableUUIDs()`
Then the probability of collision `p(r; H)` can be approximated as the result of dividing the square root of the product of half of pi times `r` by `H`:
{
dataLayer.push(arguments);
}
gtag('js', new Date());
gtag('config', 'UA-159642755-1');
```
--------------------------------
### CLI Timestamp UUID Generation and Parsing
Source: https://github.com/simplyhexagonal/short-unique-id/blob/main/docs/index.html
Shows how to use the command-line interface (CLI) to generate a UUID with a timestamp and parse the timestamp from a given UUID.
```bash
$ suid -s -l 42
lW611f30a2ky4276g3l8N7nBHI5AQ5rCiwYzU47HP2
$ suid -p lW611f30a2ky4276g3l8N7nBHI5AQ5rCiwYzU47HP2
2021-08-20T04:33:38.000Z
```
--------------------------------
### UUID Validation
Source: https://github.com/simplyhexagonal/short-unique-id/blob/main/README.md
Shows how to validate UUIDs against the instance's default dictionary or a custom provided dictionary using the .validate() method. It includes generating a UUID first.
```js
// Instantiate using one of the default dictionary strings
const uid = new ShortUniqueId({
dictionary: 'hex',
});
const uuid = uid.stamp(32); // Generate a UUID
// Validate the generated UUID against the instance dictionary
const isValid = uid.validate(uuid);
console.log(`Is the UUID valid? ${isValid}`);
// ---
// Validate the generated UUID against the provided dictionary
const customDictionary = ['a', 'b', /* ... */];
const isValid = uid.validate(uuid, customDictionary);
console.log(`Is the UUID valid? ${isValid}`);
```
--------------------------------
### Generate Random UUIDs
Source: https://github.com/simplyhexagonal/short-unique-id/blob/main/README.md
Demonstrates how to create a new ShortUniqueId instance with a specified length and generate random IDs using the `rnd()` method or by destructuring `randomUUID`.
```ts
const uid = new ShortUniqueId({ length: 10 });
uid.rnd(); // p0ZoB1FwH6
uid.rnd(); // mSjGCTfn8w
uid.rnd(); // yt4Xx5nHMB
// ...
// or
const { randomUUID } = new ShortUniqueId({ length: 10 });
randomUUID(); // e8Civ0HoDy
randomUUID(); // iPjiGoHXAK
randomUUID(); // n528gSMwTN
// ...
```
--------------------------------
### Basic UUID Generation
Source: https://github.com/simplyhexagonal/short-unique-id/blob/main/docs/index.html
Illustrates the fundamental usage of ShortUniqueId for generating random UUIDs. It covers instantiation with a specified length and using the `rnd()` method or destructuring for direct access.
```javascript
const uid = new ShortUniqueId({ length: 10 });
uid.rnd(); // p0ZoB1FwH6
uid.rnd(); // mSjGCTfn8w
uid.rnd(); // yt4Xx5nHMB
// ...
// or
const { randomUUID } = new ShortUniqueId({ length: 10 });
randomUUID(); // e8Civ0HoDyr
randomUUID(); // iPjiGoHXAK
randomUUID(); // n528gSMwTN
// ...
```
--------------------------------
### Customizing Dictionaries
Source: https://github.com/simplyhexagonal/short-unique-id/blob/main/README.md
Illustrates how to instantiate the library with a specific dictionary or change the dictionary after instantiation. The library supports default dictionaries like 'hex', 'alpha', 'alphanum', and more, which are generated on the fly.
```js
// instantiate using one of the default dictionary strings
const uid = new ShortUniqueId({
dictionary: 'hex',
});
console.log(uid.dict.join());
// 0,1,2,3,4,5,6,7,8,9,a,b,c,d,e,f
// or change the dictionary after instantiation
uid.setDictionary('alpha_upper');
console.log(uid.dict.join());
// A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z
```
--------------------------------
### Browser Usage
Source: https://github.com/simplyhexagonal/short-unique-id/blob/main/docs/index.html
Demonstrates how to integrate and use the short-unique-id library within a web browser environment, typically via a script tag.
```javascript
```
--------------------------------
### Google Analytics Configuration
Source: https://github.com/simplyhexagonal/short-unique-id/blob/main/docs/modules.html
Configures Google Analytics (gtag.js) for tracking, initializing the dataLayer and setting the configuration with a measurement ID.
```javascript
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-159642755-1');
```