Javascript object utilities.
Check documentation here
checks if o
is a number.
function isNumber(o: unknown): o is number;
checks if o
is an array.
function isArray<T>(o: unknown): o is Array<T>;
checks if o
is an object.
function isObject(o: unknown): o is object;
checks if o
is null.
function isNull(o: unknown): o is null;
checks if o
is undefined.
function isUndefined(o: unknown): o is undefined;
checks if o
is boolean.
function isBoolean(o: unknown): o is boolean;
checks if o
is bigint.
function isBigint(o: unknown): o is bigint;
checks if o
is symbol.
function isSymbol(o: unknown): o is bigint;
checks if o
is a function.
function isFunction<F = () => void>(o: unknown): o is F;
checks if o
is falsy.
function isFalsy(o: unknown): o is false | 0 | '' | null | undefined | null;
checks if o
is a primitive.
function isPrimitive(
o: unknown
): o is string | number | bigint | boolean | undefined | symbol | null;
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 };
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.
perform a deep copy of the given object.
function copy<T>(source: T): T;
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>>
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;
a better version of typeof
that diffirentiate null
, object
and array
.
function getType(o: unknown): Type;
export type Type =
| 'undefined'
| 'null'
| 'boolean'
| 'number'
| 'bigint'
| 'string'
| 'symbol'
| 'object'
| 'array';
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
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>;
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>;