File tree Expand file tree Collapse file tree 2 files changed +6
-0
lines changed Expand file tree Collapse file tree 2 files changed +6
-0
lines changed Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ import { isArray } from './is-array';
22import { isString } from './is-string' ;
33import { isArguments } from './is-arguments' ;
44import { isUndefined } from './is-undefined' ;
5+ import { isSet } from './is-set' ;
56
67/**
78 * Checks if `o` is an empty object. An object is "empty" if it:
@@ -19,6 +20,9 @@ export function isEmpty(o: unknown): boolean {
1920 if ( isArray ( o ) || isString ( o ) || isArguments ( o ) ) {
2021 return o . length === 0 ;
2122 }
23+ if ( isSet ( o ) ) {
24+ return o . size === 0 ;
25+ }
2226 // Non-object arguments passed into Object.keys are coerced into objects (the only
2327 // exception being undefined or null, which is handled above). Therefore, it's ok to
2428 // assume the input is an object because it will be once passed through. See also:
Original file line number Diff line number Diff line change @@ -6,6 +6,7 @@ describe('isEmpty', () => {
66
77 it ( 'correctly classifies empty things' , ( ) => {
88 expect ( t . isEmpty ( [ ] ) ) . to . strictlyEqual ( true ) ;
9+ expect ( t . isEmpty ( new Set ( [ ] ) ) ) . to . strictlyEqual ( true ) ;
910 // eslint-disable-next-line
1011 expect ( t . isEmpty ( new Array ( ) ) ) . to . strictlyEqual ( true ) ;
1112 expect ( t . isEmpty ( { } ) ) . to . strictlyEqual ( true ) ;
@@ -41,6 +42,7 @@ describe('isEmpty', () => {
4142 expect ( t . isEmpty ( { length : 0 } ) ) . to . strictlyEqual ( false ) ;
4243 expect ( t . isEmpty ( [ 1 ] ) ) . to . strictlyEqual ( false ) ;
4344 expect ( t . isEmpty ( new Array ( 10 ) ) ) . to . strictlyEqual ( false ) ;
45+ expect ( t . isEmpty ( new Set ( [ 1 ] ) ) ) . to . strictlyEqual ( false ) ;
4446 } ) ;
4547
4648} ) ;
You can’t perform that action at this time.
0 commit comments