CoolFace
Apppublic

AK-21/Graphite-Industrial-Intelligence

sourceHugging Faceupdated 3mo agoView on Hugging Face
0likes
paths.js39 linesDownload Raw Back to src
1/*2 * Transforms `path` into its relative `base` version3 * If base isn't part of the path provided returns absolute path e.g. `~/app`4 */5const _relativePath = (base, path) =>6  !path.toLowerCase().indexOf(base.toLowerCase())7    ? path.slice(base.length) || "/"8    : "~" + path;9 10/**11 * When basepath is `undefined` or '/' it is ignored (we assume it's empty string)12 */13const baseDefaults = (base = "") => (base === "/" ? "" : base);14 15export const absolutePath = (to, base) =>16  to[0] === "~" ? to.slice(1) : baseDefaults(base) + to;17 18export const relativePath = (base = "", path) =>19  _relativePath(unescape(baseDefaults(base)), unescape(path));20 21/*22 * Removes leading question mark23 */24const stripQm = (str) => (str[0] === "?" ? str.slice(1) : str);25 26/*27 * decodes escape sequences such as %2028 */29const unescape = (str) => {30  try {31    return decodeURI(str);32  } catch (_e) {33    // fail-safe mode: if string can't be decoded do nothing34    return str;35  }36};37 38export const sanitizeSearch = (search) => unescape(stripQm(search));39