-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #36 from educorvi/develop
fix
- Loading branch information
Showing
2 changed files
with
24 additions
and
12 deletions.
There are no files selected for viewing
10 changes: 10 additions & 0 deletions
10
common/changes/@educorvi/rita/develop_2024-09-06-13-59.json
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,10 @@ | ||
{ | ||
"changes": [ | ||
{ | ||
"packageName": "@educorvi/rita", | ||
"comment": "don't fail on error due to calling `toString()` on undefined", | ||
"type": "patch" | ||
} | ||
], | ||
"packageName": "@educorvi/rita" | ||
} |
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,43 +1,45 @@ | ||
import { Duration } from 'luxon'; | ||
|
||
export function assertBoolean(value: any): asserts value is boolean { | ||
export function assertBoolean(value: unknown): asserts value is boolean { | ||
if (typeof value !== 'boolean') { | ||
throw new TypeError('Value is not a boolean: ' + value.toString()); | ||
throw new TypeError('Value is not a boolean: ' + value?.toString()); | ||
} | ||
} | ||
|
||
export function assertNumber(value: any): asserts value is number { | ||
export function assertNumber(value: unknown): asserts value is number { | ||
if (typeof value !== 'number') { | ||
throw new TypeError('Value is not a number: ' + value.toString()); | ||
throw new TypeError('Value is not a number: ' + value?.toString()); | ||
} | ||
} | ||
|
||
export function assertDate(value: any): asserts value is Date { | ||
export function assertDate(value: unknown): asserts value is Date { | ||
if (!(value instanceof Date)) { | ||
throw new TypeError('Value is not a date: ' + value.toString()); | ||
throw new TypeError('Value is not a date: ' + value?.toString()); | ||
} | ||
} | ||
|
||
export function assertNumberOrDate(value: any): asserts value is number | Date { | ||
export function assertNumberOrDate( | ||
value: unknown | ||
): asserts value is number | Date { | ||
if (!(typeof value === 'number' || value instanceof Date)) { | ||
throw new TypeError( | ||
'Value is neither a number nor a data: ' + value.toString() | ||
'Value is neither a number nor a data: ' + value?.toString() | ||
); | ||
} | ||
} | ||
|
||
export function assertDuration(value: any): asserts value is Duration { | ||
export function assertDuration(value: unknown): asserts value is Duration { | ||
if (!Duration.isDuration(value)) { | ||
throw new TypeError('Value is not a duration: ' + value.toString()); | ||
throw new TypeError('Value is not a duration: ' + value?.toString()); | ||
} | ||
} | ||
|
||
export function hasLength( | ||
value: any | ||
value: unknown | ||
): asserts value is Record<any, any> & { length: number } { | ||
if (!value || !value.hasOwnProperty('length')) { | ||
throw new TypeError( | ||
'Value does not have a length property: ' + value.toString() | ||
'Value does not have a length property: ' + value?.toString() | ||
); | ||
} | ||
} |