@slan-health/taro-vueuse
Version:
taro vue版本hooks
63 lines (62 loc) • 1.55 kB
JavaScript
import { isRef } from "vue";
const objectToString = Object.prototype.toString;
const toTypeString = (val) => objectToString.call(val);
const isPlainObject = (val) => toTypeString(val) === "[object Object]";
const isArray = (val) => Array.isArray(val);
const isObject = (val) => val !== null && typeof val === "object";
const isFunction = (fn) => fn instanceof Function;
const isNil = (val) => val === null || val === void 0;
const resolvedPromise = () => new Promise(() => {
});
const get = (source, path, defaultValue = void 0) => {
const paths = path.replace(/\[(\d+)\]/g, ".$1").split(".");
let result = source;
for (const p of paths) {
result = Object(result)[p];
if (result === void 0) {
return defaultValue;
}
}
return result;
};
function omit(object, keys) {
const result = Object.assign({}, object);
for (const key of keys) {
delete result[key];
}
return result;
}
const warning = (message, throwError = false) => {
const msg = `Warning: [vue-request] ${message}`;
if (throwError) {
return new Error(msg);
} else {
console.error(msg);
}
};
const refToRaw = (value) => {
return isRef(value) ? value.value : value;
};
const shallowCopy = (value) => {
if (isObject(value)) {
return Object.assign(isArray(value) ? [] : {}, value);
} else {
return value;
}
};
export {
get,
isArray,
isFunction,
isNil,
isObject,
isPlainObject,
objectToString,
omit,
refToRaw,
resolvedPromise,
shallowCopy,
toTypeString,
warning
};
//# sourceMappingURL=index.js.map