3.9.7 • Published 6 years ago
koa-params-extractor v3.9.7
Koa Params Extractor

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
- find in alias location. (ctx.xxx)
- find in req location. (ctx.req.xxx)
- find in request location. (ctx.request.xxx)
Install
$ npm i koa-params-extractor
Usage
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
paramsExtractor.extract(ctx, parameters = [parameter.headers, parameter.params, parameter.query, parameter.body]);
Parameters
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.
wheredefines where to find the parameter.- If
whereis not an instance ofWhere, the parameter iswhere. - If
whereis an instance ofWhere, the parameter is found inctxwith information fromwhere.
- If
nameis the name of the parameter.- If
nameexists, the same name is taken from the parameter's location.
- If
combineLevelis the level at which the imported arguments are to be combined.0means the imported parameter is the parameter to pass.1means the imported parameter is a child of the parameter to pass.
asspecifies a name when passing a parameter.indexis index of the parameter to pass.
Where defines where to find the parameter.
nameis the name of the location from which to retrieve the parameter.koaRequestmeans to find the location of a parameter inctx.request.nodeRequestmeans to find the location of a parameter inctx.req.contextmeans to find the location of a parameter inctx.
The default value is params, query, header, body, cookies defined.
3.9.7
6 years ago
3.9.6
6 years ago
3.9.5
6 years ago
3.9.4
6 years ago
3.9.3
6 years ago
3.9.2
6 years ago
3.9.1
6 years ago
3.9.0
6 years ago
3.8.8
6 years ago
3.8.4
6 years ago
3.8.3
6 years ago
3.8.2
6 years ago
3.8.1
6 years ago
3.8.7
6 years ago
3.8.6
6 years ago
3.8.5
6 years ago
3.8.0
6 years ago
3.7.1
6 years ago
3.6.2
6 years ago
3.7.0
6 years ago
3.6.1
6 years ago
3.4.0
6 years ago
3.3.1
6 years ago
3.5.1
6 years ago
3.5.0
6 years ago
3.4.1
6 years ago
3.3.0
6 years ago
3.2.0
6 years ago
3.1.0
6 years ago
3.0.1
6 years ago
3.0.0
6 years ago
2.0.1
6 years ago
2.0.0
6 years ago
1.0.3
6 years ago
1.0.2
6 years ago
1.0.1
6 years ago
1.0.0
6 years ago
0.0.0
6 years ago