# Object I/O Utilities for common object operations: cloning, merging, picking, omitting, and emptiness checking. ## clone Deep clones a JSON-like object or array using JSON.parse(JSON.stringify()). ```typescript import { clone } from "@triplef/helpers/object-io"; ``` ```typescript function clone(obj: T): T; ``` ### Example ```typescript const original = { a: 1, b: { c: 2 }, arr: [1, 2, 3] }; const copy = clone(original); copy.b.c = 99; // Only copy is modified original.b.c; // Still 2 ``` --- ## isEmpty Checks if a JSON-like object or array is empty. ```typescript import { isEmpty } from "@triplef/helpers/object-io"; ``` ```typescript function isEmpty(obj: Record | any[]): boolean; ``` ### Behavior | Input | Result | | ---------- | ------------------ | | `{}` | `true` | | `{ a: 1 }` | `false` | | `[]` | `true` | | `[1, 2]` | `false` | | Non-object | Throws `TypeError` | ### Example ```typescript isEmpty({}); // true isEmpty({ a: 1 }); // false isEmpty([]); // true isEmpty([1, 2]); // false isEmpty(null); // throws TypeError isEmpty("string"); // throws TypeError ``` --- ## merge Merges two JSON-like objects with optional deep merging. ```typescript import { merge } from "@triplef/helpers/object-io"; ``` ```typescript function merge( a: Record, b: Record, deep?: boolean ): Record; ``` ### Parameters | Parameter | Type | Description | | --------- | --------------------- | ------------------------------------ | | `a` | `Record` | Target object | | `b` | `Record` | Source object | | `deep` | `boolean` | Enable deep merge (default: `false`) | ### Example ```typescript // Shallow merge const shallow = merge({ a: 1, b: 2 }, { b: 3, c: 4 }); // { a: 1, b: 3, c: 4 } // Deep merge const deep = merge({ a: { b: 1 } }, { a: { c: 2 } }, true); // { a: { b: 1, c: 2 } } ``` --- ## omit Creates a new object by omitting specified keys. ```typescript import { omit } from "@triplef/helpers/object-io"; ``` ```typescript function omit( obj: T, keys: Array ): Omit; ``` ### Example ```typescript const user = { id: 1, name: "John", password: "secret", token: "abc" }; const safe = omit(user, ["password", "token"]); // { id: 1, name: "John" } ``` --- ## pick Creates a new object by selecting only specified keys. ```typescript import { pick } from "@triplef/helpers/object-io"; ``` ```typescript function pick( obj: T, keys: Array ): Pick; ``` ### Example ```typescript const user = { id: 1, name: "John", age: 30, email: "john@example.com" }; const basic = pick(user, ["id", "name"]); // { id: 1, name: "John" } ```