Skip to content

Commit

Permalink
isObject returns false for arrays [major]
Browse files Browse the repository at this point in the history
  • Loading branch information
overlookmotel committed Apr 30, 2020
1 parent 5977080 commit 821bf4d
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 7 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,12 @@ All methods return `true` or `false`.
* `isSymbol`
* `isUndefined`
* `isRegExp`
* `isObject`
* `isDate`
* `isError`
* `isFunction`
* `isPrimitive`

NB [core-util-is](https://www.npmjs.com/package/core-util-is)'s `isBuffer` is not included.
NB [core-util-is](https://www.npmjs.com/package/core-util-is)'s `isBuffer` is not included. `isObject` method differs from [core-util-is](https://www.npmjs.com/package/core-util-is)'s method of same name (see [below](#objects)).

### Additional functions

Expand All @@ -69,6 +68,7 @@ NB [core-util-is](https://www.npmjs.com/package/core-util-is)'s `isBuffer` is no

#### Objects

* `isObject` - `true` if passed object (not including arrays)
* `isEmptyObject` - `true` if passed object with no properties

#### Other
Expand Down
8 changes: 4 additions & 4 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,6 @@ export function isRegExp(arg) {
return isTypeByToString('RegExp', arg);
}

export function isObject(arg) {
return isType('object', arg) && !isNull(arg);
}

export function isDate(arg) {
return isTypeByToString('Date', arg);
}
Expand Down Expand Up @@ -87,6 +83,10 @@ export function isFullString(arg) {

// Objects

export function isObject(arg) {
return isType('object', arg) && !isNull(arg) && !isArray(arg);
}

export function isEmptyObject(arg) {
return isObject(arg) && Object.keys(arg).length === 0;
}
Expand Down
44 changes: 43 additions & 1 deletion test/objects.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,40 @@

// Modules
// eslint-disable-next-line import/no-unresolved, node/no-missing-import
import {isEmptyObject} from 'is-it-type';
import {isObject, isEmptyObject} from 'is-it-type';

// Tests

describe('isObject', () => {
it('returns true for {}', () => {
expect(isObject({})).toBe(true);
});

it('returns true for {a: 1}', () => {
expect(isObject({a: 1})).toBe(true);
});

it('returns false for []', () => {
expect(isObject([])).toBe(false);
});

it('returns false for [1, 2, 3]', () => {
expect(isObject([1, 2, 3])).toBe(false);
});

it("returns false for ''", () => {
expect(isObject('')).toBe(false);
});

it('returns false for null', () => {
expect(isObject(null)).toBe(false);
});

it('returns false for undefined', () => {
expect(isObject(undefined)).toBe(false);
});
});

describe('isEmptyObject', () => {
it('returns true for {}', () => {
expect(isEmptyObject({})).toBe(true);
Expand All @@ -18,11 +48,23 @@ describe('isEmptyObject', () => {
expect(isEmptyObject({a: 1})).toBe(false);
});

it('returns false for []', () => {
expect(isEmptyObject([])).toBe(false);
});

it('returns false for [1, 2, 3]', () => {
expect(isEmptyObject([1, 2, 3])).toBe(false);
});

it("returns false for ''", () => {
expect(isEmptyObject('')).toBe(false);
});

it('returns false for null', () => {
expect(isEmptyObject(null)).toBe(false);
});

it('returns false for undefined', () => {
expect(isEmptyObject(undefined)).toBe(false);
});
});

0 comments on commit 821bf4d

Please sign in to comment.