# egg-helper

> a egg plugins for Separate helper.js

Latest version **1.1.5** (published 2018-12-04) · MIT license · 0 weekly downloads

## Install

```sh
npm install egg-helper
pnpm add egg-helper
yarn add egg-helper
bun add egg-helper
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.5 |
| Published | 2018-12-04 |
| First published | 2018-08-07 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=8.0.0 |
| Dependencies | 0 |
| Unpacked size | 8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | yuezm |
| Maintainers | yuezm |
| Keywords | egg, eggPlugin, egg-plugin, helper, egg-helper |

## Links

- npm: https://www.npmjs.com/package/egg-helper
- Repository: https://github.com/yuezm/egg-helper
- Homepage: https://github.com/yuezm/egg-helper#readme
- Issues: https://github.com/yuezm/egg-helper/issues
- npm.io page: https://npm.io/package/egg-helper

## Alternatives

- [lodash.assign](https://npm.io/package/lodash.assign.md) — 2.3M weekly downloads
- [lodash.chunk](https://npm.io/package/lodash.chunk.md) — 1.8M weekly downloads
- [react-native-ios-utilities](https://npm.io/package/react-native-ios-utilities.md) — 138.5K weekly downloads
- [@technically/lodash](https://npm.io/package/@technically/lodash.md) — 50.9K weekly downloads
- [@fluid-topics/ft-icon](https://npm.io/package/@fluid-topics/ft-icon.md) — 20.6K weekly downloads

## Recent versions

- 1.1.5 (latest) — 2018-12-04
- 1.1.4 — 2018-12-04
- 1.1.3 — 2018-09-10
- 1.1.2 — 2018-08-10
- 1.1.1 — 2018-08-10
- 1.1.0 — 2018-08-09
- 1.0.8 — 2018-08-09
- 1.0.7 — 2018-08-08
- 1.0.6 — 2018-08-08
- 1.0.5 — 2018-08-07
- 1.0.4 — 2018-08-07
- 1.0.2 — 2018-08-07
- 1.0.1 — 2018-08-07
- 1.0.0 — 2018-08-07

## README

# egg-helper

[![NPM version][npm-image]][npm-url]
[![build status][travis-image]][travis-url]
[![Test coverage][codecov-image]][codecov-url]
[![David deps][david-image]][david-url]
[![Known Vulnerabilities][snyk-image]][snyk-url]
[![npm download][download-image]][download-url]

[npm-image]: https://img.shields.io/npm/v/egg-helper.svg?style=flat-square
[npm-url]: https://npmjs.org/package/egg-helper
[travis-image]: https://img.shields.io/travis/yuezm/egg-helper.svg?style=flat-square
[travis-url]: https://travis-ci.org/yuezm/egg-helper
[codecov-image]: https://img.shields.io/codecov/c/github/yuezm/egg-helper.svg?style=flat-square
[codecov-url]: https://codecov.io/github/yuezm/egg-helper?branch=master
[david-image]: https://img.shields.io/david/yuezm/egg-helper.svg?style=flat-square
[david-url]: https://david-dm.org/yuezm/egg-helper
[snyk-image]: https://snyk.io/test/npm/egg-helper/badge.svg?style=flat-square
[snyk-url]: https://snyk.io/test/npm/egg-helper
[download-image]: https://img.shields.io/npm/dm/egg-helper.svg?style=flat-square
[download-url]: https://npmjs.org/package/egg-helper

<!--
Description here.
-->

### 依赖说明

#### 依赖的 egg 版本

egg-helper 版本 | egg 1.x
--- | ---
1.x | 😁
0.x | ❌

#### 依赖的插件
<!--

如果有依赖其它插件，请在这里特别说明。如

- security
- multipart

-->

### 开启插件

```js
// config/plugin.js
exports.helper = {
  enable: true,
  package: 'egg-helper',
};
```
### 使用场景
在egg项目中,拆分工具函数,对工具函数单独维护
### 优势
- 插件目的是分离 app/extend/helper.js ,分成app/helper/\*\*/*.js 的单个文件,便于维护
- 插件自动读取app/helper/\*\*/文件目录下所有文件,并挂载到ctx.helper
- 插件不会覆盖 app/extend/helper.js


### 如何使用

> 创建工具函数
```
// app/helper/util.js
module.exports = app => {
  return {
    foo() {
      // app is Application的实例
      return 'hello helper';
    },
  };
};
```
如果你想使用多级目录，如下所示

```
//app/helper/util/util1.js
module.exports = app => {
  return {
    foo1() {
      // app is Application的实例
      console.log(app);
      return 'hello helper';
    },
  };
};
```
>使用工具函数

在Controller或Service中可以如下使用

```
DemoController extends Controller{
  async index(){
    this.ctx.helper.util.foo(); // 通过如下路径可以访问到你的方法
    this.ctx.helper.util.util1.foo1(); // 当你使用多级目录的时候，也是通过文件名来使用
  }
}
```

### 详细配置

请到 [config/config.default.js](config/config.default.js) 查看详细配置项说明。

### 单元测试

<!-- 描述如何在单元测试中使用此插件，例如 schedule 如何触发。无则省略。-->
```
npm run test
```

### 提问交流

请到 [egg issues](https://github.com/eggjs/egg/issues) 异步交流。

### License

[MIT](LICENSE)

---
_Source: https://npm.io/package/egg-helper · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
