CoolFace
Datasetpublic

basant307/AI_Governance_Project

sourceHugging Faceapache-2.0updated 2mo agoView on Hugging Face
0likes48downloads
utils.cjs83 linesDownload Raw Back to dist
1'use strict';2 3const _path = require('./shared/pathe.BSlhyZSM.cjs');4 5const pathSeparators = /* @__PURE__ */ new Set(["/", "\\", void 0]);6const normalizedAliasSymbol = Symbol.for("pathe:normalizedAlias");7const SLASH_RE = /[/\\]/;8function normalizeAliases(_aliases) {9  if (_aliases[normalizedAliasSymbol]) {10    return _aliases;11  }12  const aliases = Object.fromEntries(13    Object.entries(_aliases).sort(([a], [b]) => _compareAliases(a, b))14  );15  for (const key in aliases) {16    for (const alias in aliases) {17      if (alias === key || key.startsWith(alias)) {18        continue;19      }20      if (aliases[key]?.startsWith(alias) && pathSeparators.has(aliases[key][alias.length])) {21        aliases[key] = aliases[alias] + aliases[key].slice(alias.length);22      }23    }24  }25  Object.defineProperty(aliases, normalizedAliasSymbol, {26    value: true,27    enumerable: false28  });29  return aliases;30}31function resolveAlias(path, aliases) {32  const _path$1 = _path.normalizeWindowsPath(path);33  aliases = normalizeAliases(aliases);34  for (const [alias, to] of Object.entries(aliases)) {35    if (!_path$1.startsWith(alias)) {36      continue;37    }38    const _alias = hasTrailingSlash(alias) ? alias.slice(0, -1) : alias;39    if (hasTrailingSlash(_path$1[_alias.length])) {40      return _path.join(to, _path$1.slice(alias.length));41    }42  }43  return _path$1;44}45function reverseResolveAlias(path, aliases) {46  const _path$1 = _path.normalizeWindowsPath(path);47  aliases = normalizeAliases(aliases);48  const matches = [];49  for (const [to, alias] of Object.entries(aliases)) {50    if (!_path$1.startsWith(alias)) {51      continue;52    }53    const _alias = hasTrailingSlash(alias) ? alias.slice(0, -1) : alias;54    if (hasTrailingSlash(_path$1[_alias.length])) {55      matches.push(_path.join(to, _path$1.slice(alias.length)));56    }57  }58  return matches.sort((a, b) => b.length - a.length);59}60function filename(path) {61  const base = path.split(SLASH_RE).pop();62  if (!base) {63    return void 0;64  }65  const separatorIndex = base.lastIndexOf(".");66  if (separatorIndex <= 0) {67    return base;68  }69  return base.slice(0, separatorIndex);70}71function _compareAliases(a, b) {72  return b.split("/").length - a.split("/").length;73}74function hasTrailingSlash(path = "/") {75  const lastChar = path[path.length - 1];76  return lastChar === "/" || lastChar === "\\";77}78 79exports.filename = filename;80exports.normalizeAliases = normalizeAliases;81exports.resolveAlias = resolveAlias;82exports.reverseResolveAlias = reverseResolveAlias;83 
basant307/AI_Governance_Project · CoolFace