Skip to content
This repository has been archived by the owner on Jan 14, 2025. It is now read-only.

Commit

Permalink
[No Ticket] Add onNonNull
Browse files Browse the repository at this point in the history
  • Loading branch information
mschuwalow committed Jan 22, 2024
1 parent dff066c commit e5253b5
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ export const UUID = '[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12
const uuidRegex = new RegExp(`^${UUID}$`, 'i')
const hasTrim = !!String.prototype.trim

export function onNonNull<A, B>(value: A, fn: (value: NonNullable<A>) => B): null | undefined | B {
return value != null ? fn(value) : (value as null | undefined)
}

export function safeToString(value: unknown): string {
return typeof value === 'object' ? JSON.stringify(value) : ('' + value)
}
Expand Down

0 comments on commit e5253b5

Please sign in to comment.