-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from ewerk/feature/has-empty-value
Feature/has empty value
- Loading branch information
Showing
4 changed files
with
65 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
name: PR Verification | ||
|
||
on: | ||
pull_request: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: actions/setup-node@v4 | ||
with: | ||
node-version: 20 | ||
- run: npm ci | ||
- run: npm run lint | ||
- run: npm test |
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,20 @@ | ||
import { hasEmptyValue } from './has-empty-value'; | ||
|
||
describe('hasEmptyValue helper', () => { | ||
it('should return true, if "empty" value was provided', () => { | ||
expect(hasEmptyValue('')).toBe(true); | ||
expect(hasEmptyValue([])).toBe(true); | ||
expect(hasEmptyValue(null as unknown as string)).toBe(true); | ||
expect(hasEmptyValue(undefined as unknown as string)).toBe(true); | ||
}); | ||
|
||
it('should return false, if "non-empty" value was provided', () => { | ||
expect(hasEmptyValue(false)).toBe(false); | ||
expect(hasEmptyValue(0)).toBe(false); | ||
expect(hasEmptyValue('test string')).toBe(false); | ||
expect(hasEmptyValue([ | ||
'test', | ||
'string', | ||
])).toBe(false); | ||
}); | ||
}); |
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 @@ | ||
import { isNullOrUndefined } from '../is-null-or-undefined/is-null-or-undefined'; | ||
|
||
export const hasEmptyValue = (val: number | string | boolean | Array<any>): boolean => { | ||
if (val instanceof Array) { | ||
return val.length === 0; | ||
} | ||
return isNullOrUndefined(val) || val === '' ; | ||
}; |