All files / src/utils UrlSubpathCompilerCallback.ts

63.26% Statements 31/49
100% Branches 0/0
0% Functions 0/9
63.26% Lines 31/49

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 36 37 38 39 40 41 42 43 44 45 46 47 48 49 501x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x     1x 1x     1x 1x     1x 1x     1x 1x     1x 1x     1x 1x     1x 1x     1x 1x     1x  
/*
 * Keyman is copyright (C) SIL Global. MIT License.
 *
 * URL-style path manipulation functions (OS-independent)
 */
import path from 'path-browserify';
import { CompilerPathCallbacks } from "../compiler-callbacks.js";
 
/**
 * Helper to replace all backslashes with forward slashes,
 * before passing to posix path module
 */
export class UrlSubpathCompilerCallback implements CompilerPathCallbacks {
  private normalizeSlashes(path: string): string {
    return path.replaceAll(/\\/g, '/');
  }
 
  dirname(name: string): string {
    return path.dirname(this.normalizeSlashes(name));
  }
 
  extname(name: string): string {
    return path.extname(this.normalizeSlashes(name));
  }
 
  basename(name: string, ext?: string): string {
    return path.basename(this.normalizeSlashes(name), ext);
  }
 
  isAbsolute(name: string): boolean {
    return path.isAbsolute(this.normalizeSlashes(name));
  }
 
  join(...paths: string[]): string {
    return path.join(...paths.map(this.normalizeSlashes));
  }
 
  normalize(p: string): string {
    return path.normalize(this.normalizeSlashes(p));
  }
 
  relative(from: string, to: string): string {
    return path.relative(this.normalizeSlashes(from), this.normalizeSlashes(to));
  }
 
  resolve(...args: string[]): string {
    return path.resolve(...args.map(this.normalizeSlashes));
  }
}