A collection of utilities dealing with object.
ES5, tested package
Install with npm:
$ npm i object-utils-js
with es modules
import { isObject } from 'object-utils-js'
Use isObject
if you only want to check if the value is an object and not an array, or Element object represents an HTML element, like P, DIV, A, TABLE, or any other HTML element.
true when created by the Object
constructor.
isObject(Object.create({}))
isObject(Object.create(Object.prototype))
isObject({foo: 'bar'})
isObject({})
false when not created by the Object
constructor.
isObject(null)
isObject(1)
isObject(['foo', 'bar'])
isObject([])
isObject(()=>{})
isObject(Object.create(null))
isObject(global.document)
similar to isObject func except null value
true for input parameter.
isObjectOrNull(null)
convert any input to object
toObject(null)
//=> {}
toObject({})
//=> {}
toObject({a:"a"})
//=> {a:"a"}
toObject(["a"])
//=> {}
Returns true if it is a DOM Node true
isDOMNode(document.createElement("p"))
isDOMNode(document)
false
isDOMNode(null)
isDOMNode({})
isDOMNode("")
isDOMNode(1)
Returns true if it is a DOM element true
isDOMElement(document.createElement("p"))
false
isDOMElement(null)
isDOMElement({})
isDOMElement("")
isDOMElement(1)
isDOMElement(document)
Pawel Zielinski
Copyright © 2021, [Pawel Zielinski(https://github.com/zielinskipawel). Released under the MIT License.