@camox/api-contract 0.62.0 → 0.63.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/locales.d.ts CHANGED
@@ -16,6 +16,8 @@ export type LocalePath = {
16
16
  };
17
17
  /** A locale's URL prefix: its tag in lowercase. The default locale has none. */
18
18
  export declare function localePrefix(locale: LocaleView): string;
19
+ /** A locale-relative path under its locale's prefix, keeping its search and hash: `/` is `/de`. */
20
+ export declare function localizedPath(path: string, locale: LocaleView): string;
19
21
  /**
20
22
  * The locale a runtime path names, and the path after its prefix, without search or hash. A first
21
23
  * segment that isn't a non-default locale's prefix leaves the path the default locale's. A
package/dist/locales.js CHANGED
@@ -3,6 +3,12 @@
3
3
  function localePrefix(locale) {
4
4
  return locale.isDefault ? "" : `/${locale.tag.toLowerCase()}`;
5
5
  }
6
+ /** A locale-relative path under its locale's prefix, keeping its search and hash: `/` is `/de`. */
7
+ function localizedPath(path, locale) {
8
+ const prefix = localePrefix(locale);
9
+ if (!prefix) return path;
10
+ return path === "/" || /^\/[?#]/.test(path) ? `${prefix}${path.slice(1)}` : `${prefix}${path}`;
11
+ }
6
12
  /**
7
13
  * The locale a runtime path names, and the path after its prefix, without search or hash. A first
8
14
  * segment that isn't a non-default locale's prefix leaves the path the default locale's. A
@@ -26,4 +32,4 @@ function parseLocalePath(pathname, locales) {
26
32
  }
27
33
 
28
34
  //#endregion
29
- export { localePrefix, parseLocalePath };
35
+ export { localePrefix, localizedPath, parseLocalePath };