All files / src/common type-checks.ts

0% Statements 0/19
0% Branches 0/9
0% Functions 0/8
0% Lines 0/18

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35                                                                     
export const isDefined = <T>(val: T | undefined): val is T => {
  return val !== undefined
}
 
export const notNull = <T>(val: T | null): val is T => {
  return val !== null
}
 
export const isJust = notNull
 
export const isValue = <T>(val: T | undefined | null): val is T => {
  return isDefined(val) && notNull(val)
}
 
export const isBool = (val: unknown): val is boolean => {
  return typeof val === 'boolean'
}
 
export const isNum = (val: unknown): val is number => {
  return typeof val === 'number'
}
 
export const isString = (val: unknown): val is string => {
  return typeof val === 'string'
}
 
export const isObject = <T>(val: unknown): val is Record<string, T> => {
  return val !== null && typeof val === 'object'
}
 
export const isBlob = (val: unknown): val is Blob => {
  if (typeof Blob === 'undefined') return false
  return val instanceof Blob || (isObject(val) && val?.constructor?.name === 'Blob')
}