utils.js 763 B

1234567891011121314151617181920212223242526272829
  1. export function objectOrFunction(x) {
  2. let type = typeof x;
  3. return x !== null && (type === 'object' || type === 'function');
  4. }
  5. export function isFunction(x) {
  6. return typeof x === 'function';
  7. }
  8. export function isObject(x) {
  9. return x !== null && typeof x === 'object';
  10. }
  11. export function isMaybeThenable(x) {
  12. return x !== null && typeof x === 'object';
  13. }
  14. let _isArray;
  15. if (Array.isArray) {
  16. _isArray = Array.isArray;
  17. } else {
  18. _isArray = x => Object.prototype.toString.call(x) === '[object Array]';
  19. }
  20. export const isArray = _isArray;
  21. // Date.now is not available in browsers < IE9
  22. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/now#Compatibility
  23. export const now = Date.now || (() => new Date().getTime());