is.js 1.4 KB

123456789101112131415161718192021222324252627
  1. var _a;
  2. export const isClient = typeof window !== 'undefined';
  3. export const isDef = val => typeof val !== 'undefined';
  4. export const assert = function (condition) {
  5. for (var _len = arguments.length, infos = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
  6. infos[_key - 1] = arguments[_key];
  7. }
  8. if (!condition) console.warn(...infos);
  9. };
  10. const toString = Object.prototype.toString;
  11. export const isBoolean = val => typeof val === 'boolean';
  12. export const isFunction = val => typeof val === 'function';
  13. export const isNumber = val => typeof val === 'number';
  14. export const isString = val => typeof val === 'string';
  15. export const isObject = val => toString.call(val) === '[object Object]';
  16. export const isWindow = val => typeof window !== 'undefined' && toString.call(val) === '[object Window]';
  17. export const now = () => Date.now();
  18. export const timestamp = () => +Date.now();
  19. export const clamp = (n, min, max) => Math.min(max, Math.max(min, n));
  20. export const noop = () => {};
  21. export const rand = (min, max) => {
  22. min = Math.ceil(min);
  23. max = Math.floor(max);
  24. return Math.floor(Math.random() * (max - min + 1)) + min;
  25. };
  26. export const isIOS = isClient && ((_a = window === null || window === void 0 ? void 0 : window.navigator) === null || _a === void 0 ? void 0 : _a.userAgent) && /iP(ad|hone|od)/.test(window.navigator.userAgent);
  27. export const hasOwn = (val, key) => Object.prototype.hasOwnProperty.call(val, key);