{
  "version": 3,
  "sources": ["../../src/node/path.ts"],
  "sourcesContent": ["// Copyright Joyent, Inc. and other Node contributors.\n//\n// Permission is hereby granted, free of charge, to any person obtaining a\n// copy of this software and associated documentation files (the\n// \"Software\"), to deal in the Software without restriction, including\n// without limitation the rights to use, copy, modify, merge, publish,\n// distribute, sublicense, and/or sell copies of the Software, and to permit\n// persons to whom the Software is furnished to do so, subject to the\n// following conditions:\n//\n// The above copyright notice and this permission notice shall be included\n// in all copies or substantial portions of the Software.\n//\n// THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS\n// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\n// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN\n// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,\n// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR\n// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE\n// USE OR OTHER DEALINGS IN THE SOFTWARE.\n\n// resolves . and .. elements in a path array with directory names there\n// must be no slashes, empty elements, or device names (c:\\) in the array\n// (so also no leading and trailing slashes - it does not distinguish\n// relative and absolute paths)\n\n// !! WARNING !!\n// The original implementation included ponyfills for `filters` and `substr`.\n// These have been removed in favor of native implementations supported by the current platforms.\n// See: https://github.com/scalar/scalar/pull/7235#discussion_r2484230212\n\nfunction normalizeArray(parts: Array<string>, allowAboveRoot: boolean): Array<string> {\n  // if the path tries to go above the root, `up` ends up > 0\n  let up = 0\n  for (let i = parts.length - 1; i >= 0; i--) {\n    const last = parts[i]\n    if (last === '.') {\n      parts.splice(i, 1)\n    } else if (last === '..') {\n      parts.splice(i, 1)\n      up++\n    } else if (up) {\n      parts.splice(i, 1)\n      up--\n    }\n  }\n\n  // if the path is allowed to go above the root, restore leading ..s\n  if (allowAboveRoot) {\n    for (; up--; up) {\n      parts.unshift('..')\n    }\n  }\n\n  return parts\n}\n\n// Split a filename into [root, dir, basename, ext], unix version\n// 'root' is just a slash, or nothing.\nconst splitPathRe = /^(\\/?|)([\\s\\S]*?)((?:\\.{1,2}|[^/]+?|)(\\.[^./]*|))(?:[/]*)$/\nconst splitPath = (filename: string): Array<string> | undefined => splitPathRe.exec(filename)!.slice(1)\n\n// path.resolve([from ...], to)\n// posix version\nexport function resolve(...parameters: Array<string>) {\n  let resolvedPath = '',\n    resolvedAbsolute = false\n\n  for (let i = parameters.length - 1; i >= -1 && !resolvedAbsolute; i--) {\n    const path = i >= 0 ? parameters[i] : '/'\n\n    // Skip empty and invalid entries\n    if (typeof path !== 'string') {\n      throw new TypeError('Arguments to path.resolve must be strings')\n    }\n    if (!path) {\n      continue\n    }\n\n    resolvedPath = path + '/' + resolvedPath\n    resolvedAbsolute = path.charAt(0) === '/'\n  }\n\n  // At this point the path should be resolved to a full absolute path, but\n  // handle relative paths to be safe (might happen when process.cwd() fails)\n\n  // Normalize the path\n  resolvedPath = normalizeArray(\n    resolvedPath.split('/').filter((p) => !!p),\n    !resolvedAbsolute,\n  ).join('/')\n\n  return (resolvedAbsolute ? '/' : '') + resolvedPath || '.'\n}\n\n// path.normalize(path)\n// posix version\nexport function normalize(inputPath: string): string {\n  const isPathAbsolute = isAbsolute(inputPath),\n    trailingSlash = inputPath.slice(-1) === '/'\n\n  // Normalize the path\n  let path = normalizeArray(\n    inputPath.split('/').filter((p) => !!p),\n    !isPathAbsolute,\n  ).join('/')\n\n  if (!path && !isPathAbsolute) {\n    path = '.'\n  }\n  if (path && trailingSlash) {\n    path += '/'\n  }\n\n  return (isPathAbsolute ? '/' : '') + path\n}\n\n// posix version\nexport function isAbsolute(path: string): boolean {\n  return path.charAt(0) === '/'\n}\n\n// posix version\nexport function join(...paths: string[]) {\n  return normalize(\n    paths\n      .filter((p) => {\n        if (typeof p !== 'string') {\n          throw new TypeError('Arguments to path.join must be strings')\n        }\n        return p\n      })\n      .join('/'),\n  )\n}\n\n// path.relative(from, to)\n// posix version\nexport function relative(from: string, to: string) {\n  const fromResolved = resolve(from).substring(1)\n  const toResolved = resolve(to).substring(1)\n\n  function trim(arr: Array<string>): Array<string> {\n    let start = 0\n    for (; start < arr.length; start++) {\n      if (arr[start] !== '') {\n        break\n      }\n    }\n\n    let end = arr.length - 1\n    for (; end >= 0; end--) {\n      if (arr[end] !== '') {\n        break\n      }\n    }\n\n    if (start > end) {\n      return []\n    }\n    return arr.slice(start, end - start + 1)\n  }\n\n  const fromParts = trim(fromResolved.split('/'))\n  const toParts = trim(toResolved.split('/'))\n\n  const length = Math.min(fromParts.length, toParts.length)\n  let samePartsLength = length\n  for (let i = 0; i < length; i++) {\n    if (fromParts[i] !== toParts[i]) {\n      samePartsLength = i\n      break\n    }\n  }\n\n  let outputParts = []\n  for (let i = samePartsLength; i < fromParts.length; i++) {\n    outputParts.push('..')\n  }\n\n  outputParts = outputParts.concat(toParts.slice(samePartsLength))\n\n  return outputParts.join('/')\n}\n\nexport const sep = '/'\nexport const delimiter = ':'\n\nexport function dirname(path: string): string {\n  const result = splitPath(path) as Array<string>\n  const root = result[0]\n  let dir = result[1]\n\n  if (!root && !dir) {\n    // No dirname whatsoever\n    return '.'\n  }\n\n  if (dir) {\n    // It has a dirname, strip trailing slash\n    dir = dir.slice(0, -1)\n  }\n\n  return (root as string) + dir\n}\n\nexport function basename(path: string, ext?: string): string {\n  let f = splitPath(path)![2] as string\n  // TODO: make this comparison case-insensitive on windows?\n  if (ext && f.slice(-ext.length) === ext) {\n    f = f.slice(0, -ext.length)\n  }\n  return f\n}\n\nexport function extname(path: string): string {\n  return splitPath(path)![3] as string\n}\n\nexport const path = {\n  extname,\n  basename,\n  dirname,\n  sep,\n  delimiter,\n  relative,\n  join,\n  isAbsolute,\n  normalize,\n  resolve,\n}\n"],
  "mappings": "AA+BA,SAAS,eAAe,OAAsB,gBAAwC;AAEpF,MAAI,KAAK;AACT,WAAS,IAA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