format-url-query
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',
})
formatUrlQuery(parse('tag=html&tag=css&debug=1'), {
tag: 'all',
page: '1',
})
formatUrlQuery(parse('tag=html&tag=css&debug=1'), {
tag: [],
page: '1',
})
formatUrlQuery(parse('tag=html&tag=css&debug=1'), {
tag: ['html', 'css', 'javascript'],
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