Object Utilities
Collection of object manipulation utilities.
pick
Creates an object composed of the picked object properties.
Signature:
typescript
export declare const pick: <T extends object, K extends keyof T>(
object: T,
...paths: K[]
) => Pick<T, K>;Example:
typescript
import { pick } from "easy-kit-utils";
const object = { a: 1, b: "2", c: 3 };
pick(object, ["a", "c"]);
// => { 'a': 1, 'c': 3 }omit
The opposite of pick; this method creates an object composed of the own and inherited enumerable property paths of object that are not omitted.
Signature:
typescript
export declare const omit: <T extends object, K extends keyof T>(
object: T,
...paths: K[]
) => Omit<T, K>;Example:
typescript
import { omit } from "easy-kit-utils";
const object = { a: 1, b: "2", c: 3 };
omit(object, "a", "c");
// => { 'b': '2' }merge
Deeply merges two objects.
Signature:
typescript
export declare const merge: <T extends object, U extends object>(
target: T,
source: U
) => T & U;Example:
typescript
import { merge } from "easy-kit-utils";
const object1 = { a: { b: 1 } };
const object2 = { a: { c: 2 } };
merge(object1, object2);
// => { 'a': { 'b': 1, 'c': 2 } }deepClone
Creates a deep clone of an object.
Signature:
typescript
export declare const deepClone: <T>(obj: T) => T;Example:
typescript
import { deepClone } from "easy-kit-utils";
const objects = [{ a: 1 }, { b: 2 }];
const deep = deepClone(objects);
console.log(deep[0] === objects[0]);
// => falseget
Gets the value at path of object. If the resolved value is undefined, the defaultValue is returned in its place.
Signature:
typescript
export declare const get: <T>(
object: any,
path: string | string[],
defaultValue?: T
) => T | undefined;Example:
typescript
import { get } from "easy-kit-utils";
const object = { a: [{ b: { c: 3 } }] };
get(object, "a[0].b.c");
// => 3
get(object, ["a", "0", "b", "c"]);
// => 3
get(object, "a.b.c", "default");
// => 'default'