UNPKG

chowa

Version:

UI component library based on React

96 lines (95 loc) 2.83 kB
/** * @license chowa v1.1.3 * * Copyright (c) Chowa Techonlogies Co.,Ltd.(http://www.chowa.cn). * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const moment = require("moment"); function hasProperty(obj, property) { if (obj === undefined || obj === null) { return false; } return Object.prototype.hasOwnProperty.call(obj, property); } exports.hasProperty = hasProperty; function isReactElement(ele) { if (hasProperty(ele, '$$typeof') && ele.$$typeof === Symbol.for('react.element')) { return true; } return false; } exports.isReactElement = isReactElement; function isEqual(a, b) { if (a === b) { return true; } if (typeof a === 'object' && typeof b === 'object') { if (a === null || b === null) { return a === b; } else if (isReactElement(a) && isReactElement(b)) { return isEqual(a.props, b.props); } else if (a instanceof Date && b instanceof Date) { return +a === +b; } else if (a instanceof RegExp && b instanceof RegExp) { return a.toString() === b.toString(); } else if (Array.isArray(a) && Array.isArray(b)) { const arrLen = a.length; if (arrLen !== b.length) { return false; } for (let i = arrLen; i--; i !== 0) { if (!isEqual(a[i], b[i])) { return false; } } return true; } else { const keys = Object.keys(a); const objLen = keys.length; if (objLen !== Object.keys(b).length) { return false; } for (let i = objLen; i--; i !== 0) { if (!hasProperty(b, keys[i])) { return false; } } for (let i = objLen; i--; i !== 0) { const key = keys[i]; if (!isEqual(a[key], b[key])) { return false; } } } } return a !== a && b !== b; } exports.isEqual = isEqual; function isSameMoment(a, b, granularity = 'second') { if (moment.isMoment(a) && moment.isMoment(b)) { return a.isSame(b, granularity); } return a === b; } exports.isSameMoment = isSameMoment; function isExist(a) { if (a === undefined || a === null || a === '' || (typeof a === 'object' && Object.keys(a).length === 0) || (typeof a === 'number' && isNaN(a)) || /^\s+$/.test(a)) { return false; } return true; } exports.isExist = isExist;