@wufengteam/wform
Version:
@wufengteam/wform
53 lines (52 loc) • 1.57 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.isJSONString = void 0;
exports.isNumer = isNumer;
exports.isPlainObject = isPlainObject;
exports.isString = isString;
exports.uniqueByProperty = uniqueByProperty;
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
/* eslint-disable no-underscore-dangle */
var _toString = Object.prototype.toString;
/**
* 判断是否是一个普通对象
* @param obj 任意值
* @returns boolean
*/
function isPlainObject(obj) {
return _toString.call(obj) === '[object Object]';
}
/**
* 判断是否json字符串
* @param str 任意值
* @returns boolean
*/
var isJSONString = exports.isJSONString = function isJSONString(str) {
if (typeof str === 'string') {
try {
var obj = JSON.parse(str);
if (_typeof(obj) === 'object' && obj) {
return true;
}
return false;
} catch (e) {
return false;
}
}
return false;
};
function isString(str) {
return _toString.call(str) === '[object String]';
}
function isNumer(value) {
return /^-?\d+(\.\d+)?([eE][-+]?\d+)?$/.test(value);
}
function uniqueByProperty(arr, prop) {
return arr.filter(function (obj, index, self) {
return index === self.findIndex(function (t) {
return t[prop] === obj[prop];
});
});
}