All files / app/lib utils.ts

100% Statements 13/13
100% Branches 4/4
100% Functions 5/5
100% Lines 13/13

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 3088x 88x 88x 88x 88x     88x   92x       508x       297x     88x   52x     88x   20x    
export const newline = /[\r\n]+/
export const wildcard = /\*/
export const wildcards = /\*/g
export const special = /([\[\]\(\)*?^$.+])/g
export const termBounds = /^;|;$/g
export type CommonExpansions = {[index: string]: {root: string; part: string}}
 
const special_limited = /([\[\]\(\)?^$.+])/g
export function globToRegex(term: string) {
  return ';' + term.replace(special_limited, '\\$&').replace(wildcards, '[^;]*') + ';'
}
 
export function sortByLength(a: string, b: string) {
  return a.length - b.length
}
 
export function relativeFrequency(index: number, n?: number) {
  return n && -1 !== index ? (1 - index / n) * 100 : 0
}
 
const regexDots = /\./g
export function prepareRegex(term: string) {
  return ';' + term.replace(regexDots, '[^;]') + ';'
}
 
const filePath = /^.*[/\\]/
export function fileBaseName(file: string) {
  return file.replace(filePath, '')
}