File tree Expand file tree Collapse file tree 2 files changed +57
-0
lines changed
Expand file tree Collapse file tree 2 files changed +57
-0
lines changed Original file line number Diff line number Diff line change 1+ // -----------------------------------------------------------------------------
2+ // Deps
3+ // -----------------------------------------------------------------------------
4+
5+ import { isEmptyObject } from './is-empty-object' ;
6+
7+ // -----------------------------------------------------------------------------
8+ // Tests
9+ // -----------------------------------------------------------------------------
10+
11+ const testCases : {
12+ parameters : Parameters < typeof isEmptyObject > ;
13+ result : ReturnType < typeof isEmptyObject > ;
14+ } [ ] = [
15+ {
16+ parameters : [ { } ] ,
17+ result : true
18+ } ,
19+ {
20+ parameters : [ { key : 'value' } ] ,
21+ result : false
22+ } ,
23+ {
24+ parameters : [ new Date ( ) ] ,
25+ result : true
26+ } ,
27+ {
28+ parameters : [ new RegExp ( 'x' ) ] ,
29+ result : true
30+ }
31+ ] ;
32+
33+ describe ( 'isEmptyObject tool' , ( ) => {
34+ testCases . forEach ( ( { parameters, result } , i ) => {
35+ test ( `test #${ i + 1 } : ${ parameters . join ( ', ' ) } ` , ( ) => {
36+ const bool = isEmptyObject ( ...parameters ) ;
37+ expect ( bool ) . toStrictEqual ( result ) ;
38+ } ) ;
39+ } ) ;
40+ } ) ;
Original file line number Diff line number Diff line change 1+ // -----------------------------------------------------------------------------
2+ // Deps
3+ // -----------------------------------------------------------------------------
4+
5+ import { isPlainObject } from './is-plain-object' ;
6+
7+ // -----------------------------------------------------------------------------
8+ // Helper
9+ // -----------------------------------------------------------------------------
10+
11+ /**
12+ * @param sample
13+ * @return {boolean }
14+ */
15+ export function isEmptyObject ( sample : any ) {
16+ return isPlainObject ( sample ) && Object . keys ( sample ) . length === 0 ;
17+ }
You can’t perform that action at this time.
0 commit comments