-
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.
- Loading branch information
ljdavies
committed
Apr 27, 2020
1 parent
2469c1f
commit 3ea3144
Showing
20 changed files
with
297 additions
and
296 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
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 |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/** | ||
* Assert that a value passed equals either null or undefined | ||
* | ||
* @param {any} val | ||
* @param {string} message | ||
*/ | ||
export const assertDoesntExist: (val: any, message?: string) => asserts val is null | undefined = ( | ||
val: any, | ||
message?: string | ||
): asserts val is null | undefined => { | ||
if (!(val === undefined || val === null)) { | ||
throw new Error(message); | ||
} | ||
}; | ||
|
||
/** | ||
* Asser that the value passed is not null or undefined | ||
* | ||
* @param {T} val | ||
* @param {string} message | ||
*/ | ||
export const assertExists: <T>(val: T, message?: string) => asserts val is NonNullable<T> = <T>( | ||
val: T, | ||
message?: string | ||
): asserts val is NonNullable<T> => { | ||
if (val === undefined || val === null) { | ||
throw new Error(message); | ||
} | ||
}; | ||
|
||
/** | ||
* Assert that at least one of the values passed is not null or undefined | ||
* | ||
* @param {Array<T>} val | ||
* @param {string} message | ||
*/ | ||
export const assertOneExists: <T>(val: Array<T>, message?: string) => asserts val is T[] = <T>( | ||
val: Array<T>, | ||
message?: string | ||
): asserts val is T[] => { | ||
for (const item of val) { | ||
if (item !== undefined && item !== null) { | ||
return; | ||
} | ||
} | ||
throw new Error(message); | ||
}; |
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
Oops, something went wrong.