object-utils-js

A collection of utilities dealing with object

Usage no npm install needed!

<script type="module">
  import objectUtilsJs from 'https://cdn.skypack.dev/object-utils-js';
</script>

README

object-utils-js

A collection of utilities dealing with object.

ES5, tested package

Install

Install with npm:

$ npm i object-utils-js

Usage

with es modules

import { isObject } from 'object-utils-js'

isObject

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)

isObjectOrNull

similar to isObject func except null value

true for input parameter.

isObjectOrNull(null)

toObject

convert any input to object

toObject(null)
//=> {}
toObject({})
//=> {}
toObject({a:"a"})
//=> {a:"a"}
toObject(["a"])
//=> {}

isDOMNode

Returns true if it is a DOM Node true

isDOMNode(document.createElement("p"))
isDOMNode(document)

false

isDOMNode(null)
isDOMNode({})
isDOMNode("")
isDOMNode(1)

isDOMElement

Returns true if it is a DOM element true

isDOMElement(document.createElement("p"))

false

isDOMElement(null)
isDOMElement({})
isDOMElement("")
isDOMElement(1)
isDOMElement(document)

Author

Pawel Zielinski

License

Copyright © 2021, [Pawel Zielinski(https://github.com/zielinskipawel). Released under the MIT License.