UNPKG

@intlayer/core

Version:

Includes core Intlayer functions like translation, dictionary, and utility functions shared across multiple packages.

29 lines 1.04 kB
import configuration from "@intlayer/config/built"; import { checkIsURLAbsolute } from "../utils/checkIsURLAbsolute.mjs"; const getPathWithoutLocale = (inputUrl, locales = configuration.internationalization.locales) => { const isAbsoluteUrl = checkIsURLAbsolute(inputUrl); let fixedInputUrl = inputUrl; if (inputUrl.endsWith("/")) { fixedInputUrl = inputUrl.slice(0, -1); } const url = isAbsoluteUrl ? new URL(fixedInputUrl) : new URL(fixedInputUrl, "http://example.com"); const pathname = url.pathname; if (!pathname.startsWith("/")) { url.pathname = `/${pathname}`; } const pathSegments = pathname.split("/"); const firstSegment = pathSegments[1]; if (locales.includes(firstSegment)) { pathSegments.splice(1, 1); const newPathname = pathSegments.join("/") ?? "/"; url.pathname = newPathname; } if (isAbsoluteUrl) { return url.toString(); } return url.toString().replace("http://example.com", ""); }; export { getPathWithoutLocale }; //# sourceMappingURL=getPathWithoutLocale.mjs.map