vant/packages/utils/index.js
2019-01-06 23:08:14 +08:00

50 lines
890 B
JavaScript

import Vue from 'vue';
import use from './use';
const isServer = Vue.prototype.$isServer;
function isDef(value) {
return value !== undefined && value !== null;
}
function isObj(x) {
const type = typeof x;
return x !== null && (type === 'object' || type === 'function');
}
function get(object, path) {
const keys = path.split('.');
let result = object;
keys.forEach(key => {
result = isDef(result[key]) ? result[key] : '';
});
return result;
}
const camelizeRE = /-(\w)/g;
function camelize(str) {
return str.replace(camelizeRE, (_, c) => c.toUpperCase());
}
function isAndroid() {
/* istanbul ignore next */
return isServer ? false : /android/.test(navigator.userAgent.toLowerCase());
}
function range(num, min, max) {
return Math.min(Math.max(num, min), max);
}
export {
use,
get,
range,
isObj,
isDef,
isServer,
camelize,
isAndroid
};