Skip to content

🏷️ 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

MethodDescription
cloneCreate a deep clone of an object.
mergeMerge multiple objects with configurable strategies (Deep, Shallow, etc.).
diffCompare two objects and return the structural differences.
pathSafely access nested properties using dot-notation strings.
seekFind a value anywhere within a deeply nested object by its key.
parseJSONSafely parse JSON strings with optional fallback value.
keysType-safe way to get an object's keys.
valuesType-safe way to get an object's values.
entriesType-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'

🔗 All Object Utilities