@centralping/micro-json-api-query
v0.1.0
Published
A JSON API compliant query parameter validator for micro.
Downloads
5
Readme
@CentralPing/micro-json-api-query
A micro wrapper for parsing and validating querystrings with json-api-query.
Installation
npm i --save @centralping/micro-json-api-query
API Reference
microJsonApiQuery~schema : Object
Module property that generates a new deep copy of the default schema
on every import. Apply any extensions and provide as an optional schema
for the validate
method.
Kind: inner property of microJsonApiQuery
microJsonApiQuery~parse ⇒ function
Kind: inner property of microJsonApiQuery
Returns: function - The configured parser function
| Param | Type | Default | Description |
| --- | --- | --- | --- |
| [options] | Object | | Any AJV option. |
| [options.coerceTypes] | Boolean | String | 'array' | Coerces validated values to specified types in the schema. |
| [options.ownProperties] | Boolean | true | Restricts validation to own properties of data object. |
| [schema] | Object | | A JSON Schema for a JSON API query. Defaults to the included schema
. |
Example
const parser = parse();
Examples
For Default Parsing
const {parse} = require('@centralping/micro-json-api-query');
const parser = parse();
// req is the micro request object
const {query} = parser(req);
For AJV Options
const {parse} = require('@centralping/micro-json-api-query');
const parser = parse({allErrors: true});
// req is the micro request object
const {query} = parser(req);
For Extended Verification
const {parse, schema} = require('@centralping/micro-json-api-query');
// extend schema
const parser = parse(undefined, schema);
// req is the micro request object
const {query} = parser(req);
Test
npm test
With coverage reporting:
npm test -- --coverage
With file watch:
npm run watch
License
MIT