UNPKG

@iot9x.com/ipc-utils

Version:

九星云、九星小程序、九星配置工具所共用的库方法

57 lines (56 loc) 1.33 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); class RegularUtil { /** * 检测是否为空对象 * @param obj 目标对象 * @returns */ static isEmptyObject(obj) { return JSON.stringify(obj) === '{}'; } /** * 检测是否为空 * @param target */ static isEmpty(target) { return ((!target && target !== 0) || (this.isArray(target) && !target.length) || (this.isPlainObject(target) && !Object.keys(target).length)); } /** * 检测是否是数组 * @param arr 任何数据 * @returns */ static isArray(arr) { return Array.isArray(arr); } /** * 检测是否是字面量对象 * @param value 对象 * @returns */ static isPlainObject(value) { return Object.prototype.toString.call(value) === '[object Object]'; } /** * 检测是否为json字符串 * @param str json字符串 * @returns */ static isJSON(str) { if (typeof str === 'string') { try { JSON.parse(str); return true; } catch (e) { return false; } } else return false; } } exports.default = RegularUtil;