# koa-params-extractor

> Extract Koa's Parameters

Latest version **3.9.7** (published 2020-02-11) · MIT license · 0 weekly downloads

## Install

```sh
npm install koa-params-extractor
pnpm add koa-params-extractor
yarn add koa-params-extractor
bun add koa-params-extractor
```

## 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 | 3.9.7 |
| Published | 2020-02-11 |
| First published | 2020-01-14 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 10.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Park Si-Yual |
| Maintainers | araxsiyual |

## Links

- npm: https://www.npmjs.com/package/koa-params-extractor
- Homepage: https://github.com/kdPark0723/koa-params-extractor
- Issues: https://github.com/kdPark0723/koa-params-extractor/issues
- npm.io page: https://npm.io/package/koa-params-extractor

## Recent versions

- 3.9.7 (latest) — 2020-02-11
- 3.9.6 — 2020-02-11
- 3.9.5 — 2020-02-11
- 3.9.4 — 2020-02-11
- 3.9.3 — 2020-02-11
- 3.9.2 — 2020-02-11
- 3.9.1 — 2020-02-11
- 3.9.0 — 2020-02-11
- 3.8.8 — 2020-02-10
- 3.8.7 — 2020-02-09
- 3.8.6 — 2020-02-09
- 3.8.5 — 2020-02-09
- 3.8.4 — 2020-02-09
- 3.8.3 — 2020-02-09
- 3.8.2 — 2020-02-09
- … 23 more at https://npm.io/package/koa-params-extractor/versions

## README

# Koa Params Extractor

![](https://img.shields.io/npm/dm/koa-params-extractor.png?style=flat-square)

**Extract Koa's request parameters**

​    

Helps to get parameters (headers, params, query, body) that can be distributed or in different locations in a consistent way

1. find in alias location. (ctx.xxx)
2. find in req location. (ctx.req.xxx)
3. find in request location. (ctx.request.xxx)

​        

## Install

```shell
$ npm i koa-params-extractor
```

​        

## Usage

```js
const paramsExtractor = require('koa-params-extractor');

router.post('/user', async (ctx) => {
  const { id, username, password } = paramsExtractor.extract(ctx);
    
  const response = await signUpUser({ id, username, password });
  ctx.body = response;
});
```

​    

### Extract

```js
paramsExtractor.extract(ctx, parameters = [parameter.headers, parameter.params, parameter.query, parameter.body]);
```

​    

### Parameters

```js
function Parameter(
  where = new Where(null, true, true, true),
  options = { name: null, combineLevel: 0, as: null, index: undefined }
) {
  this.where = where;
  this.name = options.name;
  this.combineLevel = options.combineLevel;
  this.as = options.as;
  this.index = options.index;
}

function Where(name, koaRequest, nodeRequest, context) {
  this.name = name;
  this.koaRequest = koaRequest;
  this.nodeRequest = nodeRequest;
  this.context = context;
}
```

- Parameters defines the information of the parameters to pass.
  - `where` defines where to find the parameter.
    - If `where` is not an instance of `Where`, the parameter is `where` .
    - If `where` is an instance of `Where`, the parameter is found in `ctx` with information from `where`.
  - `name` is the name of the parameter.
    - If `name` exists, the same name is taken from the parameter's location.
  - `combineLevel` is the level at which the imported arguments are to be combined.
    - `0` means the imported parameter is the parameter to pass.
    - `1` means the imported parameter is a child of the parameter to pass.
  - `as` specifies a name when passing a parameter.
  - `index` is index of the parameter to pass.
- Where defines where to find the parameter.
  - `name` is the name of the location from which to retrieve the parameter.
  - `koaRequest` means to find the location of a parameter in `ctx.request`.
  - `nodeRequest` means to find the location of a parameter in `ctx.req`.
  - `context` means to find the location of a parameter in `ctx`.

- The default value is params, query, header, body, cookies defined.

​

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