1.0.0 • Published 6 years ago
charset-utils v1.0.0
Charset utilities. Contains helper functions related to charset.
Installation
npm install charset-utils
# Or
yarn add charset-utilsUsage
const { getIndexVal } = require('charset-utils');
// Or
const getIndexVal = require('charset-utils/libs/getIndexVal');
getIndexVal(100, 'abcdefghijklmnopqrstuvwxyz');
// Output: dwAvailable Function
getIndexVal(index, charset) string
index- Desired index valuecharset- Target charset
Get charset value based on the index entered. Example:
getIndexVal(1502, '0123456789');
// Output: 1502
getIndexVal(2, 'abcdef');
// Output: c
getIndexVal(25, 'abcdefghijklmnopqrstuvwxyz');
// Output: z
getIndexVal(26, 'abcdefghijklmnopqrstuvwxyz');
// Output: ba
// With .padStart
getIndexVal(6, '0123456789').padStart(4, '0');
// Output: 0006randomIntInclusive(min, max) number
min- Minimal random value will be generated (inclusive)max- Max random value will be generated (inclusive)
Generate random number with min(inclusive) and max(inclusive). Example:
randomIntInclusive(0, 5);
// Output: 4
randomIntInclusive(0, 5);
// Output: 0
randomIntInclusive(0, 8);
// Output: 8shuffleCharset(charset) string
charset- Target charset
Randomize the entered charset. Example:
shuffleCharset('abc');
// Output: bca
shuffleCharset('abcd');
// Output: dacb
shuffleCharset('0123456');
// Output: 2146531.0.0
6 years ago