Skip to content

Latest commit

 

History

History
41 lines (35 loc) · 1.29 KB

File metadata and controls

41 lines (35 loc) · 1.29 KB

API

qsStrict(options, definitions, search) ⇒ Object

Parse a queryString according to the provided definitions

Kind: global function
Returns: Object - The parsed properties

Param Type Description
options Object Parser options
options.allowEmptySearch Boolean Avoid throwing when the search is empty
options.allowUnknownParams Boolean Avoid throwing when some params are unknown
options.allowDefault Boolean Avoid throwing when some params is set to its default value
options.allowUnorderedParams Boolean Avoid throwing when params are not set in the same order than declarations
definitions Array Swagger compatible list of defitions
search string The actual query string to parse

Example

import qs from 'strict-qs';

const qsOptions = { allowEmptySearch: true };
const qsDefinition = [{
  name: 'pages',
  in: 'query',
  type: 'array',
  items: {
    type: 'number',
  },
  ordered: true,
  description: 'The pages to print',
}];

qs(qsOptions, qsDefinition, '?pages=0&pages=1&pages=2');
// Returns:
// {
//  pages: [0, 1, 2], // eslint-disable-line
// }