-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
suggester: treat null and undefined as the same in eq check
- Loading branch information
Showing
5 changed files
with
35 additions
and
7 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,14 @@ | ||
import {eq} from './eq' | ||
|
||
describe('EQ', () => { | ||
test('EQ', () => { | ||
expect(eq(undefined, undefined)).toBeTruthy() | ||
expect(eq(undefined, null)).toBeTruthy() | ||
expect(eq(null, undefined)).toBeTruthy() | ||
expect(eq(null, null)).toBeTruthy() | ||
expect(eq(1, 1)).toBeTruthy() | ||
expect(eq(1, 2)).toBeFalsy() | ||
expect(eq(2, 1)).toBeFalsy() | ||
expect(eq(1, '1')).toBeFalsy() | ||
}) | ||
}) |
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,13 @@ | ||
// eq is an equality check, but treats null and undefined as equal | ||
export const eq = ( | ||
a: number | undefined | null | string, | ||
b: number | undefined | null | string | ||
): boolean => { | ||
if (a === null) { | ||
a = undefined | ||
} | ||
if (b === null) { | ||
b = undefined | ||
} | ||
return a === b | ||
} |
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 @@ | ||
export * from './eq' |
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