Skip to content

Commit

Permalink
Support Object.create(null) as plain object (#23)
Browse files Browse the repository at this point in the history
  • Loading branch information
TrySound committed Jul 21, 2020
1 parent e38be41 commit ae35765
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 9 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# 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)

> Returns true if an object was created by the `Object` constructor.
> Returns true if an object was created by the `Object` constructor, or Object.create(null).
Please consider following this project's author, [Jon Schlinkert](https://github.com/jonschlinkert), and consider starring the project to show your :heart: and support.

Expand Down Expand Up @@ -116,4 +116,4 @@ Released under the [MIT License](LICENSE).

***

_This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.8.0, on April 28, 2019._
_This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.8.0, on April 28, 2019._
5 changes: 3 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@
import isObject from 'isobject';

function isObjectObject(o) {
var type = Object.prototype.toString.call(o)
return isObject(o) === true
&& Object.prototype.toString.call(o) === '[object Object]';
&& (type === '[object Object]' || type === '[object Null]');
}

export default function isPlainObject(o) {
Expand All @@ -19,7 +20,7 @@ export default function isPlainObject(o) {

// If has modified constructor
ctor = o.constructor;
if (typeof ctor !== 'function') return false;
if (ctor === undefined) return true;

// If has modified prototype
prot = ctor.prototype;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "is-plain-object",
"description": "Returns true if an object was created by the `Object` constructor.",
"description": "Returns true if an object was created by the `Object` constructor, or Object.create(null).",
"version": "3.0.1",
"homepage": "https://github.com/jonschlinkert/is-plain-object",
"author": "Jon Schlinkert (https://github.com/jonschlinkert)",
Expand Down
6 changes: 3 additions & 3 deletions test/browser-iframe.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
Object.create({}),
Object.create(Object.prototype),
{foo: 'bar'},
{}
{},
Object.create(null)
];

// Should return false with isPlainObject()
Expand All @@ -23,8 +24,7 @@
['foo', 'bar'],
[],
new Foo,
null,
Object.create(null)
null
];

</script>
Expand Down
2 changes: 1 addition & 1 deletion test/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ describe('Same-Realm Server Tests', function() {
assert(isPlainObject(Object.create(Object.prototype)));
assert(isPlainObject({foo: 'bar'}));
assert(isPlainObject({}));
assert(isPlainObject(Object.create(null)));
});

it('should return `false` if the object is not created by the `Object` constructor.', function() {
Expand All @@ -26,6 +27,5 @@ describe('Same-Realm Server Tests', function() {
assert(!isPlainObject([]));
assert(!isPlainObject(new Foo));
assert(!isPlainObject(null));
assert(!isPlainObject(Object.create(null)));
});
});

0 comments on commit ae35765

Please sign in to comment.