object-array-utils
object-array-utils allows to check the type of an object or an array.
import { isObjectLiteral } from 'object-array-utils';
isObjectLiteral({ prop: 1 })
isObjectLiteral(new Date())
isObjectLiteral([1])
import { isObjectInstance } from 'object-array-utils';
isObjectInstance({ prop: 1 })
isObjectInstance(new Date())
isObjectInstance([1])
import { isObject } from 'object-array-utils';
isObject({ prop: 1 })
isObject(new Date())
isObject([1])
import { isArray } from 'object-array-utils';
isArray([1])
import { isArrayOfObjects } from 'object-array-utils';
isArrayOfObjects([{ prop: 1 }, new Date()])
isArrayOfObjects([1])
isArrayOfObjects([])
import { isArrayOfObjectLiterals } from 'object-array-utils';
isArrayOfObjectLiterals([{ prop: 1 }, { prop: 2 }])
isArrayOfObjectLiterals([{ prop: 1 }, new Date()])
isArrayOfObjectLiterals([1])
isArrayOfObjectLiterals([])
import { isNullOrUndefined } from 'object-array-utils';
isNullOrUndefined(null)
isNullOrUndefined(undefined)
import { hasObjectProp } from 'object-array-utils';
hasObjectProp({ prop: 1 }, 'prop')
import { isObjectSubset } from 'object-array-utils';
isObjectSubset({ prop1: 1, prop2: 2 }, { prop1: 1 })
isObjectSubset({ prop1: { foo: 1, bar: 2 } }, prop2: 2 }, { prop1: { bar: 2 } })
isObjectSubset({ prop1: [1, 2], prop2: 2 }, { prop1: [2] })
import { isArraySubset } from 'object-array-utils';
isArraySubset([1, 2], [1])
isArraySubset([1, { foo: 1, bar: 2 }], [{ bar: 2 }])
import { areObjectsEqual } from 'object-array-utils';
areObjectsEqual({ prop1: 1, prop2: 2 }, { prop2: 2, prop1: 1 })
import { areArraysEqual } from 'object-array-utils';
areArraysEqual([1, { prop1: 1, prop2: 2 }], [{ prop2: 2, prop1: 1 }, 1])
import { deepFreeze } from 'object-array-utils';
deepFreeze({ foo: 1 })
Limitations
isObjectSubset and isArraySubset may result into false negatives when dealing with arrays of object literals. For example:
isArraySubset([{ foo: 1 }, { bar: 2 }], [{}, { bar: 2 }])
isArraySubset([{ foo: 1 }, { bar: 2 }], [{}, { foo: 1 }])
Installation
You can get object-array-utils via npm.
$ npm install object-array-utils --save