This repository has been archived by the owner on Feb 23, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 219
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replace lodash isEmpty with type guard
- Loading branch information
1 parent
380fedb
commit a8dda6e
Showing
7 changed files
with
39 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
export const isEmpty = ( value: unknown ): boolean => { | ||
return ( | ||
value === null || | ||
value === undefined || | ||
( typeof value === 'object' && Object.keys( value ).length === 0 ) || | ||
( typeof value === 'string' && value.trim().length === 0 ) | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { isEmpty } from '@woocommerce/types'; | ||
|
||
describe( 'Testing isEmpty()', () => { | ||
it( 'Correctly handles null', () => { | ||
expect( isEmpty( null ) ).toBe( true ); | ||
} ); | ||
it( 'Correctly handles undefined', () => { | ||
expect( isEmpty( undefined ) ).toBe( true ); | ||
} ); | ||
it( 'Correctly handles empty objects', () => { | ||
expect( isEmpty( {} ) ).toBe( true ); | ||
} ); | ||
it( 'Correctly handles empty arrays', () => { | ||
expect( isEmpty( [] ) ).toBe( true ); | ||
} ); | ||
it( 'Correctly handles empty strings', () => { | ||
expect( isEmpty( '' ) ).toBe( true ); | ||
} ); | ||
it( 'Correctly handles object with values', () => { | ||
expect( isEmpty( { a: '1' } ) ).toBe( false ); | ||
} ); | ||
} ); |