Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/zhangmingfeng/egg-easy-utils
egg utils plugin
https://github.com/zhangmingfeng/egg-easy-utils
egg-easy-utils egg-plugin helper utils
Last synced: about 2 months ago
JSON representation
egg utils plugin
- Host: GitHub
- URL: https://github.com/zhangmingfeng/egg-easy-utils
- Owner: zhangmingfeng
- License: mit
- Created: 2018-09-10T08:51:46.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2018-09-10T08:51:56.000Z (over 6 years ago)
- Last Synced: 2024-08-09T03:17:24.744Z (6 months ago)
- Topics: egg-easy-utils, egg-plugin, helper, utils
- Language: JavaScript
- Homepage:
- Size: 1.95 KB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# egg-easy-utils
该插件是为了解放helper, 统一管理工具类函数, 按模块分类,比如: strings, arrays# Install
```bash
$ npm i --save egg-easy-utils
```## Usage & configuration
- `config.default.js`
```js
// 相对app目录的路径,默认值utils
exports.utils = {
path: 'utils'
};
```- `config/plugin.js`
``` js
exports.utils = {
enable: true,
package: 'egg-easy-utils'
}
```### example
```js
// app/utils/strings.js
module.exports = (app) => {
return {
md5(str) {
const md5sum = crypto.createHash('md5');
md5sum.update(str);
return md5sum.digest('hex');
}
}
}
```
```js
// controller.js or service.js
console.log(this.ctx.utils.strings.md5('test-md5'));//print: 42505649011f560d32a0a7a6427a8778
```