@cylution/string-random
v1.0.6
Published
creating random id, slug, salt, password, ...
Downloads
3
Readme
@cylution/string-random
npm i @cylution/string-random
Or
yarn add @cylution/string-random
generate random string
Usage
js
const StringRandom = require('@cylution/string-random')
console.log(StringRandom.rand(10, StringRandom.lowerCharacters))
// => mhixlmigag
ts
import StringRandom from '@cylution/string-random'
console.log(StringRandom.rand(10, StringRandom.lowerCharacters))
// => mhixlmigag
methods
rand(length = 10, characters: string[]) => string
- length: return string length
- characters: random in characters
randPickCharactersFromEveryGroups(length: number, ...groups: string[][]) => string
This method same as rand() but it will pick characters from every input's groups
- length: return string length
- ...groups: rest of characters input
exports characters
const lowerCharacters = 'abcdefghijklmnopqrstuvwxyz'.split('')
const upperCharacters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'.split('')
const numericCharacters = '0123456789'.split('')
const specialPrintableCharacters = '!"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~'.split('')
const urlSafeCharacters = [].concat(lowerCharacters, upperCharacters, numericCharacters, '-._~'.split(''))
const distinguishableCharacters = 'CDEHKMPRTUWXY012458'.split('')
const asciiPrintableCharacters = [].concat(lowerCharacters, upperCharacters, numericCharacters, specialPrintableCharacters)
const alphanumericCharacters = [].concat(lowerCharacters, upperCharacters, numericCharacters)