Appearance
Object
individual package can be found here
@riadh-adrani/obj-utils
.
Types
ts
type Type =
| 'undefined'
| 'null'
| 'boolean'
| 'number'
| 'bigint'
| 'string'
| 'symbol'
| 'object'
| 'array';
areEqual()
perform deep comparison of two objects of any type.
ts
function areEquals(obj1: unknown, obj2: unknown, depth?: number): boolean;
obj1
: first object.obj2
: second object.depth
: maximum comparison depth.10
by default.
copy()
create a deep copy from the given object. Works only with plain JavaScript objects.
ts
function copy<T>(source: T): T;
source
: source object.
hasProperty()
checks if the given object has the named property as a key.
ts
function hasProperty<T>(object: T, property: string): boolean;
object
: source object.property
: property name.
isFalsy()
checks if a value is falsy or not.
JavaScript falsy value are : false
, 0
, -0
, ""
, null
, undefined
, Nan
.
ts
function isFalsy<T>(value: T, additionalFalsyList?: unknown[]): boolean;
value
: source object.additionalFalsyList
: a list of additional value that should be considered falsy..
isFunction()
checks if an object is a function.
ts
function isFunction(object: unknown): boolean;
object
: source object.
isPrimitive()
checks if an object is of a primitive type.
JavaScript primitive types : string
, number
, bigint
, boolean
, undefined
, symbol
and null.
ts
function isPrimitive<T>(object: T): boolean;
object
: source object.
merge()
perform deep merge of two objects
.
ts
function merge<T = Record<string, unknown>>(...objects: Record<string, unknown>[]): T;
...objects
: objects to be merged.
isNumber()
checks if the object provided is a number.
ts
function isNumber(o: unknown): boolean;
o
: any object.
isString()
checks if the object provided is a string.
ts
function isString(o: unknown): boolean;
o
: any object.
isArray()
checks if the object provided is an array.
ts
function isArray(o: unknown): boolean;
o
: any object.
isObject()
checks if the object provided is an object.
ts
function isObject(o: unknown): boolean;
o
: any object.
isNull()
checks if the object provided is null.
ts
function isNull(o: unknown): boolean;
o
: any object.
isUndefined()
checks if the object provided is equal to undefined
.
ts
function isUndefined(o: unknown): boolean;
o
: any object.
isBoolean()
checks if the object provided is of type boolean
.
ts
function isBoolean(o: unknown): boolean;
o
: any object.
isBigint()
checks if the object provided is of type bigint
.
ts
function isBigint(o: unknown): boolean;
o
: any object.
isSymbol()
checks if the object provided is of type symbol
.
ts
function isSymbol(o: unknown): boolean;
o
: any object.
getType()
returns the type
of the object.
This fucntion differntiate between object
, array
and null
.
check Type for the full list of values.
ts
function getType(o: unknown): Type;
o
: any object.
forEachKey()
run a callback for each key in a Record
.
ts
function <T>(callback: (key: string, value: T, index: number) => void, object: Record<string, T>)
callback
: callback to be executed.object
: source object.
throws when object is not an object.
pick()
creates a new object with only the given keys.
ts
function pick<T extends Object, K extends keyof T>(object: T, ...keys: Array<K>): Pick<T, K>;
object
: source object....keys
: object's key to preserve.
omit()
creates a new object omitting the given keys.
ts
function omit<T extends Object, K extends keyof T>(object: T, ...keys: Array<K>): Omit<T, K>;
object
: source object....keys
: object's key to omit
keyHasCircularDependency()
detects if the given key have a circular dependency within.
ts
function hasCircularDependency<T extends object>(o: T, key: keyof T, visited: Set<unkown>): boolean;
o
: objectkey
: specific key to be testedvisited
: a set of additional object that will be tested against each value within the specific key, empty by default.