All files / src fallback.ts

83.33% Statements 5/6
100% Branches 2/2
100% Functions 1/1
80% Lines 4/5

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 1222x         22x 105x       105x  
import S from './sanitised.js'
import type Sid from './sanitised-identifier.js'
 
/** @returns sanitised value as is, otherwise falls back to provided sanitation function. */
export const fallback =
  <T>(x: T, f: (_: Exclude<T, S | Sid>) => undefined | S): undefined | S =>
    x instanceof S ?
      x :
      f(x as Exclude<T, S | Sid>)
 
export default fallback