charset-utils

1.0.0 • Public • Published

Actions Status NPM Version

Charset utilities. Contains helper functions related to charset.

Installation

npm install charset-utils
# Or 
yarn add charset-utils

Usage

const { getIndexVal } = require('charset-utils');
// Or
const getIndexVal = require('charset-utils/libs/getIndexVal');
 
getIndexVal(100, 'abcdefghijklmnopqrstuvwxyz');
// Output: dw

Available Function

getIndexVal(index, charset) string

  • index - Desired index value
  • charset - 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: 0006

randomIntInclusive(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: 8

shuffleCharset(charset) string

  • charset - Target charset

Randomize the entered charset. Example:

shuffleCharset('abc');
// Output: bca
 
shuffleCharset('abcd');
// Output: dacb
 
shuffleCharset('0123456');
// Output: 214653

Package Sidebar

Install

npm i charset-utils

Weekly Downloads

1

Version

1.0.0

License

MIT

Unpacked Size

6.57 kB

Total Files

13

Last publish

Collaborators

  • laodemalfatih