Noisy Pneumatic Mnemonic

    fast-key-generator
    TypeScript icon, indicating that this package has built-in type declarations

    1.0.1 • Public • Published

    fast-key-generator

    Simple utils library for API calls.

    npm version npm downloads npm license


    Instalation

    To install fast-key-generator - you can use npm or yarn package manager.
    npm install fast-key-generator --save
    yarn add fast-key-generator

    Documentation

    The fast-key-generator library includes only one function generateKey. Below you can find the documentation for this function.


    The generateKey function

    The simple method for key generation.
    The generateKey function takes only one parameter, which is an object.
    The options parameter may includes the following fields:
    Name Type Default value Description
    size number 16 Key size (without prefix).
    prefix string "" Key prefix.
    chartype string "alpha" Can be one of "alpha", "numeric", "alphanum", "symbols".
    chartset string "" If you provide charset, then the generator will use the characters from this charset & ignore the chartype.
    transform string or function "none" Can be one of "none", "lower", "upper" or custom function that takes a key as the first argument & should return formatted key.
    validate function empty function If the function returns true, the generation process will be completed. If false, the generation process will start again until the function returns true.
    exclude array of strings [] An array of strings that should not be keys.

    Examples

    import { generateKey } from 'fast-key-generator';
     
    const key = generateKey();
    // The key will be a string with a length of 16
     

    import { generateKey } from 'fast-key-generator';
     
    const key = generateKey({
      size: 1,
      prefix: 'key_',
      chartype: 'numeric',
      exclude: [
        'key_0',
        'key_1',
        'key_2',
        'key_3',
        'key_4',
        'key_5',
        'key_6',
        'key_7',
        'key_8',
      ]
    });
     
    // The key will be "key_9"
     

    import { generateKey } from 'fast-key-generator';
     
    const key = generateKey({
      size: 1,
      prefix: 'key_',
      chartype: 'numeric',
      validate: (key) => key.includes('2')
    });
     
    // The key will be "key_2"

    Install

    npm i fast-key-generator

    DownloadsWeekly Downloads

    99

    Version

    1.0.1

    License

    MIT

    Unpacked Size

    6.53 kB

    Total Files

    6

    Last publish

    Collaborators

    • npm