Format the parsed URL query with default values.
npm install @yuheiy/format-url-query
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'
}
*/
Returns an object of the same type as the format
.
Type: { [key: string]: string | string[] }
The object returned by querystring.parse()
.
Type: { [key: string]: string | string[] }
The format that is the return type and default values.
MIT © Yuhei Yasuda