1+ import { isPlainObject } from "./_utils" ;
12import type { Merger , DefuFn as DefuFunction , DefuInstance } from "./types" ;
23
34// Base function to apply defaults
@@ -7,7 +8,7 @@ function _defu<T>(
78 namespace = "." ,
89 merger ?: Merger ,
910) : T {
10- if ( ! _isPlainObject ( defaults ) ) {
11+ if ( ! isPlainObject ( defaults ) ) {
1112 return _defu ( baseObject , { } , namespace , merger ) ;
1213 }
1314
@@ -30,7 +31,7 @@ function _defu<T>(
3031
3132 if ( Array . isArray ( value ) && Array . isArray ( object [ key ] ) ) {
3233 object [ key ] = [ ...value , ...object [ key ] ] ;
33- } else if ( _isPlainObject ( value ) && _isPlainObject ( object [ key ] ) ) {
34+ } else if ( isPlainObject ( value ) && isPlainObject ( object [ key ] ) ) {
3435 object [ key ] = _defu (
3536 value ,
3637 object [ key ] ,
@@ -45,23 +46,6 @@ function _defu<T>(
4546 return object ;
4647}
4748
48- // From sindresorhus/is-plain-obj
49- // MIT License
50- // Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)
51- function _isPlainObject ( value : unknown ) : boolean {
52- if ( value === null || typeof value !== "object" ) {
53- return false ;
54- }
55- const prototype = Object . getPrototypeOf ( value ) ;
56- return (
57- ( prototype === null ||
58- prototype === Object . prototype ||
59- Object . getPrototypeOf ( prototype ) === null ) &&
60- ! ( Symbol . toStringTag in value ) &&
61- ! ( Symbol . iterator in value )
62- ) ;
63- }
64-
6549// Create defu wrapper with optional merger and multi arg support
6650export function createDefu ( merger ?: Merger ) : DefuFunction {
6751 return ( ...arguments_ ) =>
0 commit comments