123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131 |
- 'use strict'
- const { toString } = Object.prototype
- export function isArray(val) {
- return toString.call(val) === '[object Array]'
- }
- export function isObject(val) {
- return val !== null && typeof val === 'object'
- }
- export function isDate(val) {
- return toString.call(val) === '[object Date]'
- }
- export function isURLSearchParams(val) {
- return typeof URLSearchParams !== 'undefined' && val instanceof URLSearchParams
- }
- export function forEach(obj, fn) {
-
- if (obj === null || typeof obj === 'undefined') {
- return
- }
-
- if (typeof obj !== 'object') {
-
- obj = [obj]
- }
- if (isArray(obj)) {
-
- for (let i = 0, l = obj.length; i < l; i++) {
- fn.call(null, obj[i], i, obj)
- }
- } else {
-
- for (const key in obj) {
- if (Object.prototype.hasOwnProperty.call(obj, key)) {
- fn.call(null, obj[key], key, obj)
- }
- }
- }
- }
- export function isBoolean(val) {
- return typeof val === 'boolean'
- }
- export function isPlainObject(obj) {
- return Object.prototype.toString.call(obj) === '[object Object]'
- }
- export function deepMerge(/* obj1, obj2, obj3, ... */) {
- const 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
- }
- export function isUndefined(val) {
- return typeof val === 'undefined'
- }
|