is.js 999 B

123456789101112131415161718192021222324252627282930313233
  1. import _curry2 from "./internal/_curry2.js";
  2. /**
  3. * See if an object (i.e. `val`) is an instance of the supplied constructor. This
  4. * function will check up the inheritance chain, if any.
  5. * If `val` was created using `Object.create`, `R.is(Object, val) === true`.
  6. *
  7. * @func
  8. * @memberOf R
  9. * @since v0.3.0
  10. * @category Type
  11. * @sig (* -> {*}) -> a -> Boolean
  12. * @param {Object} ctor A constructor
  13. * @param {*} val The value to test
  14. * @return {Boolean}
  15. * @example
  16. *
  17. * R.is(Object, {}); //=> true
  18. * R.is(Number, 1); //=> true
  19. * R.is(Object, 1); //=> false
  20. * R.is(String, 's'); //=> true
  21. * R.is(String, new String('')); //=> true
  22. * R.is(Object, new String('')); //=> true
  23. * R.is(Object, 's'); //=> false
  24. * R.is(Number, {}); //=> false
  25. */
  26. var is =
  27. /*#__PURE__*/
  28. _curry2(function is(Ctor, val) {
  29. return val instanceof Ctor || val != null && (val.constructor === Ctor || Ctor.name === 'Object' && typeof val === 'object');
  30. });
  31. export default is;