@riadh-adrani/obj-utils
v1.0.5
Published
Javascript objects utilities
Downloads
71
Readme
obj-utils
Javascript object utilities.
Check documentation here
Methods
isNumber
checks if o
is a number.
function isNumber(o: unknown): o is number;
isArray
checks if o
is an array.
function isArray<T>(o: unknown): o is Array<T>;
isObject
checks if o
is an object.
function isObject(o: unknown): o is object;
isNull
checks if o
is null.
function isNull(o: unknown): o is null;
isUndefined
checks if o
is undefined.
function isUndefined(o: unknown): o is undefined;
isBoolean
checks if o
is boolean.
function isBoolean(o: unknown): o is boolean;
isBigint
checks if o
is bigint.
function isBigint(o: unknown): o is bigint;
isSymbol
checks if o
is symbol.
function isSymbol(o: unknown): o is bigint;
isFunction
checks if o
is a function.
function isFunction<F = () => void>(o: unknown): o is F;
isFalsy
checks if o
is falsy.
function isFalsy(o: unknown): o is false | 0 | '' | null | undefined | null;
isPrimitive
checks if o
is a primitive.
function isPrimitive(
o: unknown
): o is string | number | bigint | boolean | undefined | symbol | null;
hasProperty
checks if o
is an object with the given property.
function hasProperty<V = unknown, K extends string | number | symbol = string>(
o: unknown,
property: K
): o is { [P in K]: V };
areEqual
checks if obj1
is deeply and strictly equal to obj2
.
function areEqual(obj1: unknown, obj2: unknown, depth?: number): boolean;
you can set a maximum depth, it is set to
10
by default.
copy
perform a deep copy of the given object.
function copy<T>(source: T): T;
copyKeys
copy keys from an object to another with the possibility of ignoring some keys.
function copyKeys<F extends object, T extends object>(
source: F,
target: T,
...exclude: Array<StringWithAutoComplete<keyof F>>
forEachKey
execute a callback for each key in an object.
function forEachKey<T extends object>(
callback: (key: keyof T, value: T[keyof T], index: number) => void,
object: T
): void;
getType
a better version of typeof
that diffirentiate null
, object
and array
.
function getType(o: unknown): Type;
Type
export type Type =
| 'undefined'
| 'null'
| 'boolean'
| 'number'
| 'bigint'
| 'string'
| 'symbol'
| 'object'
| 'array';
merge
perform a deep merge of two or more objects.
function merge<S extends object, T extends object = S>(...objects: Array<S>): T;
comparison are performed by
key
.
new keys will be added.
the function will try to mainting similar object structure, overrding keys only when types are different, using
getType
omit
copy an object but omitting certain keys.
function omit<T extends object, K extends keyof T>(
object: T,
...keys: Array<StringWithAutoComplete<keyof T | K>>
): Omit<T, K>;
pick
create a new object of selected keys.
function pick<T extends object, K extends keyof T>(
object: T,
...keys: Array<keyof T | K>
): Pick<T, K>;