@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();
const {query} = parser(req);
For AJV Options
const {parse} = require('@centralping/micro-json-api-query');
const parser = parse({allErrors: true});
const {query} = parser(req);
For Extended Verification
const {parse, schema} = require('@centralping/micro-json-api-query');
const parser = parse(undefined, schema);
const {query} = parser(req);
Test
npm test
With coverage reporting:
npm test -- --coverage
With file watch:
npm run watch
License
MIT