Generate a unique ID in Document
Generate a unique ID in Document.
Demo
Examples
import DocumentGenerateId from '@saekitominaga/document-generate-id';
const documentGenerateId1 = new DocumentGenerateId();
documentGenerateId1.generate(); // e.g. GUaHJ6ao5m
const documentGenerateId2 = new DocumentGenerateId(8, {
alphalower: true,
alphaupper: false,
number: true,
symbol: '-_:.',
}, 'js-', 3);
documentGenerateId2.generate(); // e.g. js-7f3h1w:l
Constructor
new DocumentGenerateId(
length = 10,
charactorType = {
alphalower: true,
alphaupper: true,
number: true,
symbol: '',
},
prefix = '',
trialLimit = 10
)
Parameters
-
length
[Optional] - Length of ID (Excluding the prefix part)
-
charactorType
[Optional] - Type of characters used for ID
-
alphalower
[Optional] - [a-z]
-
alphaupper
[Optional] - [A-Z]
-
number
[Optional] - [0-9]
-
symbol
[Optional] - Enumerate symbol characters (e.g. '-_:.')
-
-
prefix
[Optional] - Prefix of ID
-
trialLimit
[Optional] - Maximum number of attempts if the generated ID exists in the document
Methods
generate(): string
- Generate a unique ID in document