├── .editorconfig ├── .eslintrc.json ├── .gitattributes ├── .gitignore ├── .travis.yml ├── LICENSE ├── README.md ├── is-plain-object.d.ts ├── is-plain-object.js ├── package.json ├── rollup.config.js └── test ├── browser-iframe.html ├── browser.html └── server.js /.editorconfig: -------------------------------------------------------------------------------- 1 | # http://editorconfig.org/ 2 | root = true 3 | 4 | [*] 5 | charset = utf-8 6 | end_of_line = lf 7 | indent_size = 2 8 | indent_style = space 9 | insert_final_newline = true 10 | trim_trailing_whitespace = true 11 | 12 | [{**/{actual,fixtures,expected,templates}/**,*.md}] 13 | trim_trailing_whitespace = false 14 | insert_final_newline = false 15 | -------------------------------------------------------------------------------- /.eslintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "env": { 3 | "browser": false, 4 | "es6": true, 5 | "node": true, 6 | "mocha": true 7 | }, 8 | 9 | "globals": { 10 | "document": false, 11 | "navigator": false, 12 | "window": false 13 | }, 14 | 15 | "rules": { 16 | "accessor-pairs": 2, 17 | "arrow-spacing": [2, { "before": true, "after": true }], 18 | "block-spacing": [2, "always"], 19 | "brace-style": [2, "1tbs", { "allowSingleLine": true }], 20 | "comma-dangle": [2, "never"], 21 | "comma-spacing": [2, { "before": false, "after": true }], 22 | "comma-style": [2, "last"], 23 | "constructor-super": 2, 24 | "curly": [2, "multi-line"], 25 | "dot-location": [2, "property"], 26 | "eol-last": 2, 27 | "eqeqeq": [2, "allow-null"], 28 | "generator-star-spacing": [2, { "before": true, "after": true }], 29 | "handle-callback-err": [2, "^(err|error)$" ], 30 | "indent": [2, 2, { "SwitchCase": 1 }], 31 | "key-spacing": [2, { "beforeColon": false, "afterColon": true }], 32 | "keyword-spacing": [2, { "before": true, "after": true }], 33 | "new-cap": [2, { "newIsCap": true, "capIsNew": false }], 34 | "new-parens": 2, 35 | "no-array-constructor": 2, 36 | "no-caller": 2, 37 | "no-class-assign": 2, 38 | "no-cond-assign": 2, 39 | "no-const-assign": 2, 40 | "no-control-regex": 2, 41 | "no-debugger": 2, 42 | "no-delete-var": 2, 43 | "no-dupe-args": 2, 44 | "no-dupe-class-members": 2, 45 | "no-dupe-keys": 2, 46 | "no-duplicate-case": 2, 47 | "no-empty-character-class": 2, 48 | "no-eval": 2, 49 | "no-ex-assign": 2, 50 | "no-extend-native": 2, 51 | "no-extra-bind": 2, 52 | "no-extra-boolean-cast": 2, 53 | "no-extra-parens": [2, "functions"], 54 | "no-fallthrough": 2, 55 | "no-floating-decimal": 2, 56 | "no-func-assign": 2, 57 | "no-implied-eval": 2, 58 | "no-inner-declarations": [2, "functions"], 59 | "no-invalid-regexp": 2, 60 | "no-irregular-whitespace": 2, 61 | "no-iterator": 2, 62 | "no-label-var": 2, 63 | "no-labels": 2, 64 | "no-lone-blocks": 2, 65 | "no-mixed-spaces-and-tabs": 2, 66 | "no-multi-spaces": 2, 67 | "no-multi-str": 2, 68 | "no-multiple-empty-lines": [2, { "max": 1 }], 69 | "no-native-reassign": 0, 70 | "no-negated-in-lhs": 2, 71 | "no-new": 2, 72 | "no-new-func": 2, 73 | "no-new-object": 2, 74 | "no-new-require": 2, 75 | "no-new-wrappers": 2, 76 | "no-obj-calls": 2, 77 | "no-octal": 2, 78 | "no-octal-escape": 2, 79 | "no-proto": 0, 80 | "no-redeclare": 2, 81 | "no-regex-spaces": 2, 82 | "no-return-assign": 2, 83 | "no-self-compare": 2, 84 | "no-sequences": 2, 85 | "no-shadow-restricted-names": 2, 86 | "no-spaced-func": 2, 87 | "no-sparse-arrays": 2, 88 | "no-this-before-super": 2, 89 | "no-throw-literal": 2, 90 | "no-trailing-spaces": 0, 91 | "no-undef": 2, 92 | "no-undef-init": 2, 93 | "no-unexpected-multiline": 2, 94 | "no-unneeded-ternary": [2, { "defaultAssignment": false }], 95 | "no-unreachable": 2, 96 | "no-unused-vars": [2, { "vars": "all", "args": "none" }], 97 | "no-useless-call": 0, 98 | "no-with": 2, 99 | "one-var": [0, { "initialized": "never" }], 100 | "operator-linebreak": [0, "after", { "overrides": { "?": "before", ":": "before" } }], 101 | "padded-blocks": [0, "never"], 102 | "quotes": [2, "single", "avoid-escape"], 103 | "radix": 2, 104 | "semi": [2, "always"], 105 | "semi-spacing": [2, { "before": false, "after": true }], 106 | "space-before-blocks": [2, "always"], 107 | "space-before-function-paren": [2, "never"], 108 | "space-in-parens": [2, "never"], 109 | "space-infix-ops": 2, 110 | "space-unary-ops": [2, { "words": true, "nonwords": false }], 111 | "spaced-comment": [0, "always", { "markers": ["global", "globals", "eslint", "eslint-disable", "*package", "!", ","] }], 112 | "use-isnan": 2, 113 | "valid-typeof": 2, 114 | "wrap-iife": [2, "any"], 115 | "yoda": [2, "never"] 116 | } 117 | } 118 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Enforce Unix newlines 2 | * text eol=lf 3 | 4 | # binaries 5 | *.ai binary 6 | *.psd binary 7 | *.jpg binary 8 | *.gif binary 9 | *.png binary 10 | *.jpeg binary -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # always ignore files 2 | *.DS_Store 3 | *.sublime-* 4 | 5 | # test related, or directories generated by tests 6 | test/actual 7 | actual 8 | coverage 9 | .nyc* 10 | 11 | # npm 12 | node_modules 13 | npm-debug.log 14 | 15 | # yarn 16 | yarn.lock 17 | yarn-error.log 18 | 19 | # misc 20 | _gh_pages 21 | _draft 22 | _drafts 23 | bower_components 24 | vendor 25 | temp 26 | tmp 27 | TODO.md 28 | package-lock.json 29 | browser 30 | dist 31 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | sudo: false 2 | os: 3 | - linux 4 | - osx 5 | language: node_js 6 | node_js: 7 | - node 8 | - '14' 9 | - '12' 10 | - '10' 11 | git: 12 | depth: 10 13 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014-2017, Jon Schlinkert. 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # is-plain-object [![NPM version](https://img.shields.io/npm/v/is-plain-object.svg?style=flat)](https://www.npmjs.com/package/is-plain-object) [![NPM monthly downloads](https://img.shields.io/npm/dm/is-plain-object.svg?style=flat)](https://npmjs.org/package/is-plain-object) [![NPM total downloads](https://img.shields.io/npm/dt/is-plain-object.svg?style=flat)](https://npmjs.org/package/is-plain-object) [![Linux Build Status](https://img.shields.io/travis/jonschlinkert/is-plain-object.svg?style=flat&label=Travis)](https://travis-ci.org/jonschlinkert/is-plain-object) 2 | 3 | > Returns true if an object was created by the `Object` constructor, or Object.create(null). 4 | 5 | Please consider following this project's author, [Jon Schlinkert](https://github.com/jonschlinkert), and consider starring the project to show your :heart: and support. 6 | 7 | ## Install 8 | 9 | Install with [npm](https://www.npmjs.com/): 10 | 11 | ```sh 12 | $ npm install --save is-plain-object 13 | ``` 14 | 15 | Use [isobject](https://github.com/jonschlinkert/isobject) if you only want to check if the value is an object and not an array or null. 16 | 17 | ## Usage 18 | 19 | with es modules 20 | ```js 21 | import { isPlainObject } from 'is-plain-object'; 22 | ``` 23 | 24 | or with commonjs 25 | ```js 26 | const { isPlainObject } = require('is-plain-object'); 27 | ``` 28 | 29 | **true** when created by the `Object` constructor, or Object.create(null). 30 | 31 | ```js 32 | isPlainObject(Object.create({})); 33 | //=> true 34 | isPlainObject(Object.create(Object.prototype)); 35 | //=> true 36 | isPlainObject({foo: 'bar'}); 37 | //=> true 38 | isPlainObject({}); 39 | //=> true 40 | isPlainObject(null); 41 | //=> true 42 | ``` 43 | 44 | **false** when not created by the `Object` constructor. 45 | 46 | ```js 47 | isPlainObject(1); 48 | //=> false 49 | isPlainObject(['foo', 'bar']); 50 | //=> false 51 | isPlainObject([]); 52 | //=> false 53 | isPlainObject(new Foo); 54 | //=> false 55 | isPlainObject(Object.create(null)); 56 | //=> false 57 | ``` 58 | 59 | ## About 60 | 61 |
62 | Contributing 63 | 64 | Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](../../issues/new). 65 | 66 |
67 | 68 |
69 | Running Tests 70 | 71 | Running and reviewing unit tests is a great way to get familiarized with a library and its API. You can install dependencies and run tests with the following command: 72 | 73 | ```sh 74 | $ npm install && npm test 75 | ``` 76 | 77 |
78 | 79 |
80 | Building docs 81 | 82 | _(This project's readme.md is generated by [verb](https://github.com/verbose/verb-generate-readme), please don't edit the readme directly. Any changes to the readme must be made in the [.verb.md](.verb.md) readme template.)_ 83 | 84 | To generate the readme, run the following command: 85 | 86 | ```sh 87 | $ npm install -g verbose/verb#dev verb-generate-readme && verb 88 | ``` 89 | 90 |
91 | 92 | ### Related projects 93 | 94 | You might also be interested in these projects: 95 | 96 | * [is-number](https://www.npmjs.com/package/is-number): Returns true if a number or string value is a finite number. Useful for regex… [more](https://github.com/jonschlinkert/is-number) | [homepage](https://github.com/jonschlinkert/is-number "Returns true if a number or string value is a finite number. Useful for regex matches, parsing, user input, etc.") 97 | * [isobject](https://www.npmjs.com/package/isobject): Returns true if the value is an object and not an array or null. | [homepage](https://github.com/jonschlinkert/isobject "Returns true if the value is an object and not an array or null.") 98 | * [kind-of](https://www.npmjs.com/package/kind-of): Get the native type of a value. | [homepage](https://github.com/jonschlinkert/kind-of "Get the native type of a value.") 99 | 100 | ### Contributors 101 | 102 | | **Commits** | **Contributor** | 103 | | --- | --- | 104 | | 19 | [jonschlinkert](https://github.com/jonschlinkert) | 105 | | 6 | [TrySound](https://github.com/TrySound) | 106 | | 6 | [stevenvachon](https://github.com/stevenvachon) | 107 | | 3 | [onokumus](https://github.com/onokumus) | 108 | | 1 | [wtgtybhertgeghgtwtg](https://github.com/wtgtybhertgeghgtwtg) | 109 | 110 | ### Author 111 | 112 | **Jon Schlinkert** 113 | 114 | * [GitHub Profile](https://github.com/jonschlinkert) 115 | * [Twitter Profile](https://twitter.com/jonschlinkert) 116 | * [LinkedIn Profile](https://linkedin.com/in/jonschlinkert) 117 | 118 | ### License 119 | 120 | Copyright © 2019, [Jon Schlinkert](https://github.com/jonschlinkert). 121 | Released under the [MIT License](LICENSE). 122 | 123 | *** 124 | 125 | _This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.8.0, on April 28, 2019._ 126 | -------------------------------------------------------------------------------- /is-plain-object.d.ts: -------------------------------------------------------------------------------- 1 | export function isPlainObject(o: any): boolean; 2 | -------------------------------------------------------------------------------- /is-plain-object.js: -------------------------------------------------------------------------------- 1 | /*! 2 | * is-plain-object 3 | * 4 | * Copyright (c) 2014-2017, Jon Schlinkert. 5 | * Released under the MIT License. 6 | */ 7 | 8 | function isObject(o) { 9 | return Object.prototype.toString.call(o) === '[object Object]'; 10 | } 11 | 12 | export function isPlainObject(o) { 13 | var ctor,prot; 14 | 15 | if (isObject(o) === false) return false; 16 | 17 | // If has modified constructor 18 | ctor = o.constructor; 19 | if (ctor === undefined) return true; 20 | 21 | // If has modified prototype 22 | prot = ctor.prototype; 23 | if (isObject(prot) === false) return false; 24 | 25 | // If constructor does not have an Object-specific method 26 | if (prot.hasOwnProperty('isPrototypeOf') === false) { 27 | return false; 28 | } 29 | 30 | // Most likely a plain Object 31 | return true; 32 | }; 33 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "is-plain-object", 3 | "description": "Returns true if an object was created by the `Object` constructor, or Object.create(null).", 4 | "version": "5.0.0", 5 | "homepage": "https://github.com/jonschlinkert/is-plain-object", 6 | "author": "Jon Schlinkert (https://github.com/jonschlinkert)", 7 | "contributors": [ 8 | "Jon Schlinkert (http://twitter.com/jonschlinkert)", 9 | "Osman Nuri Okumuş (http://onokumus.com)", 10 | "Steven Vachon (https://svachon.com)", 11 | "(https://github.com/wtgtybhertgeghgtwtg)", 12 | "Bogdan Chadkin (https://github.com/TrySound)" 13 | ], 14 | "repository": "jonschlinkert/is-plain-object", 15 | "bugs": { 16 | "url": "https://github.com/jonschlinkert/is-plain-object/issues" 17 | }, 18 | "license": "MIT", 19 | "main": "dist/is-plain-object.js", 20 | "module": "dist/is-plain-object.mjs", 21 | "types": "is-plain-object.d.ts", 22 | "files": [ 23 | "is-plain-object.d.ts", 24 | "dist" 25 | ], 26 | "exports": { 27 | ".": { 28 | "import": "./dist/is-plain-object.mjs", 29 | "require": "./dist/is-plain-object.js" 30 | }, 31 | "./package.json": "./package.json" 32 | }, 33 | "engines": { 34 | "node": ">=0.10.0" 35 | }, 36 | "scripts": { 37 | "build": "rollup -c", 38 | "test_browser": "mocha-headless-chrome --args=disable-web-security -f test/browser.html", 39 | "test_node": "mocha -r esm", 40 | "test": "npm run test_node && npm run build && npm run test_browser", 41 | "prepare": "rollup -c" 42 | }, 43 | "devDependencies": { 44 | "chai": "^4.2.0", 45 | "esm": "^3.2.22", 46 | "gulp-format-md": "^1.0.0", 47 | "mocha": "^6.1.4", 48 | "mocha-headless-chrome": "^3.1.0", 49 | "rollup": "^2.22.1" 50 | }, 51 | "keywords": [ 52 | "check", 53 | "is", 54 | "is-object", 55 | "isobject", 56 | "javascript", 57 | "kind", 58 | "kind-of", 59 | "object", 60 | "plain", 61 | "type", 62 | "typeof", 63 | "value" 64 | ], 65 | "verb": { 66 | "toc": false, 67 | "layout": "default", 68 | "tasks": [ 69 | "readme" 70 | ], 71 | "plugins": [ 72 | "gulp-format-md" 73 | ], 74 | "related": { 75 | "list": [ 76 | "is-number", 77 | "isobject", 78 | "kind-of" 79 | ] 80 | }, 81 | "lint": { 82 | "reflinks": true 83 | } 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /rollup.config.js: -------------------------------------------------------------------------------- 1 | export default { 2 | input: './is-plain-object.js', 3 | output: [ 4 | { 5 | format: 'iife', 6 | file: 'browser/is-plain-object.js', 7 | name: 'library', 8 | }, 9 | { 10 | format: 'cjs', 11 | file: 'dist/is-plain-object.js', 12 | }, 13 | { 14 | format: 'esm', 15 | file: 'dist/is-plain-object.mjs' 16 | } 17 | ] 18 | } 19 | -------------------------------------------------------------------------------- /test/browser-iframe.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Cross-Realm isPlainObject() 6 | 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /test/browser.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Cross-Realm isPlainObject() 6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 62 | 63 | 64 | -------------------------------------------------------------------------------- /test/server.js: -------------------------------------------------------------------------------- 1 | /*! 2 | * is-plain-object 3 | * 4 | * Copyright (c) 2014-2017, Jon Schlinkert. 5 | * Licensed under the MIT License. 6 | */ 7 | 8 | import assert from 'assert'; 9 | import { isPlainObject } from '../is-plain-object.js'; 10 | 11 | describe('Same-Realm Server Tests', function() { 12 | it('should return `true` if the object is created by the `Object` constructor.', function() { 13 | assert(isPlainObject(Object.create({}))); 14 | assert(isPlainObject(Object.create(Object.prototype))); 15 | assert(isPlainObject({foo: 'bar'})); 16 | assert(isPlainObject({})); 17 | assert(isPlainObject(Object.create(null))); 18 | }); 19 | 20 | it('should return `false` if the object is not created by the `Object` constructor.', function() { 21 | function Foo() {this.abc = {};}; 22 | 23 | assert(!isPlainObject(/foo/)); 24 | assert(!isPlainObject(function() {})); 25 | assert(!isPlainObject(1)); 26 | assert(!isPlainObject(['foo', 'bar'])); 27 | assert(!isPlainObject([])); 28 | assert(!isPlainObject(new Foo)); 29 | assert(!isPlainObject(null)); 30 | }); 31 | }); 32 | --------------------------------------------------------------------------------