This commit is contained in:
aihe 2024-07-18 00:03:41 +08:00
parent ff3b988850
commit 965f565060

View File

@ -179,6 +179,48 @@ const textDecoder = (input)=> {
return decodeURIComponent(escape(String.fromCharCode(...[input])));
}
const getQueryObject = (url)=> {
var query = url.split('?')[1];
var obj = {};
query = query.split('&');
query.forEach(query => {
var item = query.split('=');
obj[item[0]] = item[1]; // 当然如果有中文/Unicode字符可以在这里用URIencode方法转码一下
});
return obj;
}
export function isPlainObject(obj){
return typeof obj === 'object' && Object.prototype.toString.call(obj) === '[object Object]'
}
export function isPlainArray(obj){
return typeof obj === 'object' && Object.prototype.toString.call(obj) === '[object Array]'
}
export function deepAssign() {
let len = arguments.length, target = arguments[0]
if (!isPlainObject(target)) {
target = {}
}
for (let i = 1; i < len; i++) {
let source = arguments[i]
if (isPlainObject(source)) {
for (let s in source) {
if (s === '__proto__' || target === source[s]) {
continue
}
if (isPlainObject(source[s])) {
target[s] = deepAssign(target[s], source[s])
} else {
target[s] = source[s]
}
}
}
}
return target
}
export {
getAddressDetail,
@ -192,4 +234,5 @@ export {
throttle,
textEncoder,
textDecoder,
getQueryObject,
}