@yuheiy/format-url-query
TypeScript icon, indicating that this package has built-in type declarations

0.0.2 • Public • Published

format-url-query Build Status

Format the parsed URL query with default values.

Install

npm install @yuheiy/format-url-query

Usage

const formatUrlQuery = require('@yuheiy/format-url-query')
const { parse } = require('querystring')

formatUrlQuery(parse('tag=html&debug=1'), {
  tag: 'all',
  page: '1',
})
/*
{
  tag: 'html',
  page: '1'
}
*/

formatUrlQuery(parse('tag=html&tag=css&debug=1'), {
  tag: 'all',
  page: '1',
})
/*
{
  tag: 'html',
  page: '1'
}
*/

formatUrlQuery(parse('tag=html&tag=css&debug=1'), {
  tag: [],
  page: '1',
})
/*
{
  tag: ['html', 'css'],
  page: '1'
}
*/

formatUrlQuery(parse('tag=html&tag=css&debug=1'), {
  tag: ['html', 'css', 'javascript'],
  page: '1',
})
/*
{
  tag: ['html', 'css'],
  page: '1'
}
*/

API

formatUrlQuery(parsedUrlQuery, format)

Returns an object of the same type as the format.

parsedUrlQuery

Type: { [key: string]: string | string[] }

The object returned by querystring.parse().

format

Type: { [key: string]: string | string[] }

The format that is the return type and default values.

License

MIT © Yuhei Yasuda

Readme

Keywords

none

Package Sidebar

Install

npm i @yuheiy/format-url-query

Weekly Downloads

1

Version

0.0.2

License

MIT

Unpacked Size

5.5 kB

Total Files

5

Last publish

Collaborators

  • yuheiy