Skip to content

Commit

Permalink
Merge pull request #13 from dictor93/feat/isObject
Browse files Browse the repository at this point in the history
Add feature isObject function
  • Loading branch information
prdn authored Nov 2, 2023
2 parents 8b76855 + 4f112b1 commit 983ccc3
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# 1.4.0
- feat: isObject

# 1.3.0
- feat: isFunction

Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Currently supported utils:
- `isEmpty` - checks if value is an empty object, collection, map, or set
- `isFunction` - checks if input is a Function object.
- `isNil` - checks whenever value is null or undefined
- `isObject` - checks if the input is not a nullable object instance
- `isPlainObject` - checks if input is object, not null object and not array object
- `merge` - deep merge functionality for objects
- `omit` - provides new object that omits only specific fields of source object
Expand Down
1 change: 1 addition & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export function getArrayUniq (arr: Array<any>): Array<any>
export function isEmpty(val: any): boolean
export function isFunction(val: any): boolean
export function isNil(val: any): boolean
export function isObject(verifiable: any): Boolean
export function isPlainObject(val: any): boolean
export function merge(obj: Object, ...sources: Object[]): Object
export function omit(obj: Object, keys: Array<string>): Object
Expand Down
2 changes: 2 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const getArrayUniq = require('./src/getArrayUniq')
const isEmpty = require('./src/isEmpty')
const isFunction = require('./src/isFunction')
const isNil = require('./src/isNil')
const isObject = require('./src/isObject')
const isPlainObject = require('./src/isPlainObject')
const merge = require('./src/merge')
const omit = require('./src/omit')
Expand All @@ -24,6 +25,7 @@ module.exports = {
isEmpty,
isFunction,
isNil,
isObject,
isPlainObject,
merge,
omit,
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": "@bitfinex/lib-js-util-base",
"version": "1.3.0",
"version": "1.4.0",
"description": "general utils",
"main": "index.js",
"scripts": {
Expand Down
9 changes: 9 additions & 0 deletions src/isObject.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
'use strict'

const isObject = (verifiable) => {
if (verifiable == null) return false
const type = typeof verifiable
return type === 'object'
}

module.exports = isObject
33 changes: 33 additions & 0 deletions test/isObject.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
'use strict'

/* eslint-env mocha */

const assert = require('assert')
const { isObject } = require('../index')

describe('isObject', () => {
it('should return true for plain object', () => {
const object = { a: 'foo' }
assert.ok(isObject(object))
})

it('should return true for array', () => {
const object = []
assert.ok(isObject(object))
})

it('should return true for result of any constructor', () => {
assert.ok(isObject(new Set()))
assert.ok(isObject(new Promise(() => {})))
assert.ok(isObject(new Map()))
assert.ok(isObject(new RegExp()))
})

it('should return false for null and primitives', () => {
assert.ok(!isObject(null))
assert.ok(!isObject('foo'))
assert.ok(!isObject(123456))
assert.ok(!isObject(true))
assert.ok(!isObject(undefined))
})
})

0 comments on commit 983ccc3

Please sign in to comment.