UNPKG

@hsui/core

Version:

Hundsun frontend runtime core framework

87 lines (77 loc) 1.92 kB
import _typeof from "@babel/runtime/helpers/esm/typeof"; /** * Native isArray */ export var isArray = Array.isArray; /** * Underscore isFunction */ export function isFunction(value) { return Object.prototype.toString.call(value) === '[object Function]'; } /** * Redux isPlainObject */ export function isPlainObject(obj) { if (_typeof(obj) !== 'object' || obj === null) return false; var proto = obj; while (Object.getPrototypeOf(proto) !== null) { proto = Object.getPrototypeOf(proto); } return Object.getPrototypeOf(obj) === proto; } /** * Check if powered by HUI Micro App */ export function isMicroApp() { return Boolean(window.__POWERED_BY_HUI_MICRO_APP__); } /** * simple generate uuid * 支持 ie10 及以上 * 基于 uuid v4 添加 performance.now 避免重复 */ export function uuid() { var d = Date.now(); if (typeof performance !== 'undefined' && typeof performance.now === 'function') { d += performance.now(); //use high-precision timer if available } return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) { var r = (d + Math.random() * 16) % 16 | 0; d = Math.floor(d / 16); return (c === 'x' ? r : r & 0x3 | 0x8).toString(16); }); } /** * Underscore uniqueId */ var idCounter = 0; export function uniqueId(prefix) { var id = ++idCounter + ''; return prefix ? prefix + id : id; } /** * Native extend */ export var extend = Object.assign; /** * Lodash isObject */ export function isObject(value) { var type = _typeof(value); return value != null && (type == 'object' || type == 'function'); } /** * Underscore clone */ export function clone(value) { if (!isObject(value)) return value; if (typeof value === 'function') return value; return isArray(value) ? value.slice() : extend({}, value); } /** * DeepClone */ export function deepClone(value) { return JSON.parse(JSON.stringify(value)); }