odeo-random-string-generator
v1.0.3
Published
npm i odeo-random-string-generator
Downloads
3
Readme
Installation
npm i odeo-random-string-generator
Usage
Using CommonJS
const {randomStringGenerator} = require('odeo-random-string-generator/cjs');
Using ES6
import { randomStringGenerator } from 'odeo-random-string-generator/esm'
Examples
randomStringGenerator({ length: 32 })
// VIJGJNjhj9a@0w"m1c.wG41>^VEa'vRg
// If no data type is specified, the random string will be generated using printable characters.
randomStringGenerator({ length: 32, dataType: DataType.ALPHANUMERIC})
// WpdAXR8i8vwLat9x5ni6qwEvMkjNYrkB
randomStringGenerator({ length: 32, dataType: DataType.ALPHABET})
// aGllCjKCGSMOgUDJXRohxYvqhcJRMYrD
randomStringGenerator({ length: 32, dataType: DataType.BASE64})
// 6ZRzMhBPvQGgj8CFZqvpwswrjCQ0ktx9NoBJ3jgRmsA=
// Note. This generates random bytes of the requested length which is then encoded to a Base64 string
// so the Base64 string will be longer than the requested length.
randomStringGenerator({ length: 32, dataType: DataType.NUMERIC})
// 83573362289418518982677306029602
randomStringGenerator({ length: 32, dataType: DataType.HEXADECIMAL})
// c052179ccab09ff24cbd46c78a11e5c9
randomStringGenerator({ length: 32, dataType: DataType.PRINTABLE_CHARACTERS})
// G(4~(?4Q/T{;!A[:|[jZn{C"G/4caKTv
randomStringGenerator({ length: 32, dataType: DataType.URL_SAFE_CHARACTERS})
// -Py4nXvFF-fq9Nm0VYIra.unJlNxF3yW
result = randomStringGenerator({ length: 10, dataType: DataType.CUSTOM_CHARACTERS, characters: 'ABCD'})
// ABDDCDABCC