eggjs-hashids
v1.0.1
Published
Generate a short unique ID from the integer for egg.js
Downloads
3
Maintainers
Readme
egg-hashids
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.