first commit
This commit is contained in:
63
unpackage/dist/dev/mp-weixin/request/luch-request/utils.js
vendored
Normal file
63
unpackage/dist/dev/mp-weixin/request/luch-request/utils.js
vendored
Normal file
@@ -0,0 +1,63 @@
|
||||
"use strict";
|
||||
var toString = Object.prototype.toString;
|
||||
function isArray(val) {
|
||||
return toString.call(val) === "[object Array]";
|
||||
}
|
||||
function isObject(val) {
|
||||
return val !== null && typeof val === "object";
|
||||
}
|
||||
function isDate(val) {
|
||||
return toString.call(val) === "[object Date]";
|
||||
}
|
||||
function isURLSearchParams(val) {
|
||||
return typeof URLSearchParams !== "undefined" && val instanceof URLSearchParams;
|
||||
}
|
||||
function forEach(obj, fn) {
|
||||
if (obj === null || typeof obj === "undefined") {
|
||||
return;
|
||||
}
|
||||
if (typeof obj !== "object") {
|
||||
obj = [obj];
|
||||
}
|
||||
if (isArray(obj)) {
|
||||
for (var i = 0, l = obj.length; i < l; i++) {
|
||||
fn.call(null, obj[i], i, obj);
|
||||
}
|
||||
} else {
|
||||
for (var key in obj) {
|
||||
if (Object.prototype.hasOwnProperty.call(obj, key)) {
|
||||
fn.call(null, obj[key], key, obj);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
function isPlainObject(obj) {
|
||||
return Object.prototype.toString.call(obj) === "[object Object]";
|
||||
}
|
||||
function deepMerge() {
|
||||
let result = {};
|
||||
function assignValue(val, key) {
|
||||
if (typeof result[key] === "object" && typeof val === "object") {
|
||||
result[key] = deepMerge(result[key], val);
|
||||
} else if (typeof val === "object") {
|
||||
result[key] = deepMerge({}, val);
|
||||
} else {
|
||||
result[key] = val;
|
||||
}
|
||||
}
|
||||
for (let i = 0, l = arguments.length; i < l; i++) {
|
||||
forEach(arguments[i], assignValue);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
function isUndefined(val) {
|
||||
return typeof val === "undefined";
|
||||
}
|
||||
exports.deepMerge = deepMerge;
|
||||
exports.forEach = forEach;
|
||||
exports.isArray = isArray;
|
||||
exports.isDate = isDate;
|
||||
exports.isObject = isObject;
|
||||
exports.isPlainObject = isPlainObject;
|
||||
exports.isURLSearchParams = isURLSearchParams;
|
||||
exports.isUndefined = isUndefined;
|
||||
Reference in New Issue
Block a user