index.js 2.3 KB

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