/**
* @packageDocumentation
**/
export interface ShortUniqueIdRanges {
[k: string]: [number, number];
}
export interface ShortUniqueIdRangesMap {
[k: string]: ShortUniqueIdRanges;
}
export type ShortUniqueIdDefaultDictionaries = 'number' | 'alpha' | 'alpha_lower' | 'alpha_upper' | 'alphanum' | 'alphanum_lower' | 'alphanum_upper' | 'hex';
/**
* ```js
* {
* dictionary: ['z', 'a', 'p', 'h', 'o', 'd', ...],
* shuffle: false,
* debug: false,
* length: 6,
* }
* ```
*
* @see {@link DEFAULT_OPTIONS}
*/
export interface ShortUniqueIdOptions {
/** User-defined character dictionary */
dictionary: string[] | ShortUniqueIdDefaultDictionaries;
/** If true, sequentialUUID use the dictionary in the given order */
shuffle: boolean;
/** If true the instance will console.log useful info */
debug: boolean;
/** From 1 to infinity, the length you wish your UUID to be */
length: number;
/** From 0 to infinity, the current value for the sequential UUID counter */
counter: number;
}
/**
* 6 was chosen as the default UUID length since for most cases
* it will be more than aptly suitable to provide millions of UUIDs
* with a very low probability of producing a duplicate UUID.
*
* For example, with a dictionary including digits from 0 to 9,
* as well as the alphabet from a to z both in UPPER and lower case,
* the probability of generating a duplicate in 1,000,000 rounds
* is ~0.00000002, or about 1 in 50,000,000.
*/
export declare const DEFAULT_UUID_LENGTH: number;
export declare const DEFAULT_OPTIONS: ShortUniqueIdOptions;
/**
* Generate random or sequential UUID of any length.
*
* ### Use as module
*
* ```js
* // Deno (web module) Import
* import ShortUniqueId from 'https://cdn.jsdelivr.net/npm/short-unique-id@latest/src/index.ts';
*
* // ES6 / TypeScript Import
* import ShortUniqueId from 'short-unique-id';
*
* // or Node.js require
* const ShortUniqueId = require('short-unique-id');
*
* // Instantiate
* const uid = new ShortUniqueId();
*
* // Random UUID
* console.log(uid.rnd());
*
* // Sequential UUID
* console.log(uid.seq());
* ```
*
* ### Use in browser
*
* ```html
*
*
*
*
*
* ```
*
* ### Options
*
* Options can be passed when instantiating `uid`:
*
* ```js
* const options = { ... };
*
* const uid = new ShortUniqueId(options);
* ```
*
* For more information take a look at the [ShortUniqueIdOptions type definition](/interfaces/shortuniqueidoptions.html).
*/
export default class ShortUniqueId {
/** @hidden */
static default: typeof ShortUniqueId;
counter: number;
debug: boolean;
dict: string[];
version: string;
dictIndex: number;
dictRange: number[];
lowerBound: number;
upperBound: number;
dictLength: number;
uuidLength: number;
protected _digit_first_ascii: number;
protected _digit_last_ascii: number;
protected _alpha_lower_first_ascii: number;
protected _alpha_lower_last_ascii: number;
protected _hex_last_ascii: number;
protected _alpha_upper_first_ascii: number;
protected _alpha_upper_last_ascii: number;
protected _number_dict_ranges: ShortUniqueIdRanges;
protected _alpha_dict_ranges: ShortUniqueIdRanges;
protected _alpha_lower_dict_ranges: ShortUniqueIdRanges;
protected _alpha_upper_dict_ranges: ShortUniqueIdRanges;
protected _alphanum_dict_ranges: ShortUniqueIdRanges;
protected _alphanum_lower_dict_ranges: ShortUniqueIdRanges;
protected _alphanum_upper_dict_ranges: ShortUniqueIdRanges;
protected _hex_dict_ranges: ShortUniqueIdRanges;
protected _dict_ranges: ShortUniqueIdRangesMap;
protected log: (...args: any[]) => void;
/** Change the dictionary after initialization. */
setDictionary: (dictionary: string[] | ShortUniqueIdDefaultDictionaries, shuffle?: boolean) => void;
seq: () => string;
/**
* Generates UUID based on internal counter that's incremented after each ID generation.
* @alias `const uid = new ShortUniqueId(); uid.seq();`
*/
sequentialUUID: () => string;
rnd: (uuidLength?: number) => string;
/**
* Generates UUID by creating each part randomly.
* @alias `const uid = new ShortUniqueId(); uid.rnd(uuidLength: number);`
*/
randomUUID: (uuidLength?: number) => string;
fmt: (format: string, date?: Date) => string;
/**
* Generates custom UUID with the provided format string.
* @alias `const uid = new ShortUniqueId(); uid.fmt(format: string);`
*/
formattedUUID: (format: string, date?: Date) => string;
/**
* Calculates total number of possible UUIDs.
*
* Given that:
*
* - `H` is the total number of possible UUIDs
* - `n` is the number of unique characters in the dictionary
* - `l` is the UUID length
*
* Then `H` is defined as `n` to the power of `l`:
*
*