UNPKG

vue-simple

Version:

Use Vue in the simplest and easiest way, contain more than one of plugins and other to do that, i hope you will like it.

203 lines (180 loc) 5.33 kB
import _typeof from 'babel-runtime/helpers/typeof'; /** * @type {{all:Function}} */ import deepmerge from 'deepmerge'; /* global toString:true */ // utils is a library of generic helper functions non-specific to axios var toString = Object.prototype.toString; /** * 合并多个对象属性并返回合并后的新对象 * @param args 需要合并的对象,不能是 null 或 undefined * @returns {*} */ function merge() { for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { args[_key] = arguments[_key]; } return deepmerge.all([{}].concat(args)); } /** * 确定参数是否为 Array 数组类型 * * @param {Object} val The value to test * @returns {boolean} True if value is an Array, otherwise false */ function isArray(val) { return Array.isArray ? Array.isArray(val) : toString.call(val) === '[object Array]'; } /** * 确定参数是否为 ArrayBuffer 类型 * * @param {Object} val The value to test * @returns {boolean} True if value is an ArrayBuffer, otherwise false */ function isArrayBuffer(val) { return toString.call(val) === '[object ArrayBuffer]'; } /** * 确定参数是否为 FormData 表单数据对象类型 * * @param {Object} val The value to test * @returns {boolean} True if value is an FormData, otherwise false */ function isFormData(val) { return typeof FormData !== 'undefined' && val instanceof FormData; } /** * 确定参数是否为 ArrayBuffer 的 view 类型 * * @param {Object} val The value to test * @returns {boolean} True if value is a view on an ArrayBuffer, otherwise false */ function isArrayBufferView(val) { var result = void 0; if (typeof ArrayBuffer !== 'undefined' && ArrayBuffer.isView) { result = ArrayBuffer.isView(val); } else { result = val && val.buffer && val.buffer instanceof ArrayBuffer; } return result; } /** * 确定参数是否为 String 字符串类型 * * @param {Object} val The value to test * @returns {boolean} True if value is a String, otherwise false */ function isString(val) { return typeof val === 'string'; } /** * 确定参数是否为 Number 数值类型 * * @param {Object} val The value to test * @returns {boolean} True if value is a Number, otherwise false */ function isNumber(val) { return typeof val === 'number'; } /** * 确定参数是否为 undefined 类型 * * @param {Object} val The value to test * @returns {boolean} True if the value is undefined, otherwise false */ function isUndefined(val) { return typeof val === 'undefined'; } /** * 确定参数是否为 Object 对象类型 * * @param {Object} val The value to test * @returns {boolean} True if value is an Object, otherwise false */ function isObject(val) { return val !== null && (typeof val === 'undefined' ? 'undefined' : _typeof(val)) === 'object'; } /** * 确定参数是否为 Date 日期类型 * * @param {Object} val The value to test * @returns {boolean} True if value is a Date, otherwise false */ function isDate(val) { return toString.call(val) === '[object Date]'; } /** * 确定参数是否为 File 文件对象类型 * * @param {Object} val The value to test * @returns {boolean} True if value is a File, otherwise false */ function isFile(val) { return toString.call(val) === '[object File]'; } /** * 确定参数是否为 Blob 类型 * * @param {Object} val The value to test * @returns {boolean} True if value is a Blob, otherwise false */ function isBlob(val) { return toString.call(val) === '[object Blob]'; } /** * 确定参数是否为 Function 函数类型 * * @param {Object} val The value to test * @returns {boolean} True if value is a Function, otherwise false */ function isFunction(val) { return toString.call(val) === '[object Function]'; } /** * 确定参数是否为 Stream 对象 * * @param {Object} val The value to test * @returns {boolean} True if value is a Stream, otherwise false */ function isStream(val) { return isObject(val) && isFunction(val.pipe); } /** * 确定参数值是否为 URLSearchParams 对象 * * @param {Object} val The value to test * @returns {boolean} True if value is a URLSearchParams object, otherwise false */ function isURLSearchParams(val) { return typeof URLSearchParams !== 'undefined' && val instanceof URLSearchParams; } /** * 去除字符串前后的空白字符 * * @param {String} str The String to trim * @returns {String} The String freed of excess whitespace */ function trim(str) { return str.replace(/^\s*/, '').replace(/\s*$/, ''); } /** * 确定当前应用是否运行在标准浏览器环境中 * * This allows axios to run in a web worker, and react-native. * Both environments support XMLHttpRequest, but not fully standard globals. * * web workers: * typeof window -> undefined * typeof document -> undefined * * react-native: * navigator.product -> 'ReactNative' */ function isStandardBrowserEnv() { if (typeof navigator !== 'undefined' && navigator.product === 'ReactNative') { return false; } return typeof window !== 'undefined' && typeof document !== 'undefined'; } export { isArray, isArrayBuffer, isFormData, isArrayBufferView, isString, isNumber, isObject, isUndefined, isDate, isFile, isBlob, isFunction, isStream, isURLSearchParams, isStandardBrowserEnv, trim, merge };