index.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. import Vue from 'vue';
  2. export { createNamespace } from './create';
  3. export { addUnit } from './format/unit';
  4. export var inBrowser = typeof window !== 'undefined';
  5. export var isServer = Vue.prototype.$isServer; // eslint-disable-next-line @typescript-eslint/no-empty-function
  6. export function noop() {}
  7. export function isDef(val) {
  8. return val !== undefined && val !== null;
  9. }
  10. export function isFunction(val) {
  11. return typeof val === 'function';
  12. }
  13. export function isObject(val) {
  14. return val !== null && typeof val === 'object';
  15. }
  16. export function isPromise(val) {
  17. return isObject(val) && isFunction(val.then) && isFunction(val.catch);
  18. }
  19. export function get(object, path) {
  20. var keys = path.split('.');
  21. var result = object;
  22. keys.forEach(function (key) {
  23. var _result$key;
  24. result = isObject(result) ? (_result$key = result[key]) != null ? _result$key : '' : '';
  25. });
  26. return result;
  27. }
  28. /**
  29. * Checks if `value` is an empty object, collection, map, or set.
  30. *
  31. * Objects are considered empty if they have no own enumerable string keyed
  32. * properties.
  33. *
  34. * Array-like values such as `arguments` objects, arrays, buffers, strings, or
  35. * jQuery-like collections are considered empty if they have a `length` of `0`.
  36. * Similarly, maps and sets are considered empty if they have a `size` of `0`.
  37. *
  38. * @function isEmpty
  39. * @param {*} value The value to check.
  40. * @returns {boolean} Returns `true` if `value` is empty, else `false`.
  41. * @example
  42. *
  43. * _.isEmpty(null);
  44. * // => true
  45. *
  46. * _.isEmpty(true);
  47. * // => true
  48. *
  49. * _.isEmpty(1);
  50. * // => true
  51. *
  52. * _.isEmpty([1, 2, 3]);
  53. * // => false
  54. *
  55. * _.isEmpty({ 'a': 1 });
  56. * // => false
  57. */
  58. export function isEmpty(value) {
  59. if (value == null) {
  60. return true;
  61. }
  62. if (typeof value !== 'object') {
  63. return true;
  64. }
  65. return Object.keys(value).length === 0;
  66. }