-
Notifications
You must be signed in to change notification settings - Fork 225
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
clean up usage of null/undefined (#380)
* Make usage of null/undefined more consistent. Primarily allowing either value for user input. * add explicit return type to canonicalDomain * add note for weird parse behavior * Update lib/cookie/cookie.ts Co-authored-by: Colin Casey <[email protected]> * Replace `Nullable<T>` with more precise `T | undefined` * add a bit of breathing room to the file size * Change `parse` to only return undefined on failure, nut null | undefined. * standardize helpers on returning undefined * update doc for return type * change fromJSON to return undefined instead of null * fix incorrect comparison * change date helpers to avoid null, for consistency * update fromJSON tests for new return type * Make test assertions more strict Apply suggestions from code review Co-authored-by: Colin Casey <[email protected]> --------- Co-authored-by: Colin Casey <[email protected]>
- Loading branch information
1 parent
e2151b6
commit a48c867
Showing
16 changed files
with
204 additions
and
199 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
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
import type { Nullable } from '../utils' | ||
import { canonicalDomain } from './canonicalDomain' | ||
|
||
// Dumped from [email protected], with the following changes: | ||
|
@@ -9,16 +10,16 @@ const IP_REGEX_LOWERCASE = | |
|
||
// S5.1.3 Domain Matching | ||
export function domainMatch( | ||
str?: string | null, | ||
domStr?: string | null, | ||
str?: Nullable<string>, | ||
domStr?: Nullable<string>, | ||
canonicalize?: boolean, | ||
): boolean | null { | ||
): boolean | undefined { | ||
if (str == null || domStr == null) { | ||
return null | ||
return undefined | ||
} | ||
|
||
let _str: string | null | ||
let _domStr: string | null | ||
let _str: Nullable<string> | ||
let _domStr: Nullable<string> | ||
|
||
if (canonicalize !== false) { | ||
_str = canonicalDomain(str) | ||
|
@@ -29,7 +30,7 @@ export function domainMatch( | |
} | ||
|
||
if (_str == null || _domStr == null) { | ||
return null | ||
return undefined | ||
} | ||
|
||
/* | ||
|
Oops, something went wrong.