@prezly/theme-kit-core 7.0.0 → 8.0.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/build/boilerplate.cjs +17 -0
- package/build/boilerplate.d.ts +8 -0
- package/build/boilerplate.mjs +9 -0
- package/build/constants.cjs +11 -0
- package/build/{utils/constants.d.ts → constants.d.ts} +2 -1
- package/build/constants.mjs +5 -0
- package/build/content-delivery/ContentDelivery.cjs +348 -0
- package/build/content-delivery/ContentDelivery.d.ts +8 -4
- package/build/content-delivery/ContentDelivery.mjs +342 -0
- package/build/content-delivery/cache/index.cjs +35 -0
- package/build/content-delivery/cache/index.d.ts +3 -0
- package/build/content-delivery/cache/index.mjs +3 -0
- package/build/content-delivery/cache/memory.cjs +64 -0
- package/build/content-delivery/cache/memory.d.ts +2 -0
- package/build/content-delivery/cache/memory.mjs +58 -0
- package/build/content-delivery/cache/stacked.cjs +32 -0
- package/build/content-delivery/cache/stacked.d.ts +2 -0
- package/build/content-delivery/cache/stacked.mjs +26 -0
- package/build/content-delivery/cache/type.cjs +1 -0
- package/build/content-delivery/cache/type.d.ts +8 -0
- package/build/content-delivery/cache/type.mjs +1 -0
- package/build/content-delivery/index.cjs +27 -0
- package/build/content-delivery/index.d.ts +2 -1
- package/build/content-delivery/index.mjs +2 -0
- package/build/environment.cjs +42 -0
- package/build/environment.d.ts +2 -0
- package/build/environment.mjs +36 -0
- package/build/galleries.cjs +38 -0
- package/build/galleries.d.ts +11 -0
- package/build/galleries.mjs +30 -0
- package/build/http/HttpClient.cjs +66 -0
- package/build/http/HttpClient.d.ts +20 -0
- package/build/http/HttpClient.mjs +59 -0
- package/build/http/index.cjs +10 -0
- package/build/http/index.d.ts +1 -0
- package/build/http/index.mjs +2 -0
- package/build/index.cjs +88 -0
- package/build/index.d.ts +15 -4
- package/build/index.mjs +26 -0
- package/build/intl/getLanguageDisplayName.cjs +37 -0
- package/build/intl/getLanguageDisplayName.d.ts +20 -0
- package/build/intl/getLanguageDisplayName.mjs +32 -0
- package/build/intl/getLanguageDisplayName.test.cjs +46 -0
- package/build/intl/getLanguageDisplayName.test.mjs +44 -0
- package/build/intl/index.cjs +12 -0
- package/build/intl/index.d.ts +1 -5
- package/build/intl/index.mjs +1 -0
- package/build/metadata/getAlternateLanguageLinks.cjs +76 -0
- package/build/{seo → metadata}/getAlternateLanguageLinks.d.ts +2 -2
- package/build/metadata/getAlternateLanguageLinks.mjs +72 -0
- package/build/metadata/getAlternateLanguageLinks.test.cjs +198 -0
- package/build/metadata/getAlternateLanguageLinks.test.mjs +196 -0
- package/build/metadata/index.cjs +12 -0
- package/build/metadata/index.d.ts +2 -0
- package/build/metadata/index.mjs +1 -0
- package/build/metadata/types.cjs +1 -0
- package/build/metadata/types.d.ts +6 -0
- package/build/metadata/types.mjs +1 -0
- package/build/newsrooms.cjs +36 -0
- package/build/newsrooms.d.ts +5 -0
- package/build/newsrooms.mjs +28 -0
- package/build/privacy-portal.cjs +28 -0
- package/build/privacy-portal.d.ts +9 -0
- package/build/privacy-portal.mjs +21 -0
- package/build/resolvable.cjs +38 -0
- package/build/resolvable.d.ts +71 -0
- package/build/resolvable.mjs +32 -0
- package/build/routing/Route.cjs +46 -0
- package/build/routing/Route.d.ts +37 -0
- package/build/routing/Route.mjs +40 -0
- package/build/routing/Router.cjs +51 -0
- package/build/routing/Router.d.ts +23 -0
- package/build/routing/Router.mjs +45 -0
- package/build/routing/Routing.cjs +24 -0
- package/build/routing/Routing.d.ts +1 -0
- package/build/routing/Routing.mjs +2 -0
- package/build/routing/UrlGenerator.cjs +13 -0
- package/build/routing/UrlGenerator.d.ts +39 -0
- package/build/routing/UrlGenerator.mjs +7 -0
- package/build/routing/index.cjs +24 -0
- package/build/routing/index.d.ts +4 -0
- package/build/routing/index.mjs +4 -0
- package/build/routing/types.cjs +1 -0
- package/build/routing/types.d.ts +14 -0
- package/build/routing/types.mjs +1 -0
- package/build/routing/utils/generateUrlFromPattern.cjs +52 -0
- package/build/routing/utils/generateUrlFromPattern.d.ts +12 -0
- package/build/routing/utils/generateUrlFromPattern.mjs +47 -0
- package/build/routing/utils/generateUrlFromPattern.test.cjs +44 -0
- package/build/routing/utils/generateUrlFromPattern.test.mjs +42 -0
- package/build/routing/utils/getShortestLocaleSlug.cjs +60 -0
- package/build/routing/utils/getShortestLocaleSlug.d.ts +11 -0
- package/build/routing/utils/getShortestLocaleSlug.mjs +53 -0
- package/build/routing/utils/getShortestLocaleSlug.test.cjs +37 -0
- package/build/routing/utils/getShortestLocaleSlug.test.mjs +35 -0
- package/build/routing/utils/index.cjs +40 -0
- package/build/routing/utils/index.d.ts +5 -0
- package/build/routing/utils/index.mjs +5 -0
- package/build/routing/utils/isNumberCode.cjs +12 -0
- package/build/routing/utils/isNumberCode.d.ts +4 -0
- package/build/routing/utils/isNumberCode.mjs +6 -0
- package/build/routing/utils/matchLocaleSlug.cjs +41 -0
- package/build/routing/utils/matchLocaleSlug.d.ts +15 -0
- package/build/routing/utils/matchLocaleSlug.mjs +34 -0
- package/build/routing/utils/matchLocaleSlug.test.cjs +43 -0
- package/build/routing/utils/matchLocaleSlug.test.mjs +40 -0
- package/build/routing/utils/normalizeUrl.cjs +9 -0
- package/build/routing/utils/normalizeUrl.d.ts +1 -0
- package/build/routing/utils/normalizeUrl.mjs +3 -0
- package/build/search.cjs +1 -0
- package/build/{types.d.ts → search.d.ts} +3 -3
- package/build/search.mjs +1 -0
- package/build/sitemap/build.cjs +33 -0
- package/build/sitemap/build.d.ts +6 -0
- package/build/sitemap/build.mjs +27 -0
- package/build/sitemap/generate.cjs +192 -0
- package/build/sitemap/generate.d.ts +37 -0
- package/build/sitemap/generate.mjs +183 -0
- package/build/sitemap/index.cjs +38 -0
- package/build/sitemap/index.d.ts +4 -0
- package/build/sitemap/index.mjs +3 -0
- package/build/sitemap/stringify.cjs +24 -0
- package/build/sitemap/stringify.d.ts +2 -0
- package/build/sitemap/stringify.mjs +18 -0
- package/build/sitemap/types.cjs +1 -0
- package/build/sitemap/types.d.ts +67 -0
- package/build/sitemap/types.mjs +1 -0
- package/build/uploads.cjs +14 -0
- package/build/{utils/getAssetsUrl.d.ts → uploads.d.ts} +1 -1
- package/build/uploads.mjs +8 -0
- package/build/uploads.test.cjs +10 -0
- package/build/uploads.test.mjs +8 -0
- package/package.json +23 -26
- package/build/content-delivery/ContentDelivery.js +0 -238
- package/build/content-delivery/ContentDelivery.js.map +0 -1
- package/build/content-delivery/index.js +0 -28
- package/build/content-delivery/index.js.map +0 -1
- package/build/data-fetching/api/index.d.ts +0 -1
- package/build/data-fetching/api/index.js +0 -6
- package/build/data-fetching/api/index.js.map +0 -1
- package/build/data-fetching/api/initContentDeliveryClient.d.ts +0 -4
- package/build/data-fetching/api/initContentDeliveryClient.js +0 -25
- package/build/data-fetching/api/initContentDeliveryClient.js.map +0 -1
- package/build/data-fetching/index.d.ts +0 -3
- package/build/data-fetching/index.js +0 -20
- package/build/data-fetching/index.js.map +0 -1
- package/build/data-fetching/lib/getAlgoliaSettings.d.ts +0 -4
- package/build/data-fetching/lib/getAlgoliaSettings.js +0 -21
- package/build/data-fetching/lib/getAlgoliaSettings.js.map +0 -1
- package/build/data-fetching/lib/getEnvVariables.d.ts +0 -4
- package/build/data-fetching/lib/getEnvVariables.js +0 -43
- package/build/data-fetching/lib/getEnvVariables.js.map +0 -1
- package/build/data-fetching/lib/index.d.ts +0 -3
- package/build/data-fetching/lib/index.js +0 -10
- package/build/data-fetching/lib/index.js.map +0 -1
- package/build/data-fetching/lib/isUuid.d.ts +0 -1
- package/build/data-fetching/lib/isUuid.js +0 -9
- package/build/data-fetching/lib/isUuid.js.map +0 -1
- package/build/data-fetching/types.d.ts +0 -13
- package/build/data-fetching/types.js +0 -3
- package/build/data-fetching/types.js.map +0 -1
- package/build/index.js +0 -21
- package/build/index.js.map +0 -1
- package/build/intl/getFallbackLocale.d.ts +0 -10
- package/build/intl/getFallbackLocale.js +0 -24
- package/build/intl/getFallbackLocale.js.map +0 -1
- package/build/intl/index.js +0 -27
- package/build/intl/index.js.map +0 -1
- package/build/intl/languages.d.ts +0 -57
- package/build/intl/languages.js +0 -191
- package/build/intl/languages.js.map +0 -1
- package/build/intl/locale.d.ts +0 -11
- package/build/intl/locale.js +0 -41
- package/build/intl/locale.js.map +0 -1
- package/build/intl/localeConfig.d.ts +0 -2
- package/build/intl/localeConfig.js +0 -22
- package/build/intl/localeConfig.js.map +0 -1
- package/build/intl/localeList.d.ts +0 -2
- package/build/intl/localeList.js +0 -114
- package/build/intl/localeList.js.map +0 -1
- package/build/intl/localeObject.d.ts +0 -51
- package/build/intl/localeObject.js +0 -98
- package/build/intl/localeObject.js.map +0 -1
- package/build/seo/getAlternateLanguageLinks.js +0 -85
- package/build/seo/getAlternateLanguageLinks.js.map +0 -1
- package/build/seo/index.d.ts +0 -2
- package/build/seo/index.js +0 -19
- package/build/seo/index.js.map +0 -1
- package/build/seo/types.d.ts +0 -4
- package/build/seo/types.js +0 -3
- package/build/seo/types.js.map +0 -1
- package/build/seo/utils/bindLanguagesWithLocales.d.ts +0 -11
- package/build/seo/utils/bindLanguagesWithLocales.js +0 -23
- package/build/seo/utils/bindLanguagesWithLocales.js.map +0 -1
- package/build/seo/utils/createAlternateLanguageLink.d.ts +0 -5
- package/build/seo/utils/createAlternateLanguageLink.js +0 -15
- package/build/seo/utils/createAlternateLanguageLink.js.map +0 -1
- package/build/seo/utils/index.d.ts +0 -2
- package/build/seo/utils/index.js +0 -8
- package/build/seo/utils/index.js.map +0 -1
- package/build/server.d.ts +0 -2
- package/build/server.js +0 -21
- package/build/server.js.map +0 -1
- package/build/types.js +0 -3
- package/build/types.js.map +0 -1
- package/build/utils/assertServerEnv.d.ts +0 -1
- package/build/utils/assertServerEnv.js +0 -10
- package/build/utils/assertServerEnv.js.map +0 -1
- package/build/utils/boilerplate.d.ts +0 -8
- package/build/utils/boilerplate.js +0 -27
- package/build/utils/boilerplate.js.map +0 -1
- package/build/utils/constants.js +0 -8
- package/build/utils/constants.js.map +0 -1
- package/build/utils/getAssetsUrl.js +0 -13
- package/build/utils/getAssetsUrl.js.map +0 -1
- package/build/utils/getDataRequestLink.d.ts +0 -3
- package/build/utils/getDataRequestLink.js +0 -12
- package/build/utils/getDataRequestLink.js.map +0 -1
- package/build/utils/getGalleryThumbnail.d.ts +0 -2
- package/build/utils/getGalleryThumbnail.js +0 -15
- package/build/utils/getGalleryThumbnail.js.map +0 -1
- package/build/utils/getLocalizedCategoryData.d.ts +0 -12
- package/build/utils/getLocalizedCategoryData.js +0 -34
- package/build/utils/getLocalizedCategoryData.js.map +0 -1
- package/build/utils/getNewsroomLogoUrl.d.ts +0 -5
- package/build/utils/getNewsroomLogoUrl.js +0 -30
- package/build/utils/getNewsroomLogoUrl.js.map +0 -1
- package/build/utils/getPrivacyPortalUrl.d.ts +0 -8
- package/build/utils/getPrivacyPortalUrl.js +0 -13
- package/build/utils/getPrivacyPortalUrl.js.map +0 -1
- package/build/utils/getStoryPublicationDate.d.ts +0 -3
- package/build/utils/getStoryPublicationDate.js +0 -14
- package/build/utils/getStoryPublicationDate.js.map +0 -1
- package/build/utils/getUploadcareGroupUrl.d.ts +0 -8
- package/build/utils/getUploadcareGroupUrl.js +0 -17
- package/build/utils/getUploadcareGroupUrl.js.map +0 -1
- package/build/utils/index.d.ts +0 -14
- package/build/utils/index.js +0 -31
- package/build/utils/index.js.map +0 -1
- package/build/utils/isEmbargoStory.d.ts +0 -6
- package/build/utils/isEmbargoStory.js +0 -9
- package/build/utils/isEmbargoStory.js.map +0 -1
- package/build/utils/isGalleryEmpty.d.ts +0 -2
- package/build/utils/isGalleryEmpty.js +0 -8
- package/build/utils/isGalleryEmpty.js.map +0 -1
- package/build/utils/sdkHelpers.d.ts +0 -32
- package/build/utils/sdkHelpers.js +0 -42
- package/build/utils/sdkHelpers.js.map +0 -1
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { Locale } from '@prezly/theme-kit-intl';
|
|
2
|
+
export interface Context {
|
|
3
|
+
defaultLocale: Locale.Code;
|
|
4
|
+
locales: Locale.Code[];
|
|
5
|
+
toLocaleSlug?: (locale: Locale.Code, context: Pick<Context, 'defaultLocale' | 'locales'>) => Locale.UrlSlug;
|
|
6
|
+
}
|
|
7
|
+
export type Params = Record<string, string | undefined | null> & ({
|
|
8
|
+
localeCode?: Locale.Code;
|
|
9
|
+
} | {
|
|
10
|
+
localeSlug?: Locale.AnySlug;
|
|
11
|
+
});
|
|
12
|
+
export declare function generateUrlFromPattern(pattern: `/${string}`, params?: Params, context?: Context): `/${string}`;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
2
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
3
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
4
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : String(i); }
|
|
5
|
+
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
6
|
+
/* eslint-disable @typescript-eslint/no-use-before-define */
|
|
7
|
+
|
|
8
|
+
import { omitUndefined } from '@technically/omit-undefined';
|
|
9
|
+
import UrlPattern from 'url-pattern';
|
|
10
|
+
import { getShortestLocaleSlug } from "./getShortestLocaleSlug.mjs";
|
|
11
|
+
import { normalizeUrl } from "./normalizeUrl.mjs";
|
|
12
|
+
var CACHE = new Map();
|
|
13
|
+
function toUrlPattern(pattern) {
|
|
14
|
+
var cached = CACHE.get(pattern);
|
|
15
|
+
if (cached) return cached;
|
|
16
|
+
var urlPattern = new UrlPattern(pattern);
|
|
17
|
+
CACHE.set(pattern, urlPattern);
|
|
18
|
+
return urlPattern;
|
|
19
|
+
}
|
|
20
|
+
export function generateUrlFromPattern(pattern) {
|
|
21
|
+
var params = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
22
|
+
var context = arguments.length > 2 ? arguments[2] : undefined;
|
|
23
|
+
var urlPattern = toUrlPattern(pattern);
|
|
24
|
+
if (context) {
|
|
25
|
+
var {
|
|
26
|
+
localeCode
|
|
27
|
+
} = params;
|
|
28
|
+
var localeSlug = getLocaleSlug(params, context);
|
|
29
|
+
return normalizeUrl(urlPattern.stringify(omitUndefined(_objectSpread(_objectSpread({}, params), {}, {
|
|
30
|
+
localeCode,
|
|
31
|
+
localeSlug
|
|
32
|
+
}))));
|
|
33
|
+
}
|
|
34
|
+
return normalizeUrl(urlPattern.stringify(omitUndefined(params)));
|
|
35
|
+
}
|
|
36
|
+
function getLocaleSlug(params, context) {
|
|
37
|
+
if (params.localeSlug) {
|
|
38
|
+
return params.localeSlug;
|
|
39
|
+
}
|
|
40
|
+
if (params.localeCode) {
|
|
41
|
+
var {
|
|
42
|
+
toLocaleSlug = getShortestLocaleSlug
|
|
43
|
+
} = context;
|
|
44
|
+
return toLocaleSlug(params.localeCode, context) || '';
|
|
45
|
+
}
|
|
46
|
+
return '';
|
|
47
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _generateUrlFromPattern = require("./generateUrlFromPattern.cjs");
|
|
4
|
+
describe('generateUrlFromPattern', () => {
|
|
5
|
+
it('should generate a URL (without context)', () => {
|
|
6
|
+
var href = (0, _generateUrlFromPattern.generateUrlFromPattern)('/:localeCode/media', {
|
|
7
|
+
localeCode: 'en'
|
|
8
|
+
});
|
|
9
|
+
expect(href).toBe('/en/media');
|
|
10
|
+
});
|
|
11
|
+
it('should generate a URL with optional variables (without context)', () => {
|
|
12
|
+
var href = (0, _generateUrlFromPattern.generateUrlFromPattern)('/(:localeSlug/)media', {
|
|
13
|
+
localeSlug: ''
|
|
14
|
+
});
|
|
15
|
+
expect(href).toBe('/media');
|
|
16
|
+
});
|
|
17
|
+
it('should generate a URL based on the current locale', () => {
|
|
18
|
+
var href = (0, _generateUrlFromPattern.generateUrlFromPattern)('/(:localeSlug/)media', {
|
|
19
|
+
localeCode: 'fr'
|
|
20
|
+
}, {
|
|
21
|
+
defaultLocale: 'en',
|
|
22
|
+
locales: ['en', 'nl', 'fr']
|
|
23
|
+
});
|
|
24
|
+
expect(href).toBe('/fr/media');
|
|
25
|
+
});
|
|
26
|
+
it('should generate a homepage URL based on the current locale', () => {
|
|
27
|
+
var href = (0, _generateUrlFromPattern.generateUrlFromPattern)('/(:localeSlug/)media', {
|
|
28
|
+
localeCode: 'en'
|
|
29
|
+
}, {
|
|
30
|
+
defaultLocale: 'en',
|
|
31
|
+
locales: ['en', 'nl', 'fr']
|
|
32
|
+
});
|
|
33
|
+
expect(href).toBe('/media');
|
|
34
|
+
});
|
|
35
|
+
it('should generate a shortest possible locale slug', () => {
|
|
36
|
+
var href = (0, _generateUrlFromPattern.generateUrlFromPattern)('/(:localeSlug/)media', {
|
|
37
|
+
localeCode: 'nl_BE'
|
|
38
|
+
}, {
|
|
39
|
+
defaultLocale: 'en_US',
|
|
40
|
+
locales: ['en_US', 'nl_BE', 'fr_FR']
|
|
41
|
+
});
|
|
42
|
+
expect(href).toBe('/nl/media');
|
|
43
|
+
});
|
|
44
|
+
});
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { generateUrlFromPattern } from "./generateUrlFromPattern.mjs";
|
|
2
|
+
describe('generateUrlFromPattern', () => {
|
|
3
|
+
it('should generate a URL (without context)', () => {
|
|
4
|
+
var href = generateUrlFromPattern('/:localeCode/media', {
|
|
5
|
+
localeCode: 'en'
|
|
6
|
+
});
|
|
7
|
+
expect(href).toBe('/en/media');
|
|
8
|
+
});
|
|
9
|
+
it('should generate a URL with optional variables (without context)', () => {
|
|
10
|
+
var href = generateUrlFromPattern('/(:localeSlug/)media', {
|
|
11
|
+
localeSlug: ''
|
|
12
|
+
});
|
|
13
|
+
expect(href).toBe('/media');
|
|
14
|
+
});
|
|
15
|
+
it('should generate a URL based on the current locale', () => {
|
|
16
|
+
var href = generateUrlFromPattern('/(:localeSlug/)media', {
|
|
17
|
+
localeCode: 'fr'
|
|
18
|
+
}, {
|
|
19
|
+
defaultLocale: 'en',
|
|
20
|
+
locales: ['en', 'nl', 'fr']
|
|
21
|
+
});
|
|
22
|
+
expect(href).toBe('/fr/media');
|
|
23
|
+
});
|
|
24
|
+
it('should generate a homepage URL based on the current locale', () => {
|
|
25
|
+
var href = generateUrlFromPattern('/(:localeSlug/)media', {
|
|
26
|
+
localeCode: 'en'
|
|
27
|
+
}, {
|
|
28
|
+
defaultLocale: 'en',
|
|
29
|
+
locales: ['en', 'nl', 'fr']
|
|
30
|
+
});
|
|
31
|
+
expect(href).toBe('/media');
|
|
32
|
+
});
|
|
33
|
+
it('should generate a shortest possible locale slug', () => {
|
|
34
|
+
var href = generateUrlFromPattern('/(:localeSlug/)media', {
|
|
35
|
+
localeCode: 'nl_BE'
|
|
36
|
+
}, {
|
|
37
|
+
defaultLocale: 'en_US',
|
|
38
|
+
locales: ['en_US', 'nl_BE', 'fr_FR']
|
|
39
|
+
});
|
|
40
|
+
expect(href).toBe('/nl/media');
|
|
41
|
+
});
|
|
42
|
+
});
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.getShortestLocaleSlug = getShortestLocaleSlug;
|
|
7
|
+
var _themeKitIntl = require("@prezly/theme-kit-intl");
|
|
8
|
+
var _isNumberCode = require("./isNumberCode.cjs");
|
|
9
|
+
/* eslint-disable @typescript-eslint/no-use-before-define */
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Get the shortest locale code possible from full locale code
|
|
13
|
+
* First: try shorting to neutral language code (there should be no locales with the same language code)
|
|
14
|
+
* Then: try shorting to region code (there should be no locales with the same region code)
|
|
15
|
+
* Finally: return the original locale code (shorting is not possible)
|
|
16
|
+
*/
|
|
17
|
+
function getShortestLocaleSlug(locale, context) {
|
|
18
|
+
var _ref, _getUnambiguousLangCo;
|
|
19
|
+
var {
|
|
20
|
+
code: localeCode,
|
|
21
|
+
lang: langCode,
|
|
22
|
+
region: regionCode,
|
|
23
|
+
slug: localeSlug
|
|
24
|
+
} = _themeKitIntl.Locale.from(locale);
|
|
25
|
+
|
|
26
|
+
// If it's a default locale, return false (no locale needed in URL)
|
|
27
|
+
if (localeCode === context.defaultLocale) {
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
var shortened = // Try shortening to neutral language code
|
|
31
|
+
(_ref = (_getUnambiguousLangCo = getUnambiguousLangCode(langCode, context)) !== null && _getUnambiguousLangCo !== void 0 ? _getUnambiguousLangCo :
|
|
32
|
+
// Try shortening to region code
|
|
33
|
+
getUnambiguousRegionCode(regionCode, context)) !== null && _ref !== void 0 ? _ref :
|
|
34
|
+
// Return the original (exact) code if shortening is not possible
|
|
35
|
+
localeSlug;
|
|
36
|
+
return shortened.toLowerCase();
|
|
37
|
+
}
|
|
38
|
+
function getUnambiguousLangCode(langCode, context) {
|
|
39
|
+
var candidates = context.locales.filter(code => _themeKitIntl.Locale.isLanguageCode(code, langCode));
|
|
40
|
+
if (candidates.length === 1) {
|
|
41
|
+
return langCode;
|
|
42
|
+
}
|
|
43
|
+
return undefined;
|
|
44
|
+
}
|
|
45
|
+
function getUnambiguousRegionCode(regionCode, context) {
|
|
46
|
+
if (!regionCode) {
|
|
47
|
+
return undefined;
|
|
48
|
+
}
|
|
49
|
+
if ((0, _isNumberCode.isNumberCode)(regionCode)) {
|
|
50
|
+
// We don't want just numbers in our region code
|
|
51
|
+
return undefined;
|
|
52
|
+
}
|
|
53
|
+
var candidates = context.locales.filter(locale => _themeKitIntl.Locale.isRegionCode(locale, regionCode));
|
|
54
|
+
// Prevent collision with neutral language codes
|
|
55
|
+
var collisions = context.locales.filter(locale => _themeKitIntl.Locale.isLanguageCode(locale, regionCode.toLowerCase()));
|
|
56
|
+
if (candidates.length === 1 && collisions.length === 0) {
|
|
57
|
+
return regionCode;
|
|
58
|
+
}
|
|
59
|
+
return undefined;
|
|
60
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Locale } from '@prezly/theme-kit-intl';
|
|
2
|
+
/**
|
|
3
|
+
* Get the shortest locale code possible from full locale code
|
|
4
|
+
* First: try shorting to neutral language code (there should be no locales with the same language code)
|
|
5
|
+
* Then: try shorting to region code (there should be no locales with the same region code)
|
|
6
|
+
* Finally: return the original locale code (shorting is not possible)
|
|
7
|
+
*/
|
|
8
|
+
export declare function getShortestLocaleSlug(locale: Locale.Code, context: {
|
|
9
|
+
locales: Locale.Code[];
|
|
10
|
+
defaultLocale: Locale.Code;
|
|
11
|
+
}): Locale.AnySlug | false;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-use-before-define */
|
|
2
|
+
import { Locale } from '@prezly/theme-kit-intl';
|
|
3
|
+
import { isNumberCode } from "./isNumberCode.mjs";
|
|
4
|
+
/**
|
|
5
|
+
* Get the shortest locale code possible from full locale code
|
|
6
|
+
* First: try shorting to neutral language code (there should be no locales with the same language code)
|
|
7
|
+
* Then: try shorting to region code (there should be no locales with the same region code)
|
|
8
|
+
* Finally: return the original locale code (shorting is not possible)
|
|
9
|
+
*/
|
|
10
|
+
export function getShortestLocaleSlug(locale, context) {
|
|
11
|
+
var _ref, _getUnambiguousLangCo;
|
|
12
|
+
var {
|
|
13
|
+
code: localeCode,
|
|
14
|
+
lang: langCode,
|
|
15
|
+
region: regionCode,
|
|
16
|
+
slug: localeSlug
|
|
17
|
+
} = Locale.from(locale);
|
|
18
|
+
|
|
19
|
+
// If it's a default locale, return false (no locale needed in URL)
|
|
20
|
+
if (localeCode === context.defaultLocale) {
|
|
21
|
+
return false;
|
|
22
|
+
}
|
|
23
|
+
var shortened = // Try shortening to neutral language code
|
|
24
|
+
(_ref = (_getUnambiguousLangCo = getUnambiguousLangCode(langCode, context)) !== null && _getUnambiguousLangCo !== void 0 ? _getUnambiguousLangCo :
|
|
25
|
+
// Try shortening to region code
|
|
26
|
+
getUnambiguousRegionCode(regionCode, context)) !== null && _ref !== void 0 ? _ref :
|
|
27
|
+
// Return the original (exact) code if shortening is not possible
|
|
28
|
+
localeSlug;
|
|
29
|
+
return shortened.toLowerCase();
|
|
30
|
+
}
|
|
31
|
+
function getUnambiguousLangCode(langCode, context) {
|
|
32
|
+
var candidates = context.locales.filter(code => Locale.isLanguageCode(code, langCode));
|
|
33
|
+
if (candidates.length === 1) {
|
|
34
|
+
return langCode;
|
|
35
|
+
}
|
|
36
|
+
return undefined;
|
|
37
|
+
}
|
|
38
|
+
function getUnambiguousRegionCode(regionCode, context) {
|
|
39
|
+
if (!regionCode) {
|
|
40
|
+
return undefined;
|
|
41
|
+
}
|
|
42
|
+
if (isNumberCode(regionCode)) {
|
|
43
|
+
// We don't want just numbers in our region code
|
|
44
|
+
return undefined;
|
|
45
|
+
}
|
|
46
|
+
var candidates = context.locales.filter(locale => Locale.isRegionCode(locale, regionCode));
|
|
47
|
+
// Prevent collision with neutral language codes
|
|
48
|
+
var collisions = context.locales.filter(locale => Locale.isLanguageCode(locale, regionCode.toLowerCase()));
|
|
49
|
+
if (candidates.length === 1 && collisions.length === 0) {
|
|
50
|
+
return regionCode;
|
|
51
|
+
}
|
|
52
|
+
return undefined;
|
|
53
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _languages = require("../../__mocks__/languages.cjs");
|
|
4
|
+
var _getShortestLocaleSlug = require("./getShortestLocaleSlug.cjs");
|
|
5
|
+
var locales = Object.values(_languages.LANGUAGES).map(lang => lang.code);
|
|
6
|
+
var defaultLocale = Object.values(_languages.LANGUAGES).filter(lang => lang.is_default).map(lang => lang.code)[0];
|
|
7
|
+
var context = {
|
|
8
|
+
locales,
|
|
9
|
+
defaultLocale
|
|
10
|
+
};
|
|
11
|
+
function without(codes, exclude) {
|
|
12
|
+
return codes.filter(code => code !== exclude);
|
|
13
|
+
}
|
|
14
|
+
describe('getShortestLocaleSlug', () => {
|
|
15
|
+
it('returns false for default language', () => {
|
|
16
|
+
expect((0, _getShortestLocaleSlug.getShortestLocaleSlug)('en', context)).toBe(false);
|
|
17
|
+
});
|
|
18
|
+
it('returns neutral language code if it is the only culture with that language', () => {
|
|
19
|
+
expect((0, _getShortestLocaleSlug.getShortestLocaleSlug)('es_ES', {
|
|
20
|
+
locales: without(locales, 'es_419'),
|
|
21
|
+
defaultLocale
|
|
22
|
+
})).toBe('es');
|
|
23
|
+
});
|
|
24
|
+
it('returns region code if it is the only culture with that region', () => {
|
|
25
|
+
expect((0, _getShortestLocaleSlug.getShortestLocaleSlug)('en_US', context)).toBe('us');
|
|
26
|
+
expect((0, _getShortestLocaleSlug.getShortestLocaleSlug)('en_GB', context)).toBe('gb');
|
|
27
|
+
expect((0, _getShortestLocaleSlug.getShortestLocaleSlug)('nl_NL', context)).toBe('nl-nl'); // cannot use `nl`, as it collides with language code
|
|
28
|
+
expect((0, _getShortestLocaleSlug.getShortestLocaleSlug)('fr', context)).toBe('fr');
|
|
29
|
+
});
|
|
30
|
+
it('returns full code if it can not be shortened', () => {
|
|
31
|
+
expect((0, _getShortestLocaleSlug.getShortestLocaleSlug)('fr_BE', context)).toBe('fr-be');
|
|
32
|
+
expect((0, _getShortestLocaleSlug.getShortestLocaleSlug)('nl_BE', context)).toBe('nl-be');
|
|
33
|
+
});
|
|
34
|
+
it('returns full code when trying to shorten to region code for es-419', () => {
|
|
35
|
+
expect((0, _getShortestLocaleSlug.getShortestLocaleSlug)('es_419', context)).toBe('es-419');
|
|
36
|
+
});
|
|
37
|
+
});
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { LANGUAGES } from "../../__mocks__/languages.mjs";
|
|
2
|
+
import { getShortestLocaleSlug } from "./getShortestLocaleSlug.mjs";
|
|
3
|
+
var locales = Object.values(LANGUAGES).map(lang => lang.code);
|
|
4
|
+
var defaultLocale = Object.values(LANGUAGES).filter(lang => lang.is_default).map(lang => lang.code)[0];
|
|
5
|
+
var context = {
|
|
6
|
+
locales,
|
|
7
|
+
defaultLocale
|
|
8
|
+
};
|
|
9
|
+
function without(codes, exclude) {
|
|
10
|
+
return codes.filter(code => code !== exclude);
|
|
11
|
+
}
|
|
12
|
+
describe('getShortestLocaleSlug', () => {
|
|
13
|
+
it('returns false for default language', () => {
|
|
14
|
+
expect(getShortestLocaleSlug('en', context)).toBe(false);
|
|
15
|
+
});
|
|
16
|
+
it('returns neutral language code if it is the only culture with that language', () => {
|
|
17
|
+
expect(getShortestLocaleSlug('es_ES', {
|
|
18
|
+
locales: without(locales, 'es_419'),
|
|
19
|
+
defaultLocale
|
|
20
|
+
})).toBe('es');
|
|
21
|
+
});
|
|
22
|
+
it('returns region code if it is the only culture with that region', () => {
|
|
23
|
+
expect(getShortestLocaleSlug('en_US', context)).toBe('us');
|
|
24
|
+
expect(getShortestLocaleSlug('en_GB', context)).toBe('gb');
|
|
25
|
+
expect(getShortestLocaleSlug('nl_NL', context)).toBe('nl-nl'); // cannot use `nl`, as it collides with language code
|
|
26
|
+
expect(getShortestLocaleSlug('fr', context)).toBe('fr');
|
|
27
|
+
});
|
|
28
|
+
it('returns full code if it can not be shortened', () => {
|
|
29
|
+
expect(getShortestLocaleSlug('fr_BE', context)).toBe('fr-be');
|
|
30
|
+
expect(getShortestLocaleSlug('nl_BE', context)).toBe('nl-be');
|
|
31
|
+
});
|
|
32
|
+
it('returns full code when trying to shorten to region code for es-419', () => {
|
|
33
|
+
expect(getShortestLocaleSlug('es_419', context)).toBe('es-419');
|
|
34
|
+
});
|
|
35
|
+
});
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
Object.defineProperty(exports, "generateUrlFromPattern", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function get() {
|
|
9
|
+
return _generateUrlFromPattern.generateUrlFromPattern;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
Object.defineProperty(exports, "getShortestLocaleSlug", {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function get() {
|
|
15
|
+
return _getShortestLocaleSlug.getShortestLocaleSlug;
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
Object.defineProperty(exports, "isNumberCode", {
|
|
19
|
+
enumerable: true,
|
|
20
|
+
get: function get() {
|
|
21
|
+
return _isNumberCode.isNumberCode;
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
Object.defineProperty(exports, "matchLocaleSlug", {
|
|
25
|
+
enumerable: true,
|
|
26
|
+
get: function get() {
|
|
27
|
+
return _matchLocaleSlug.matchLocaleSlug;
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
Object.defineProperty(exports, "normalizeUrl", {
|
|
31
|
+
enumerable: true,
|
|
32
|
+
get: function get() {
|
|
33
|
+
return _normalizeUrl.normalizeUrl;
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
var _generateUrlFromPattern = require("./generateUrlFromPattern.cjs");
|
|
37
|
+
var _getShortestLocaleSlug = require("./getShortestLocaleSlug.cjs");
|
|
38
|
+
var _matchLocaleSlug = require("./matchLocaleSlug.cjs");
|
|
39
|
+
var _isNumberCode = require("./isNumberCode.cjs");
|
|
40
|
+
var _normalizeUrl = require("./normalizeUrl.cjs");
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { generateUrlFromPattern } from './generateUrlFromPattern';
|
|
2
|
+
export { getShortestLocaleSlug } from './getShortestLocaleSlug';
|
|
3
|
+
export { matchLocaleSlug } from './matchLocaleSlug';
|
|
4
|
+
export { isNumberCode } from './isNumberCode';
|
|
5
|
+
export { normalizeUrl } from './normalizeUrl';
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { generateUrlFromPattern } from "./generateUrlFromPattern.mjs";
|
|
2
|
+
export { getShortestLocaleSlug } from "./getShortestLocaleSlug.mjs";
|
|
3
|
+
export { matchLocaleSlug } from "./matchLocaleSlug.mjs";
|
|
4
|
+
export { isNumberCode } from "./isNumberCode.mjs";
|
|
5
|
+
export { normalizeUrl } from "./normalizeUrl.mjs";
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.isNumberCode = isNumberCode;
|
|
7
|
+
/**
|
|
8
|
+
* Get newsroom notifications for the selected locale
|
|
9
|
+
*/
|
|
10
|
+
function isNumberCode(code) {
|
|
11
|
+
return !Number.isNaN(Number(code));
|
|
12
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.matchLocaleSlug = matchLocaleSlug;
|
|
7
|
+
var _themeKitIntl = require("@prezly/theme-kit-intl");
|
|
8
|
+
var _isNumberCode = require("./isNumberCode.cjs");
|
|
9
|
+
/* eslint-disable @typescript-eslint/no-use-before-define */
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Match the requested locale slug against the enabled locales.
|
|
13
|
+
* The enabled locales have to be provided in the order of importance:
|
|
14
|
+
* default first, then locales with public stories, then the rest.
|
|
15
|
+
*
|
|
16
|
+
* The logic is reversed from `getShortestLocaleSlug`, so that it "unwraps" the possible variants.
|
|
17
|
+
* @see {getShortestLocaleSlug()}
|
|
18
|
+
*
|
|
19
|
+
* The order of checks is:
|
|
20
|
+
* - exact locale slug match
|
|
21
|
+
* - match by language code
|
|
22
|
+
* - match by region code
|
|
23
|
+
*/
|
|
24
|
+
function matchLocaleSlug(slug, locales) {
|
|
25
|
+
var _ref, _ref2, _matchByExactLocaleSl;
|
|
26
|
+
return (_ref = (_ref2 = (_matchByExactLocaleSl = matchByExactLocaleSlug(slug, locales)) !== null && _matchByExactLocaleSl !== void 0 ? _matchByExactLocaleSl : matchByLangSlug(slug, locales)) !== null && _ref2 !== void 0 ? _ref2 : matchByRegionSlug(slug, locales)) !== null && _ref !== void 0 ? _ref : undefined;
|
|
27
|
+
}
|
|
28
|
+
function matchByExactLocaleSlug(slug, locales) {
|
|
29
|
+
if (!_themeKitIntl.Locale.isValid(slug)) return undefined;
|
|
30
|
+
var locale = _themeKitIntl.Locale.from(slug);
|
|
31
|
+
return locales.find(localeCode => localeCode === locale.code);
|
|
32
|
+
}
|
|
33
|
+
function matchByLangSlug(slug, locales) {
|
|
34
|
+
return locales.find(localeCode => _themeKitIntl.Locale.isLanguageCode(localeCode, slug.toLowerCase()));
|
|
35
|
+
}
|
|
36
|
+
function matchByRegionSlug(slug, locales) {
|
|
37
|
+
if (!slug || (0, _isNumberCode.isNumberCode)(slug)) {
|
|
38
|
+
return undefined;
|
|
39
|
+
}
|
|
40
|
+
return locales.find(localeCode => _themeKitIntl.Locale.isRegionCode(localeCode, slug.toUpperCase()));
|
|
41
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Locale } from '@prezly/theme-kit-intl';
|
|
2
|
+
/**
|
|
3
|
+
* Match the requested locale slug against the enabled locales.
|
|
4
|
+
* The enabled locales have to be provided in the order of importance:
|
|
5
|
+
* default first, then locales with public stories, then the rest.
|
|
6
|
+
*
|
|
7
|
+
* The logic is reversed from `getShortestLocaleSlug`, so that it "unwraps" the possible variants.
|
|
8
|
+
* @see {getShortestLocaleSlug()}
|
|
9
|
+
*
|
|
10
|
+
* The order of checks is:
|
|
11
|
+
* - exact locale slug match
|
|
12
|
+
* - match by language code
|
|
13
|
+
* - match by region code
|
|
14
|
+
*/
|
|
15
|
+
export declare function matchLocaleSlug(slug: Locale.AnySlug, locales: Locale.Code[]): Locale.Code | undefined;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-use-before-define */
|
|
2
|
+
import { Locale } from '@prezly/theme-kit-intl';
|
|
3
|
+
import { isNumberCode } from "./isNumberCode.mjs";
|
|
4
|
+
/**
|
|
5
|
+
* Match the requested locale slug against the enabled locales.
|
|
6
|
+
* The enabled locales have to be provided in the order of importance:
|
|
7
|
+
* default first, then locales with public stories, then the rest.
|
|
8
|
+
*
|
|
9
|
+
* The logic is reversed from `getShortestLocaleSlug`, so that it "unwraps" the possible variants.
|
|
10
|
+
* @see {getShortestLocaleSlug()}
|
|
11
|
+
*
|
|
12
|
+
* The order of checks is:
|
|
13
|
+
* - exact locale slug match
|
|
14
|
+
* - match by language code
|
|
15
|
+
* - match by region code
|
|
16
|
+
*/
|
|
17
|
+
export function matchLocaleSlug(slug, locales) {
|
|
18
|
+
var _ref, _ref2, _matchByExactLocaleSl;
|
|
19
|
+
return (_ref = (_ref2 = (_matchByExactLocaleSl = matchByExactLocaleSlug(slug, locales)) !== null && _matchByExactLocaleSl !== void 0 ? _matchByExactLocaleSl : matchByLangSlug(slug, locales)) !== null && _ref2 !== void 0 ? _ref2 : matchByRegionSlug(slug, locales)) !== null && _ref !== void 0 ? _ref : undefined;
|
|
20
|
+
}
|
|
21
|
+
function matchByExactLocaleSlug(slug, locales) {
|
|
22
|
+
if (!Locale.isValid(slug)) return undefined;
|
|
23
|
+
var locale = Locale.from(slug);
|
|
24
|
+
return locales.find(localeCode => localeCode === locale.code);
|
|
25
|
+
}
|
|
26
|
+
function matchByLangSlug(slug, locales) {
|
|
27
|
+
return locales.find(localeCode => Locale.isLanguageCode(localeCode, slug.toLowerCase()));
|
|
28
|
+
}
|
|
29
|
+
function matchByRegionSlug(slug, locales) {
|
|
30
|
+
if (!slug || isNumberCode(slug)) {
|
|
31
|
+
return undefined;
|
|
32
|
+
}
|
|
33
|
+
return locales.find(localeCode => Locale.isRegionCode(localeCode, slug.toUpperCase()));
|
|
34
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _matchLocaleSlug = require("./matchLocaleSlug.cjs");
|
|
4
|
+
/* eslint-disable @typescript-eslint/naming-convention */
|
|
5
|
+
|
|
6
|
+
describe('matchLocaleSlug', () => {
|
|
7
|
+
it('should match enabled locales by full locale slug', () => {
|
|
8
|
+
var locales = ['nl_BE', 'nl_NL', 'en'];
|
|
9
|
+
expect((0, _matchLocaleSlug.matchLocaleSlug)('nl-be', locales)).toBe('nl_BE');
|
|
10
|
+
expect((0, _matchLocaleSlug.matchLocaleSlug)('nl-nl', locales)).toBe('nl_NL');
|
|
11
|
+
expect((0, _matchLocaleSlug.matchLocaleSlug)('en', locales)).toBe('en');
|
|
12
|
+
});
|
|
13
|
+
it('should return undefined if no active locale matches locale slug', () => {
|
|
14
|
+
var locales = ['nl_BE', 'nl_NL', 'en'];
|
|
15
|
+
expect((0, _matchLocaleSlug.matchLocaleSlug)('fr-be', locales)).toBeUndefined();
|
|
16
|
+
expect((0, _matchLocaleSlug.matchLocaleSlug)('en-us', locales)).toBeUndefined();
|
|
17
|
+
expect((0, _matchLocaleSlug.matchLocaleSlug)('de-de', locales)).toBeUndefined();
|
|
18
|
+
});
|
|
19
|
+
it('should match locale by lang code slug', () => {
|
|
20
|
+
var locales = ['nl_BE', 'en_US', 'fr_BE'];
|
|
21
|
+
expect((0, _matchLocaleSlug.matchLocaleSlug)('nl', locales)).toBe('nl_BE');
|
|
22
|
+
expect((0, _matchLocaleSlug.matchLocaleSlug)('fr', locales)).toBe('fr_BE');
|
|
23
|
+
expect((0, _matchLocaleSlug.matchLocaleSlug)('en', locales)).toBe('en_US');
|
|
24
|
+
});
|
|
25
|
+
it('should match locale by region code slug', () => {
|
|
26
|
+
var locales = ['nl_BE', 'en_GB', 'en_US'];
|
|
27
|
+
expect((0, _matchLocaleSlug.matchLocaleSlug)('be', locales)).toBe('nl_BE');
|
|
28
|
+
expect((0, _matchLocaleSlug.matchLocaleSlug)('gb', locales)).toBe('en_GB');
|
|
29
|
+
expect((0, _matchLocaleSlug.matchLocaleSlug)('us', locales)).toBe('en_US');
|
|
30
|
+
});
|
|
31
|
+
it('should never match locale by number-only region code slug', () => {
|
|
32
|
+
var locales = ['es_ES', 'es_419'];
|
|
33
|
+
expect((0, _matchLocaleSlug.matchLocaleSlug)('419', locales)).toBeUndefined();
|
|
34
|
+
});
|
|
35
|
+
it('should pick locale in the given order of preference if multiple match against th shortened lang code', () => {
|
|
36
|
+
expect((0, _matchLocaleSlug.matchLocaleSlug)('en', ['en_GB', 'en_US', 'nl_BE'])).toBe('en_GB');
|
|
37
|
+
expect((0, _matchLocaleSlug.matchLocaleSlug)('en', ['nl_BE', 'en_US', 'en_GB'])).toBe('en_US');
|
|
38
|
+
});
|
|
39
|
+
it('should pick locale in the given order of preference if multiple match against th shortened region code', () => {
|
|
40
|
+
expect((0, _matchLocaleSlug.matchLocaleSlug)('be', ['nl_BE', 'fr_BE', 'en_GB'])).toBe('nl_BE');
|
|
41
|
+
expect((0, _matchLocaleSlug.matchLocaleSlug)('be', ['en_GB', 'fr_BE', 'nl_BE'])).toBe('fr_BE');
|
|
42
|
+
});
|
|
43
|
+
});
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/naming-convention */
|
|
2
|
+
import { matchLocaleSlug } from "./matchLocaleSlug.mjs";
|
|
3
|
+
describe('matchLocaleSlug', () => {
|
|
4
|
+
it('should match enabled locales by full locale slug', () => {
|
|
5
|
+
var locales = ['nl_BE', 'nl_NL', 'en'];
|
|
6
|
+
expect(matchLocaleSlug('nl-be', locales)).toBe('nl_BE');
|
|
7
|
+
expect(matchLocaleSlug('nl-nl', locales)).toBe('nl_NL');
|
|
8
|
+
expect(matchLocaleSlug('en', locales)).toBe('en');
|
|
9
|
+
});
|
|
10
|
+
it('should return undefined if no active locale matches locale slug', () => {
|
|
11
|
+
var locales = ['nl_BE', 'nl_NL', 'en'];
|
|
12
|
+
expect(matchLocaleSlug('fr-be', locales)).toBeUndefined();
|
|
13
|
+
expect(matchLocaleSlug('en-us', locales)).toBeUndefined();
|
|
14
|
+
expect(matchLocaleSlug('de-de', locales)).toBeUndefined();
|
|
15
|
+
});
|
|
16
|
+
it('should match locale by lang code slug', () => {
|
|
17
|
+
var locales = ['nl_BE', 'en_US', 'fr_BE'];
|
|
18
|
+
expect(matchLocaleSlug('nl', locales)).toBe('nl_BE');
|
|
19
|
+
expect(matchLocaleSlug('fr', locales)).toBe('fr_BE');
|
|
20
|
+
expect(matchLocaleSlug('en', locales)).toBe('en_US');
|
|
21
|
+
});
|
|
22
|
+
it('should match locale by region code slug', () => {
|
|
23
|
+
var locales = ['nl_BE', 'en_GB', 'en_US'];
|
|
24
|
+
expect(matchLocaleSlug('be', locales)).toBe('nl_BE');
|
|
25
|
+
expect(matchLocaleSlug('gb', locales)).toBe('en_GB');
|
|
26
|
+
expect(matchLocaleSlug('us', locales)).toBe('en_US');
|
|
27
|
+
});
|
|
28
|
+
it('should never match locale by number-only region code slug', () => {
|
|
29
|
+
var locales = ['es_ES', 'es_419'];
|
|
30
|
+
expect(matchLocaleSlug('419', locales)).toBeUndefined();
|
|
31
|
+
});
|
|
32
|
+
it('should pick locale in the given order of preference if multiple match against th shortened lang code', () => {
|
|
33
|
+
expect(matchLocaleSlug('en', ['en_GB', 'en_US', 'nl_BE'])).toBe('en_GB');
|
|
34
|
+
expect(matchLocaleSlug('en', ['nl_BE', 'en_US', 'en_GB'])).toBe('en_US');
|
|
35
|
+
});
|
|
36
|
+
it('should pick locale in the given order of preference if multiple match against th shortened region code', () => {
|
|
37
|
+
expect(matchLocaleSlug('be', ['nl_BE', 'fr_BE', 'en_GB'])).toBe('nl_BE');
|
|
38
|
+
expect(matchLocaleSlug('be', ['en_GB', 'fr_BE', 'nl_BE'])).toBe('fr_BE');
|
|
39
|
+
});
|
|
40
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function normalizeUrl(url: `/${string}`): `/${string}`;
|
package/build/search.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";
|