UNPKG

t-comm

Version:

专业、稳定、纯粹的工具库

105 lines (98 loc) 2.51 kB
'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); var _typeof = require('@babel/runtime/helpers/typeof'); function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; } var _typeof__default = /*#__PURE__*/_interopDefaultLegacy(_typeof); /** * 判断数据是不是正则对象 * @param {any} value - 输入数据 * @returns {boolean} 是否是正则对象 * * @example * * isRegExp(1) * * // => false * * isRegExp(/\d/) * * // => true */ function isRegExp(value) { return Object.prototype.toString.call(value) === '[object RegExp]'; } /** * 判断数据是不是时间对象 * @param {any} value - 输入数据 * @returns {boolean} 是否是时间对象 * * @example * * isDate(1) * * // => false * * isDate(new Date()) * * // => true */ function isDate(value) { return Object.prototype.toString.call(value) === '[object Date]'; } /** * 判断数据是不是函数 * @param {any} value - 输入数据 * @returns {boolean} 是否是函数 * * @example * * isFunction(1) * * // => false * * isFunction(()=>{}) * * // => true */ function isFunction(value) { // typeof val === 'function' // 也可以 return Object.prototype.toString.call(value) === '[object Function]'; } function isPlainObject(val) { return val !== null && _typeof__default["default"](val) === 'object' && !Array.isArray(val); } function isPromise(val) { return isPlainObject(val) && isFunction(val.then) && isFunction(val["catch"]); } function isDef(value) { return value !== undefined && value !== null; } function isObj(x) { var type = _typeof__default["default"](x); return x !== null && (type === 'object' || type === 'function'); } function isObject(val) { return val !== null && _typeof__default["default"](val) === 'object'; } var IMAGE_REGEXP = /\.(jpeg|jpg|gif|png|svg|webp|jfif|bmp|dpg)/i; var VIDEO_REGEXP = /\.(mp4|mpg|mpeg|dat|asf|avi|rm|rmvb|mov|wmv|flv|mkv)/i; function isImageUrl(url) { return IMAGE_REGEXP.test(url); } function isVideoUrl(url) { return VIDEO_REGEXP.test(url); } function isNumber(value) { return /^\d+(\.\d+)?$/.test(value); } exports.isDate = isDate; exports.isDef = isDef; exports.isFunction = isFunction; exports.isImageUrl = isImageUrl; exports.isNumber = isNumber; exports.isObj = isObj; exports.isObject = isObject; exports.isPlainObject = isPlainObject; exports.isPromise = isPromise; exports.isRegExp = isRegExp; exports.isVideoUrl = isVideoUrl;