@unjs/defu
Deep-merge utility for configuration objects, assigning source properties onto target without overwriting existing values.
Official Documentation ↗v6.1. Check the official docs for the latest API surface.Installation
npm install defuMethods
No methods match this filter.
@unjs/defu is deep-merge utility for configuration objects, assigning source properties onto target without overwriting existing values. This page documents the core methods, installation, and common usage patterns for the current stable release.
Installation
Install @unjs/defu with your preferred package manager using the command shown in the frontmatter. The package is published to the npm registry and ships with TypeScript types where applicable.
Core methods
The methods listed in the frontmatter cover the primary API surface. Each signature reflects the v6.1 release. Consult the official documentation linked in sourceUrl for advanced options, edge cases, and breaking changes between major versions.
Frequently asked questions
The faq section in the frontmatter answers the most common questions about @unjs/defu, including comparisons with alternatives, configuration tips, and runtime requirements. If your question is not covered, check the source URL for the full guide.
Security
Official security statements captured from the package documentation:
- 源码显式跳过 proto 与 constructor 键(原型污染防护) — “if (key === “proto” || key === “constructor”) { continue; }” (source: https://raw.githubusercontent.com/unjs/defu/main/src/defu.ts, fetched 2026-11-08T20:10:00+08:00)
API reference evidence
Fetched from official sources on 2026-11-08T20:10:00+08:00 via WebFetch https://raw.githubusercontent.com/unjs/defu/main/src/defu.ts;WebFetch https://raw.githubusercontent.com/unjs/defu/main/src/types.ts.
defu→ signature from https://raw.githubusercontent.com/unjs/defu/main/src/types.ts; official text: “export interface DefuInstance { <Source extends Input, Defaults extends Array<Input | IgnoredInput>>( source: Source | IgnoredInput, …defaults: Defaults ): Defu<Source, Defaults>; fn: DefuFn; arrayFn: DefuFn; extend(me”defuOverride→ signature from https://raw.githubusercontent.com/unjs/defu/main/src/types.ts; official text: “export interface DefuInstance { <Source extends Input, Defaults extends Array<Input | IgnoredInput>>( source: Source | IgnoredInput, …defaults: Defaults ): Defu<Source, Defaults>; fn: DefuFn; arrayFn: DefuFn; extend(me”createDefu→ signature from https://raw.githubusercontent.com/unjs/defu/main/src/defu.ts; official text: “// Create defu wrapper with optional merger and multi arg support export function createDefu(merger?: Merger): DefuFunction {”
FAQ
- How is it different from Object.assign?
- defu deep-merges nested objects and does not overwrite existing values; Object.assign is shallow and overwrites.
- Is it recursive?
- Yes. Nested objects are merged recursively; arrays are replaced, not concatenated.
- Is it zero-dependency?
- Yes. It is a single utility with no dependencies.
Report a problem with this API docOpens a pre-filled issue on GitHub.