Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

loosen object predicate to take more kinds of objects #58

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion dist/js.spec.bundle.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions lib/predicates.js
@@ -1,7 +1,7 @@
import set from "lodash.isset";
import number from "lodash.isnumber";
import fn from "lodash.isfunction";
import obj from "lodash.isplainobject";
import obj from "lodash.isobjectlike";
import nil from "lodash.isnil";
import bool from "lodash.isboolean";
import date from "lodash.isdate";
Expand Down Expand Up @@ -29,7 +29,7 @@ function isFunction(x) {
}

function isObject(x) {
return obj(x);
return obj(x) && !isArray(x);
}

function isSet(x) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -60,7 +60,7 @@
"lodash.isinteger": "^4.0.4",
"lodash.isnil": "^4.0.0",
"lodash.isnumber": "^3.0.3",
"lodash.isplainobject": "^4.0.6",
"lodash.isobjectlike": "^4.0.0",
"lodash.isregexp": "^4.0.1",
"lodash.isset": "^4.4.2",
"lodash.isstring": "^4.0.1",
Expand Down
11 changes: 11 additions & 0 deletions test/predicates.test.js
Expand Up @@ -2,6 +2,17 @@ import { expect } from "chai";
import * as p from "../lib/predicates";

describe("predicate", () => {
describe("object", () => {
it("accepts plain objects", () => {
expect(p.obj({ x: 1 })).to.be.true;
});
it("accepts instances of constructed objects", () => {
expect(p.obj(new Date())).to.be.true;
});
it("rejects arrays", () => {
expect(p.obj([1, 2])).to.be.false;
});
});
describe("number", () => {
[
-10,
Expand Down
6 changes: 3 additions & 3 deletions yarn.lock
Expand Up @@ -2582,9 +2582,9 @@ lodash.isnumber:
version "3.0.3"
resolved "https://registry.yarnpkg.com/lodash.isnumber/-/lodash.isnumber-3.0.3.tgz#3ce76810c5928d03352301ac287317f11c0b1ffc"

lodash.isplainobject:
version "4.0.6"
resolved "https://registry.yarnpkg.com/lodash.isplainobject/-/lodash.isplainobject-4.0.6.tgz#7c526a52d89b45c45cc690b88163be0497f550cb"
lodash.isobjectlike@^4.0.0:
version "4.0.0"
resolved "https://registry.yarnpkg.com/lodash.isobjectlike/-/lodash.isobjectlike-4.0.0.tgz#742c5fc65add27924d3d24191681aa9a17b2b60d"

lodash.isregexp:
version "4.0.1"
Expand Down