🏷️ Object Utilities
Object utilities provide robust tools to manipulate, compare, and traverse objects in a type-safe, ergonomic way. Use these helpers for deep cloning, merging, diffing, nested path access, and more.
📚 Quick Reference
| Method | Description |
|---|---|
clone | Create a deep clone of an object. |
merge | Merge multiple objects with configurable strategies (Deep, Shallow, etc.). |
diff | Compare two objects and return the structural differences. |
path | Safely access nested properties using dot-notation strings. |
seek | Find a value anywhere within a deeply nested object by its key. |
parseJSON | Safely parse JSON strings with optional fallback value. |
keys | Type-safe way to get an object's keys. |
values | Type-safe way to get an object's values. |
entries | Type-safe way to get an object's entries. |
💡 Practical Examples
Deep Merging & Cloning
ts
import { merge, clone } from '@vielzeug/toolkit';
const config = { api: { host: 'localhost', port: 8080 } };
const overrides = { api: { port: 3000 } };
// 1. Deep merge (config remains unchanged)
const finalConfig = merge('deep', config, overrides);
// { api: { host: 'localhost', port: 3000 } }
// 2. Deep clone
const deepCopy = clone(finalConfig);Accessing Nested Data
ts
import { path, seek } from '@vielzeug/toolkit';
const data = {
user: {
profile: {
settings: { theme: 'dark' },
},
},
};
// Access via path string
const theme = path(data, 'user.profile.settings.theme'); // 'dark'
// Find key 'theme' anywhere in the object
const themeAnywhere = seek(data, 'theme'); // 'dark'