eggjs-hashids

    1.0.1 • Public • Published

    egg-hashids

    NPM version build status Test coverage David deps Known Vulnerabilities npm download

    Hashids is small JavaScript library to generate YouTube-like ids from numbers. Use it when you don't want to expose your database ids to the user.

    This plugin is only for egg.js

    Install

    $ npm i eggjs-hashids --save

    Usage

    // {app_root}/config/plugin.js
    exports.hashids = {
      enable: true,
      package: 'eggjs-hashids',
    };

    Configuration

    // {app_root}/config/config.default.js
    exports.hashids = {
      salt: '',
      minLength: 0,
      alphabet: 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890',
    };

    see config/config.default.js and hashids for more detail.

    Example

    this.app.hashids.encode(1);   // => 'jR'
    this.app.hashids.decode('jR'); // => [ 1 ]
    this.app.hashids.encodeHex('507f1f77bcf86cd799439011'); // => 'y42LW46J9luq3Xq9XMly'
    this.app.hashids.decodeHex('y42LW46J9luq3Xq9XMly'); // => '507f1f77bcf86cd799439011'

    Questions & Suggestions

    Please open an issue here.

    License

    MIT

    Install

    npm i eggjs-hashids

    DownloadsWeekly Downloads

    8

    Version

    1.0.1

    License

    MIT

    Unpacked Size

    8.1 kB

    Total Files

    8

    Last publish

    Collaborators

    • avatar