1.2.0 • Published 3 years ago

uniquejs v1.2.0

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

Unique.js

A JavaScript library to generate random strings based on a pattern/schema.

Installation

Using npm:

npm install uniquejs

Examples

unique() // '08ycyk5878192wfm011lr7g6n1r40qtk'

unique(9) // '7q5o98g9g'

unique('aaa-nn-aaa_AA') // returns 'sor-50-kli_PT'

unique('anA') // returns 'p3S'

unique('A', 8) // 'MPGZACIY'

Usage

const unique = require('uniquejs');

unique() // '08ycyk5878192wfm011lr7g6n1r40qtk'
// returns a 32-character long alphanumberical string

unique(9) // '7q5o98g9g'
// returns an alphanumerical string of length of 9 characters

unique('n', 8) // '12934888'
unique('n') // '467463'
// returns a numerical string with length of 8 characters (defaults to 6 characters)

unique('a', 5) // 'gmlcv'
unique('a') // 'hgsdqz'
// returns a string of 5 lowercase characters (defaults to 6 characters)

unique('A', 8) // 'MPGZACIY'
unique('A') // 'UNIQUE'
// returns a  string of 8 uppercase characters (defaults to 6 characters)

Alternatively, you can use a custom schema/pattern to generate greatly customizable strings:

const unique = require('uniquejs');

unique('aannAAnnaa') // returns 'bm07Q25ge'
unique('aaa-nn-aaa_AA') // returns 'sor-50-kli_PT'
unique('anA') // returns 'p3S'

where:

'n' represents a single-digit number (0-9)\ 'a' represents a lowercase alphabet (a-z)\ 'A' represents an uppercase alphabet (A-Z)

You can also add '-' and '_' to the schema to append the same at the specified index.

1.2.0

3 years ago

1.0.0

3 years ago