index.js 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. import Vue from 'vue';
  2. export { use } from './use';
  3. export var isServer = Vue.prototype.$isServer;
  4. export function noop() {}
  5. export function isDef(value) {
  6. return value !== undefined && value !== null;
  7. }
  8. export function isObj(x) {
  9. var type = typeof x;
  10. return x !== null && (type === 'object' || type === 'function');
  11. }
  12. export function get(object, path) {
  13. var keys = path.split('.');
  14. var result = object;
  15. keys.forEach(function (key) {
  16. result = isDef(result[key]) ? result[key] : '';
  17. });
  18. return result;
  19. }
  20. var camelizeRE = /-(\w)/g;
  21. export function camelize(str) {
  22. return str.replace(camelizeRE, function (_, c) {
  23. return c.toUpperCase();
  24. });
  25. }
  26. export function isAndroid() {
  27. /* istanbul ignore next */
  28. return isServer ? false : /android/.test(navigator.userAgent.toLowerCase());
  29. }
  30. export function isIOS() {
  31. /* istanbul ignore next */
  32. return isServer ? false : /ios|iphone|ipad|ipod/.test(navigator.userAgent.toLowerCase());
  33. }
  34. export function range(num, min, max) {
  35. return Math.min(Math.max(num, min), max);
  36. }
  37. export function isInDocument(element) {
  38. return document.body.contains(element);
  39. }