1.0.1 • Published 7 years ago
eggjs-hashids v1.0.1
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 --saveUsage
// {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.