### 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`: ![](data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAANIAAABJCAYAAABIOHjCAAAO+klEQVR4Ae2dBfDsxg3GvzIzY8qMaVJMGVNmZpjSlJnbtCmkkDIzTxlSxpSbMjOnzMxwv9fVG42f9yz7zgd/SzOe89mL8pK0n7RSUnJgOzlwA0mflfSODbm2k4tZ6klz4JiSfiHpvZIO3pBr0h8kK7+dHLi7pF9KOtZ2Fj9LnRxYPweOIukHku6//qJkCZID28uB20n6naTjV6pwZEnXk3SApMfOue5WiZ+PkwM7ngNHkvRNSY+s1PQYRW76i6TvSPqNpMPL/c8lcfGc612VNPJxcmDHc+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y1iqdnXwOLxuufgmOsgjQKCr+PGnBc26J9+YYr3kejGXB7jkfyDZT7bn9shdUm80sjP0uKh+x+TgUHo9ygXpwRfahvP1Rcyaw+kR+6YTkGV16NdOE/36vrfne/wfvyH4g+bEcxbiNZZ9tcuNDLlJ3n2beBzhgGjQYj4q6SaYWn2dDwkiIR5gImTOKISM8KnbKyTJz3vKlVg7gScSPwJlIA5nGGqSH5dfSrz3H+pbT3ubNKLW4PMc7Tg0L2RYPVTkyKzAsk6Gw1kVr2NedcFv6+ayFA/gVoLEwK6FFw6zaiFEYB36oPA2RYO/8r424LJ26yI7NGDLCgwmkrFzRZRIdgMaDUgQ5g7jIaGjS2nBpLOeQO5DfDNGAow78EOAhZwhhqbmITdIiG6ggUvwG+pDyZ5wABxBOaVwoC0Ap4PIVlAKjKJ2LpVgXce4naUTkDhonWqchIzyYMzrBZ2YQosix78xabL6iYGg6OgG0yszkvcswWIDURqPXDA9ol/B97Vo4aQHY1TK8iXZ9h3y/Rg6AyaITMGJDwPVBfvf18ELjfmVJY94P6fpZb17Y2jsQEkP3QWppjvX8VgXwWoNdjZXvtqfLDA5iHqUUqyK7kMe5mlpilu0sn4ljYfklLFrKCBZ0MM9MPkJtumjjRr4C3zV0+dOnEgBtayYdfdJZR ``` -------------------------------- ### Browser Usage Source: https://github.com/simplyhexagonal/short-unique-id/blob/main/README.md Illustrates how to include the ShortUniqueId library in an HTML file using a CDN link and then use it to generate random or sequential UUIDs directly in the browser's JavaScript. ```html ``` -------------------------------- ### Google Analytics Configuration Source: https://github.com/simplyhexagonal/short-unique-id/blob/main/docs/variables/DEFAULT_OPTIONS.html This JavaScript snippet configures Google Analytics by initializing the dataLayer and setting up the gtag function for tracking. ```javascript window.dataLayer = window.dataLayer || []; function gtag(){ 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'); ```