1
+ import { isPlainObject } from "./_utils" ;
1
2
import type { Merger , DefuFn as DefuFunction , DefuInstance } from "./types" ;
2
3
3
4
// Base function to apply defaults
@@ -7,7 +8,7 @@ function _defu<T>(
7
8
namespace = "." ,
8
9
merger ?: Merger ,
9
10
) : T {
10
- if ( ! _isPlainObject ( defaults ) ) {
11
+ if ( ! isPlainObject ( defaults ) ) {
11
12
return _defu ( baseObject , { } , namespace , merger ) ;
12
13
}
13
14
@@ -30,7 +31,7 @@ function _defu<T>(
30
31
31
32
if ( Array . isArray ( value ) && Array . isArray ( object [ key ] ) ) {
32
33
object [ key ] = [ ...value , ...object [ key ] ] ;
33
- } else if ( _isPlainObject ( value ) && _isPlainObject ( object [ key ] ) ) {
34
+ } else if ( isPlainObject ( value ) && isPlainObject ( object [ key ] ) ) {
34
35
object [ key ] = _defu (
35
36
value ,
36
37
object [ key ] ,
@@ -45,23 +46,6 @@ function _defu<T>(
45
46
return object ;
46
47
}
47
48
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
-
65
49
// Create defu wrapper with optional merger and multi arg support
66
50
export function createDefu ( merger ?: Merger ) : DefuFunction {
67
51
return ( ...arguments_ ) =>
0 commit comments