Skip to content

Commit

Permalink
perf(utils): [isFalsy] use ternary
Browse files Browse the repository at this point in the history
Signed-off-by: Lexus Drumgold <[email protected]>
  • Loading branch information
unicornware committed Aug 13, 2023
1 parent 36aa5f8 commit de4e3df
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 13 deletions.
6 changes: 6 additions & 0 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ const config = {
'sort-keys': 0
}
},
{
files: ['src/utils/is-falsy.ts'],
rules: {
'@typescript-eslint/strict-boolean-expressions': 0
}
},
{
files: ['src/utils/ksort.ts'],
rules: {
Expand Down
3 changes: 2 additions & 1 deletion src/utils/__tests__/is-falsy.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*/

import VEHICLE from '#fixtures/vehicle'
import constant from '../constant'
import testSubject from '../is-falsy'

describe('unit:utils/isFalsy', () => {
Expand All @@ -13,7 +14,7 @@ describe('unit:utils/isFalsy', () => {
[1],
[true],
[VEHICLE],
[() => 'hello, world']
[constant('hello, world')]
]

// Act + Expect
Expand Down
13 changes: 1 addition & 12 deletions src/utils/is-falsy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@
*/

import type { Falsy } from '#src/types'
import includes from './includes'
import isEmptyValue from './is-empty-value'
import isFalse from './is-false'
import isNaN from './is-nan'

/**
* Checks if `value` is {@linkcode Falsy}.
Expand All @@ -27,13 +23,6 @@ import isNaN from './is-nan'
* @param {unknown} value - Value to check
* @return {value is Falsy} `true` if `value` is falsy
*/
const isFalsy = (value: unknown): value is Falsy => {
return (
isEmptyValue(value) ||
isFalse(value) ||
isNaN(value) ||
includes([0, 0n], value)
)
}
const isFalsy = (value: unknown): value is Falsy => (value ? false : true)

export default isFalsy

0 comments on commit de4e3df

Please sign in to comment.