Skip to content
This repository has been archived by the owner on Jun 1, 2020. It is now read-only.

yuheiy/format-url-query

Repository files navigation

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

About

Format the parsed URL query with default values.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published