Nutritious Pancake Mountain
    Have ideas to improve npm?Join in the discussion! »

    hashids-extended
    TypeScript icon, indicating that this package has built-in type declarations

    1.0.7 • Public • Published

    Build status Coverage Status GitHub

    node-hashids-extended

    Extended hashids for feel comfortable. Sometimes you would like to encode/decode only 1 number, but you have to use the first element of decoded array, or write a wrapper to handle it. No more!

    Installation

    npm install hashid-extended --save

    Usage

    Javascript

    const { HashidsExtended } = require('hashids-extended');
    
    const hash = new HashidsExtended(
      'mysalt',
      10,
      'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890'
    );
    const myHashedValue = hash.encode(1);
    const myHashedArray = hash.encodeArray(2, 3, 4, 5);
    
    const decodedValue = hash.decode(myHashedValue);
    const firstValue = hash.decode(myHashedArray);
    const decodedArray = hash.decodeArray(myHashedArray);
    
    console.log(decodedValue);
    console.log(firstValue);
    console.log(decodedArray);
    
    // output:
    // 1
    // 2
    // [2,3,4,5]

    Typescript

    import HashidsExtended from 'hashids-extended';
    
    const hash = new HashidsExtended(
      'mysalt',
      10,
      'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890'
    );
    const myHashedValue = hash.encode(1);
    const myHashedArray = hash.encodeArray(2, 3, 4, 5);
    
    const decodedValue = hash.decode(myHashedValue);
    const firstValue = hash.decode(myHashedArray);
    const decodedArray = hash.decodeArray(myHashedArray);
    
    console.log(decodedValue);
    console.log(firstValue);
    console.log(decodedArray);
    
    // output:
    // 1
    // 2
    // [2,3,4,5]

    Test

    npm run test

    Install

    npm i hashids-extended

    DownloadsWeekly Downloads

    3

    Version

    1.0.7

    License

    ISC

    Unpacked Size

    55.5 kB

    Total Files

    21

    Last publish

    Collaborators

    • avatar