pax_global_header00006660000000000000000000000064142523762600014521gustar00rootroot0000000000000052 comment=68e8cc77bb1bbd0bf7d629d3574b6ca70289b2cc is-plain-obj-4.1.0/000077500000000000000000000000001425237626000140075ustar00rootroot00000000000000is-plain-obj-4.1.0/.editorconfig000066400000000000000000000002571425237626000164700ustar00rootroot00000000000000root = true [*] indent_style = tab end_of_line = lf charset = utf-8 trim_trailing_whitespace = true insert_final_newline = true [*.yml] indent_style = space indent_size = 2 is-plain-obj-4.1.0/.gitattributes000066400000000000000000000000231425237626000166750ustar00rootroot00000000000000* text=auto eol=lf is-plain-obj-4.1.0/.github/000077500000000000000000000000001425237626000153475ustar00rootroot00000000000000is-plain-obj-4.1.0/.github/funding.yml000066400000000000000000000001661425237626000175270ustar00rootroot00000000000000github: sindresorhus open_collective: sindresorhus tidelift: npm/is-plain-obj custom: https://sindresorhus.com/donate is-plain-obj-4.1.0/.github/security.md000066400000000000000000000002631425237626000175410ustar00rootroot00000000000000# Security Policy To report a security vulnerability, please use the [Tidelift security contact](https://tidelift.com/security). Tidelift will coordinate the fix and disclosure. is-plain-obj-4.1.0/.github/workflows/000077500000000000000000000000001425237626000174045ustar00rootroot00000000000000is-plain-obj-4.1.0/.github/workflows/main.yml000066400000000000000000000006451425237626000210600ustar00rootroot00000000000000name: CI on: - push - pull_request jobs: test: name: Node.js ${{ matrix.node-version }} runs-on: ubuntu-latest strategy: fail-fast: false matrix: node-version: - 14 - 12 steps: - uses: actions/checkout@v2 - uses: actions/setup-node@v2 with: node-version: ${{ matrix.node-version }} - run: npm install - run: npm test is-plain-obj-4.1.0/.gitignore000066400000000000000000000000271425237626000157760ustar00rootroot00000000000000node_modules yarn.lock is-plain-obj-4.1.0/.npmrc000066400000000000000000000000231425237626000151220ustar00rootroot00000000000000package-lock=false is-plain-obj-4.1.0/benchmark.js000066400000000000000000000022331425237626000162770ustar00rootroot00000000000000import {inspect} from 'node:util'; import {runInNewContext} from 'node:vm'; import isPlainObject from 'is-plain-obj'; const runBenchmarks = () => { for (const value of values) { const name = value instanceof Error ? String(Error) : inspect(value); const paddedName = name.padEnd(50); console.time(paddedName); runLoop(value); console.timeEnd(paddedName); } }; const runLoop = value => { for (let index = 0; index < 1e8; index += 1) { isPlainObject(value); } }; const values = [ undefined, 0, 0n, '', true, Symbol(''), () => {}, // eslint-disable-next-line func-names (function namedFunc() {}), null, {}, Math, new Set([]), new ArrayBuffer(0), Promise.resolve(), Object.create(null), new Intl.Locale('en'), // eslint-disable-next-line no-new-object new Object({prop: true}), new class Class {}(), [], /regexp/, new Error('test'), new Date(), (function () { // eslint-disable-next-line prefer-rest-params return arguments; })(), new Proxy({}, {}) ]; // Warm up V8 optimization. // Must go through every branch of the code, which requires using an object from a different realm. runLoop(runInNewContext('({})')); runBenchmarks(); is-plain-obj-4.1.0/index.d.ts000066400000000000000000000012411425237626000157060ustar00rootroot00000000000000/** 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 ``` 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 ``` */ export default function isPlainObject(value: unknown): value is Record; is-plain-obj-4.1.0/index.js000066400000000000000000000005301425237626000154520ustar00rootroot00000000000000export default function isPlainObject(value) { if (typeof value !== 'object' || value === null) { return false; } const prototype = Object.getPrototypeOf(value); return (prototype === null || prototype === Object.prototype || Object.getPrototypeOf(prototype) === null) && !(Symbol.toStringTag in value) && !(Symbol.iterator in value); } is-plain-obj-4.1.0/index.test-d.ts000066400000000000000000000005141425237626000166650ustar00rootroot00000000000000import {expectAssignable} from 'tsd'; import isPlainObject from './index.js'; const foo = 'foo'; if (isPlainObject(foo)) { expectAssignable>(foo); expectAssignable>(foo); expectAssignable>(foo); expectAssignable>(foo); } is-plain-obj-4.1.0/license000066400000000000000000000021351425237626000153550ustar00rootroot00000000000000MIT License Copyright (c) Sindre Sorhus (https://sindresorhus.com) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. is-plain-obj-4.1.0/package.json000066400000000000000000000013061425237626000162750ustar00rootroot00000000000000{ "name": "is-plain-obj", "version": "4.1.0", "description": "Check if a value is a plain object", "license": "MIT", "repository": "sindresorhus/is-plain-obj", "funding": "https://github.com/sponsors/sindresorhus", "author": { "name": "Sindre Sorhus", "email": "sindresorhus@gmail.com", "url": "https://sindresorhus.com" }, "type": "module", "exports": "./index.js", "engines": { "node": ">=12" }, "scripts": { "test": "xo && ava && tsd" }, "files": [ "index.js", "index.d.ts" ], "keywords": [ "object", "is", "check", "test", "type", "plain", "vanilla", "pure", "simple" ], "devDependencies": { "ava": "^3.15.0", "tsd": "^0.14.0", "xo": "^0.38.2" } } is-plain-obj-4.1.0/readme.md000066400000000000000000000023241425237626000155670ustar00rootroot00000000000000# is-plain-obj > Check if a value is a plain object An object is plain if it's created by either `{}`, `new Object()`, or `Object.create(null)`. ## Install ``` $ npm install is-plain-obj ``` ## Usage ```js 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 ``` ## Related - [is-obj](https://github.com/sindresorhus/is-obj) - Check if a value is an object - [is](https://github.com/sindresorhus/is) - Type check values ---
Get professional support for this package with a Tidelift subscription
Tidelift helps make open source sustainable for maintainers while giving companies
assurances about security, maintenance, and licensing for their dependencies.
is-plain-obj-4.1.0/test.js000066400000000000000000000024331425237626000153260ustar00rootroot00000000000000import {runInNewContext} from 'node:vm'; import test from 'ava'; import isPlainObject from './index.js'; function Foo(x) { this.x = x; } function ObjectConstructor() {} ObjectConstructor.prototype.constructor = Object; test('main', t => { t.true(isPlainObject({})); t.true(isPlainObject({foo: true})); t.true(isPlainObject({constructor: Foo})); t.true(isPlainObject({valueOf: 0})); t.true(isPlainObject(Object.create(null))); t.true(isPlainObject(new Object())); // eslint-disable-line no-new-object t.true(isPlainObject(runInNewContext('({})'))); t.false(isPlainObject(['foo', 'bar'])); t.false(isPlainObject(new Foo(1))); t.false(isPlainObject(Math)); t.false(isPlainObject(JSON)); t.false(isPlainObject(Atomics)); t.false(isPlainObject(Error)); t.false(isPlainObject(() => {})); t.false(isPlainObject(/./)); t.false(isPlainObject(null)); t.false(isPlainObject(undefined)); t.false(isPlainObject(Number.NaN)); t.false(isPlainObject('')); t.false(isPlainObject(0)); t.false(isPlainObject(false)); t.false(isPlainObject(new ObjectConstructor())); t.false(isPlainObject(Object.create({}))); (function () { t.false(isPlainObject(arguments)); // eslint-disable-line prefer-rest-params })(); const foo = new Foo(); foo.constructor = Object; t.false(isPlainObject(foo)); });