{"ast":null,"code":"function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }\n\nfunction _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }\n\nfunction _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }\n\n/* eslint-disable @typescript-eslint/no-explicit-any */\nimport { format as formatUrl, parse as parseUrl } from 'url';\nimport { removeSubpath, subpathFromLng, subpathIsPresent, subpathIsRequired } from './index';\n\nconst parseAs = (originalAs, href) => {\n  const asType = typeof originalAs;\n  let as;\n\n  if (asType === 'undefined') {\n    as = formatUrl(href, {\n      unicode: true\n    });\n  } else if (asType === 'string') {\n    as = originalAs;\n  } else {\n    throw new Error(`'as' type must be 'string', but it is ${asType}`);\n  }\n\n  return as;\n};\n\nconst parseHref = originalHref => {\n  const hrefType = typeof originalHref;\n  let href;\n\n  if (hrefType === 'string') {\n    href = parseUrl(originalHref, true\n    /* parseQueryString */\n    );\n  } else if (hrefType === 'object') {\n    href = _objectSpread({}, originalHref);\n    href.query = originalHref.query ? _objectSpread({}, originalHref.query) : {};\n  } else {\n    throw new Error(`'href' type must be either 'string' or 'object', but it is ${hrefType}`);\n  }\n\n  return href;\n};\n\nexport const lngPathCorrector = (config, currentRoute, currentLanguage) => {\n  const {\n    allLanguages,\n    localeSubpaths\n  } = config;\n  const {\n    as: originalAs,\n    href: originalHref\n  } = currentRoute;\n\n  if (!allLanguages.includes(currentLanguage)) {\n    throw new Error('Invalid configuration: Current language is not included in all languages array');\n  }\n\n  const href = parseHref(originalHref);\n  let as = parseAs(originalAs, href);\n  /*\n  url.format prefers the 'url.search' string over\n  the 'url.query' object, so remove the search\n  string to ensure the query object is used.\n  */\n\n  delete href.search;\n  /*\n  Strip any/all subpaths from the `as` value\n  */\n\n  Object.values(localeSubpaths || {}).forEach(subpath => {\n    if (subpathIsPresent(as, subpath)) {\n      as = removeSubpath(as, subpath);\n    }\n  });\n\n  if (subpathIsRequired(config, currentLanguage)) {\n    var _as;\n\n    const basePath = `${href.protocol}//${href.host}`;\n    const currentAs = (_as = as) === null || _as === void 0 ? void 0 : _as.replace(basePath, '');\n    const subpath = subpathFromLng(config, currentLanguage);\n    as = `/${subpath}${currentAs}`.replace(/\\/$/, '');\n    href.query.lng = currentLanguage;\n    href.query.subpath = subpath;\n  }\n\n  return {\n    as,\n    href\n  };\n};","map":null,"metadata":{},"sourceType":"module"}