@centralping/micro-json-api-query

0.1.0 • Public • Published

@CentralPing/micro-json-api-query

Build Status Coverage Status Dependency Status Greenkeeper Status Known Vulnerabilities

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

Package Sidebar

Install

npm i @centralping/micro-json-api-query

Weekly Downloads

1

Version

0.1.0

License

MIT

Unpacked Size

10.6 kB

Total Files

7

Last publish

Collaborators

  • centralping-admin
  • jasoncust