Skip to content

Commit

Permalink
Merge pull request #36 from educorvi/develop
Browse files Browse the repository at this point in the history
fix
  • Loading branch information
neferin12 authored Sep 6, 2024
2 parents 15a4ac5 + 0d3ac03 commit 171e38e
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 12 deletions.
10 changes: 10 additions & 0 deletions common/changes/@educorvi/rita/develop_2024-09-06-13-59.json
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"
}
26 changes: 14 additions & 12 deletions rita-core/src/Assertions.ts
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()
);
}
}

0 comments on commit 171e38e

Please sign in to comment.