Home Reference Source Test

src/predicates/isPlainObject.ts

  1. import { isRecord } from '../objects';
  2. import { Predicate } from './Predicate';
  3.  
  4. /**
  5. * @desc
  6. * Ensures that the `value` is a plain {@link Object}.
  7. * Based on Jon Schlinkert's implementation.
  8. *
  9. * @see https://github.com/jonschlinkert/is-plain-object
  10. *
  11. * @example
  12. * import { ensure, isPlainObject } from 'tiny-types';
  13. *
  14. * ensure('plain object', {}, isPlainObject());
  15. *
  16. * @returns {Predicate<string>}
  17. */
  18. export function isPlainObject<T extends object = object>(): Predicate<T> {
  19. return Predicate.to(`be a plain object`, (value: T) => isRecord(value));
  20. }