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
$ npm i eggjs-hashids --save
// {app_root}/config/plugin.js
exports.hashids = {
enable: true,
package: 'eggjs-hashids',
};
// {app_root}/config/config.default.js
exports.hashids = {
salt: '',
minLength: 0,
alphabet: 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890',
};
see config/config.default.js and hashids for more detail.
this.app.hashids.encode(1); // => 'jR'
this.app.hashids.decode('jR'); // => [ 1 ]
this.app.hashids.encodeHex('507f1f77bcf86cd799439011'); // => 'y42LW46J9luq3Xq9XMly'
this.app.hashids.decodeHex('y42LW46J9luq3Xq9XMly'); // => '507f1f77bcf86cd799439011'
Please open an issue here.