@deepjs/qs
v0.2.9
Published
qs for url query-string
Downloads
19
Maintainers
Readme
qs
处理 url query-string 等功能
独立包,无依赖,语义化,使用简单
功能列表
- clone
- alias:
deepClone
copy
deepCopy
- alias:
- urlfix
- parse
- stringify
- compact 0.1.1 计划废弃,可使用 filter 替代
- compactObject 0.1.1 计划废弃,可使用 reduce 替代
- decodeQuery
const invalid = ['', undefined, null];
const arr = [1, 'test', '', 0, -0, +0, undefined, false, null, NaN];
// compact
const temp1 = compact(arr, invalid)
const temp2 = arr.filter(v => !invalid.includes(v))
const obj = { utm_source: 'baidu', utm_medium: '', spm: 'alipay' }
const utmKeys = ['utm_source', 'utm_medium']
// compactObject
const temp3 = compactObject(obj, invalid)
const allowedKeys = { utm_source: true, utm_medium: true }
const temp4 = Object.keys[obj].reduce((o, key) => {
if (allowedKeys(key) && typeof obj[key] !== 'undefined') {
o[key] = obj[key];
}
return o;
}, {})
使用
import { clone, stringify } from '@deepjs/qs'
const obj = {a: 1, b: 0, c: null};
console.log(clone(obj))
console.log(stringify(obj))