is-plain-obj

  • Version 4.1.0
  • Published
  • 4.08 kB
  • No dependencies
  • MIT license

Install

npm i is-plain-obj
yarn add is-plain-obj
pnpm add is-plain-obj

Overview

Check if a value is a plain object

Index

Functions

function isPlainObject

isPlainObject: <Value>(value: unknown) => value is Record<PropertyKey, Value>;
  • Check if a value is a plain object.

    An object is plain if it's created by either {}, new Object(), or Object.create(null).

    Example 1

    import isPlainObject from 'is-plain-obj';
    import {runInNewContext} from 'node:vm';
    isPlainObject({foo: 'bar'});
    //=> true
    isPlainObject(new Object());
    //=> true
    isPlainObject(Object.create(null));
    //=> true
    // This works across realms
    isPlainObject(runInNewContext('({})'));
    //=> true
    isPlainObject([1, 2, 3]);
    //=> false
    class Unicorn {}
    isPlainObject(new Unicorn());
    //=> false
    isPlainObject(Math);
    //=> false

Package Files (1)

Dependencies (0)

No dependencies.

Dev Dependencies (3)

Peer Dependencies (0)

No peer dependencies.

Badge

To add a badge like this onejsDocs.io badgeto your package's README, use the codes available below.

You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/is-plain-obj.

  • Markdown
    [![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](https://www.jsdocs.io/package/is-plain-obj)
  • HTML
    <a href="https://www.jsdocs.io/package/is-plain-obj"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>