-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
34 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
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 @@ | ||
import { isVisibleValue } from './isVisibleValue' | ||
|
||
describe('isVisibleValue', () => { | ||
test('不是', () => { | ||
expect(isVisibleValue(undefined)).toBeFalse() | ||
expect(isVisibleValue(null)).toBeFalse() | ||
expect(isVisibleValue(false)).toBeFalse() | ||
expect(isVisibleValue(true)).toBeFalse() | ||
expect(isVisibleValue('')).toBeFalse() | ||
}) | ||
|
||
test('是', () => { | ||
expect(isVisibleValue(0)).toBeTrue() | ||
expect(isVisibleValue('1')).toBeTrue() | ||
expect(isVisibleValue({})).toBeTrue() | ||
expect(isVisibleValue([])).toBeTrue() | ||
}) | ||
}) |
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,15 @@ | ||
/** | ||
* 是否是渲染后可见的值。 | ||
* 渲染后不可见的值包括:`undefined`、`null`、`true`、`false`、空字符串。 | ||
* | ||
* @param value 值 | ||
* @returns 返回结果 | ||
* ```typescript | ||
* isVisibleValue(null) // => false | ||
* isVisibleValue(0) // => true | ||
* ``` | ||
*/ | ||
export function isVisibleValue(value: any): boolean { | ||
// ref: https://reactjs.org/docs/jsx-in-depth.html#booleans-null-and-undefined-are-ignored | ||
return value != null && value !== true && value !== false && value !== '' | ||
} |