@intlayer/core 5.3.12 → 5.4.0-canary.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.
@@ -15,23 +15,23 @@ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "defau
15
15
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
16
16
  var index_exports = {};
17
17
  module.exports = __toCommonJS(index_exports);
18
- __reExport(index_exports, require('./transpiler/index.cjs'), module.exports);
19
- __reExport(index_exports, require('./interpreter/index.cjs'), module.exports);
20
18
  __reExport(index_exports, require('./dictionaryManipulator/index.cjs'), module.exports);
19
+ __reExport(index_exports, require('./interpreter/index.cjs'), module.exports);
20
+ __reExport(index_exports, require('./localization/index.cjs'), module.exports);
21
+ __reExport(index_exports, require('./transpiler/index.cjs'), module.exports);
21
22
  __reExport(index_exports, require('./types/index.cjs'), module.exports);
22
- __reExport(index_exports, require('./utils/isSameKeyPath.cjs'), module.exports);
23
23
  __reExport(index_exports, require('./utils/checkIsURLAbsolute.cjs'), module.exports);
24
+ __reExport(index_exports, require('./utils/isSameKeyPath.cjs'), module.exports);
24
25
  __reExport(index_exports, require('./utils/isValidReactElement.cjs'), module.exports);
25
- __reExport(index_exports, require('./localization/index.cjs'), module.exports);
26
26
  // Annotate the CommonJS export names for ESM import in node:
27
27
  0 && (module.exports = {
28
- ...require('./transpiler/index.cjs'),
29
- ...require('./interpreter/index.cjs'),
30
28
  ...require('./dictionaryManipulator/index.cjs'),
29
+ ...require('./interpreter/index.cjs'),
30
+ ...require('./localization/index.cjs'),
31
+ ...require('./transpiler/index.cjs'),
31
32
  ...require('./types/index.cjs'),
32
- ...require('./utils/isSameKeyPath.cjs'),
33
33
  ...require('./utils/checkIsURLAbsolute.cjs'),
34
- ...require('./utils/isValidReactElement.cjs'),
35
- ...require('./localization/index.cjs')
34
+ ...require('./utils/isSameKeyPath.cjs'),
35
+ ...require('./utils/isValidReactElement.cjs')
36
36
  });
37
37
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/index.ts"],"sourcesContent":["export * from './transpiler/index';\nexport * from './interpreter/index';\nexport * from './dictionaryManipulator/index';\nexport * from './types/index';\nexport * from './utils/isSameKeyPath';\nexport * from './utils/checkIsURLAbsolute';\nexport * from './utils/isValidReactElement';\nexport * from './localization/index';\n"],"mappings":";;;;;;;;;;;;;;;AAAA;AAAA;AAAA,0BAAc,+BAAd;AACA,0BAAc,gCADd;AAEA,0BAAc,0CAFd;AAGA,0BAAc,0BAHd;AAIA,0BAAc,kCAJd;AAKA,0BAAc,uCALd;AAMA,0BAAc,wCANd;AAOA,0BAAc,iCAPd;","names":[]}
1
+ {"version":3,"sources":["../../src/index.ts"],"sourcesContent":["export * from './dictionaryManipulator/index';\nexport * from './interpreter/index';\nexport * from './localization/index';\nexport * from './transpiler/index';\nexport * from './types/index';\nexport * from './utils/checkIsURLAbsolute';\nexport * from './utils/isSameKeyPath';\nexport * from './utils/isValidReactElement';\n"],"mappings":";;;;;;;;;;;;;;;AAAA;AAAA;AAAA,0BAAc,0CAAd;AACA,0BAAc,gCADd;AAEA,0BAAc,iCAFd;AAGA,0BAAc,+BAHd;AAIA,0BAAc,0BAJd;AAKA,0BAAc,uCALd;AAMA,0BAAc,kCANd;AAOA,0BAAc,wCAPd;","names":[]}
@@ -0,0 +1,59 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var getLocaleFromPath_exports = {};
30
+ __export(getLocaleFromPath_exports, {
31
+ getLocaleFromPath: () => getLocaleFromPath
32
+ });
33
+ module.exports = __toCommonJS(getLocaleFromPath_exports);
34
+ var import_built = __toESM(require("@intlayer/config/built"));
35
+ var import_checkIsURLAbsolute = require('../utils/checkIsURLAbsolute.cjs');
36
+ const getLocaleFromPath = (inputUrl) => {
37
+ const { defaultLocale, locales } = import_built.default.internationalization;
38
+ const isAbsoluteUrl = (0, import_checkIsURLAbsolute.checkIsURLAbsolute)(inputUrl);
39
+ let fixedInputUrl = inputUrl;
40
+ if (inputUrl.endsWith("/")) {
41
+ fixedInputUrl = inputUrl.slice(0, -1);
42
+ }
43
+ const url = isAbsoluteUrl ? new URL(fixedInputUrl) : new URL(fixedInputUrl, "http://example.com");
44
+ const pathname = url.pathname;
45
+ if (!pathname.startsWith("/")) {
46
+ return defaultLocale;
47
+ }
48
+ const pathSegments = pathname.split("/");
49
+ const firstSegment = pathSegments[1];
50
+ if (firstSegment && locales.includes(firstSegment)) {
51
+ return firstSegment;
52
+ }
53
+ return defaultLocale;
54
+ };
55
+ // Annotate the CommonJS export names for ESM import in node:
56
+ 0 && (module.exports = {
57
+ getLocaleFromPath
58
+ });
59
+ //# sourceMappingURL=getLocaleFromPath.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/localization/getLocaleFromPath.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport type { Locales } from '@intlayer/config/client';\nimport { checkIsURLAbsolute } from '../utils/checkIsURLAbsolute';\n\n/**\n * Extracts the locale segment from the given URL or pathname if present.\n * If no locale is present, returns the default locale (en).\n *\n * Example:\n *\n * ```ts\n * getLocaleFromPath('/en/dashboard') // Returns 'en'\n * getLocaleFromPath('/fr/dashboard') // Returns 'fr'\n * getLocaleFromPath('/dashboard') // Returns 'en'\n * getLocaleFromPath('dashboard') // Returns 'en'\n * getLocaleFromPath('https://example.com/es/dashboard') // Returns 'es'\n * getLocaleFromPath('https://example.com/fr/dashboard') // Returns 'fr'\n * getLocaleFromPath('https://example.com/dashboard') // Returns 'en'\n * ```\n *\n * @param inputUrl - The complete URL string or pathname to process.\n * @returns The detected locale or default (en) if no locale is found\n */\nexport const getLocaleFromPath = (inputUrl: string): Locales => {\n // Define supported locales array\n const { defaultLocale, locales } = configuration.internationalization;\n\n // Determine if the original URL is absolute (includes protocol)\n const isAbsoluteUrl = checkIsURLAbsolute(inputUrl);\n\n let fixedInputUrl = inputUrl;\n\n if (inputUrl.endsWith('/')) {\n fixedInputUrl = inputUrl.slice(0, -1);\n }\n\n // Initialize a URL object if the URL is absolute\n // For relative URLs, use a dummy base to leverage the URL API\n const url = isAbsoluteUrl\n ? new URL(fixedInputUrl)\n : new URL(fixedInputUrl, 'http://example.com');\n\n const pathname = url.pathname;\n\n // Ensure the pathname starts with '/'\n if (!pathname.startsWith('/')) {\n // If not, return the default locale\n return defaultLocale;\n }\n\n // Split the pathname to extract the first segment\n const pathSegments = pathname.split('/');\n const firstSegment = pathSegments[1]; // The segment after the first '/'\n\n // Check if the first segment is a supported locale\n if (firstSegment && locales.includes(firstSegment as Locales)) {\n // Return the detected locale\n return firstSegment as Locales;\n }\n\n // Return the default locale if no locale is found in the path\n return defaultLocale;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAA0B;AAE1B,gCAAmC;AAqB5B,MAAM,oBAAoB,CAAC,aAA8B;AAE9D,QAAM,EAAE,eAAe,QAAQ,IAAI,aAAAA,QAAc;AAGjD,QAAM,oBAAgB,8CAAmB,QAAQ;AAEjD,MAAI,gBAAgB;AAEpB,MAAI,SAAS,SAAS,GAAG,GAAG;AAC1B,oBAAgB,SAAS,MAAM,GAAG,EAAE;AAAA,EACtC;AAIA,QAAM,MAAM,gBACR,IAAI,IAAI,aAAa,IACrB,IAAI,IAAI,eAAe,oBAAoB;AAE/C,QAAM,WAAW,IAAI;AAGrB,MAAI,CAAC,SAAS,WAAW,GAAG,GAAG;AAE7B,WAAO;AAAA,EACT;AAGA,QAAM,eAAe,SAAS,MAAM,GAAG;AACvC,QAAM,eAAe,aAAa,CAAC;AAGnC,MAAI,gBAAgB,QAAQ,SAAS,YAAuB,GAAG;AAE7D,WAAO;AAAA,EACT;AAGA,SAAO;AACT;","names":["configuration"]}
@@ -19,35 +19,43 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
19
19
  var localization_exports = {};
20
20
  __export(localization_exports, {
21
21
  getHTMLTextDir: () => import_getHTMLTextDir.getHTMLTextDir,
22
+ getLocaleFromPath: () => import_getLocaleFromPath.getLocaleFromPath,
22
23
  getLocaleLang: () => import_getLocaleLang.getLocaleLang,
23
24
  getLocaleName: () => import_getLocaleName.getLocaleName,
24
25
  getLocalizedUrl: () => import_getLocalizedUrl.getLocalizedUrl,
25
26
  getMultilingualUrls: () => import_getMultilingualUrls.getMultilingualUrls,
26
27
  getPathWithoutLocale: () => import_getPathWithoutLocale.getPathWithoutLocale,
27
28
  localeDetector: () => import_localeDetector.localeDetector,
29
+ localeFlatMap: () => import_localeMapper.localeFlatMap,
28
30
  localeList: () => import_localeList.localeList,
31
+ localeMap: () => import_localeMapper.localeMap,
29
32
  localeResolver: () => import_localeResolver.localeResolver
30
33
  });
31
34
  module.exports = __toCommonJS(localization_exports);
32
- var import_getLocaleName = require('./getLocaleName.cjs');
33
35
  var import_getHTMLTextDir = require('./getHTMLTextDir.cjs');
36
+ var import_getLocaleFromPath = require('./getLocaleFromPath.cjs');
34
37
  var import_getLocaleLang = require('./getLocaleLang.cjs');
38
+ var import_getLocaleName = require('./getLocaleName.cjs');
39
+ var import_getLocalizedUrl = require('./getLocalizedUrl.cjs');
40
+ var import_getMultilingualUrls = require('./getMultilingualUrls.cjs');
41
+ var import_getPathWithoutLocale = require('./getPathWithoutLocale.cjs');
42
+ var import_localeDetector = require('./localeDetector.cjs');
35
43
  var import_localeList = require('./localeList.cjs');
44
+ var import_localeMapper = require('./localeMapper.cjs');
36
45
  var import_localeResolver = require('./localeResolver.cjs');
37
- var import_localeDetector = require('./localeDetector.cjs');
38
- var import_getPathWithoutLocale = require('./getPathWithoutLocale.cjs');
39
- var import_getMultilingualUrls = require('./getMultilingualUrls.cjs');
40
- var import_getLocalizedUrl = require('./getLocalizedUrl.cjs');
41
46
  // Annotate the CommonJS export names for ESM import in node:
42
47
  0 && (module.exports = {
43
48
  getHTMLTextDir,
49
+ getLocaleFromPath,
44
50
  getLocaleLang,
45
51
  getLocaleName,
46
52
  getLocalizedUrl,
47
53
  getMultilingualUrls,
48
54
  getPathWithoutLocale,
49
55
  localeDetector,
56
+ localeFlatMap,
50
57
  localeList,
58
+ localeMap,
51
59
  localeResolver
52
60
  });
53
61
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/localization/index.ts"],"sourcesContent":["export { getLocaleName } from './getLocaleName';\nexport { getHTMLTextDir } from './getHTMLTextDir';\nexport { getLocaleLang } from './getLocaleLang';\nexport { localeList } from './localeList';\nexport { localeResolver } from './localeResolver';\nexport { localeDetector } from './localeDetector';\nexport { getPathWithoutLocale } from './getPathWithoutLocale';\nexport { getMultilingualUrls } from './getMultilingualUrls';\nexport { getLocalizedUrl } from './getLocalizedUrl';\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,2BAA8B;AAC9B,4BAA+B;AAC/B,2BAA8B;AAC9B,wBAA2B;AAC3B,4BAA+B;AAC/B,4BAA+B;AAC/B,kCAAqC;AACrC,iCAAoC;AACpC,6BAAgC;","names":[]}
1
+ {"version":3,"sources":["../../../src/localization/index.ts"],"sourcesContent":["export { getHTMLTextDir } from './getHTMLTextDir';\nexport { getLocaleFromPath } from './getLocaleFromPath';\nexport { getLocaleLang } from './getLocaleLang';\nexport { getLocaleName } from './getLocaleName';\nexport { getLocalizedUrl } from './getLocalizedUrl';\nexport { getMultilingualUrls } from './getMultilingualUrls';\nexport { getPathWithoutLocale } from './getPathWithoutLocale';\nexport { localeDetector } from './localeDetector';\nexport { localeList } from './localeList';\nexport { localeFlatMap, localeMap } from './localeMapper';\nexport { localeResolver } from './localeResolver';\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,4BAA+B;AAC/B,+BAAkC;AAClC,2BAA8B;AAC9B,2BAA8B;AAC9B,6BAAgC;AAChC,iCAAoC;AACpC,kCAAqC;AACrC,4BAA+B;AAC/B,wBAA2B;AAC3B,0BAAyC;AACzC,4BAA+B;","names":[]}
@@ -0,0 +1,64 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var localeMapper_exports = {};
30
+ __export(localeMapper_exports, {
31
+ localeFlatMap: () => localeFlatMap,
32
+ localeMap: () => localeMap
33
+ });
34
+ module.exports = __toCommonJS(localeMapper_exports);
35
+ var import_built = __toESM(require("@intlayer/config/built"));
36
+ const { internationalization, middleware } = import_built.default;
37
+ const { prefixDefault } = middleware;
38
+ const { locales, defaultLocale } = internationalization;
39
+ const baseLocaleData = {
40
+ defaultLocale,
41
+ locales
42
+ };
43
+ const localeMap = (mapper) => locales.map(
44
+ (locale) => mapper({
45
+ ...baseLocaleData,
46
+ locale,
47
+ isDefault: locale === defaultLocale,
48
+ urlPrefix: locale === defaultLocale && !prefixDefault ? "" : `/${locale}`
49
+ })
50
+ );
51
+ const localeFlatMap = (mapper) => locales.flatMap(
52
+ (locale) => mapper({
53
+ ...baseLocaleData,
54
+ locale,
55
+ isDefault: locale === defaultLocale,
56
+ urlPrefix: locale === defaultLocale && !prefixDefault ? "" : `/${locale}`
57
+ })
58
+ );
59
+ // Annotate the CommonJS export names for ESM import in node:
60
+ 0 && (module.exports = {
61
+ localeFlatMap,
62
+ localeMap
63
+ });
64
+ //# sourceMappingURL=localeMapper.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/localization/localeMapper.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport { LocalesValues } from '@intlayer/config/client';\n\nconst { internationalization, middleware } = configuration;\nconst { prefixDefault } = middleware;\nconst { locales, defaultLocale } = internationalization;\n\nexport type LocaleData = {\n locale: LocalesValues;\n defaultLocale: LocalesValues;\n isDefault: boolean;\n locales: LocalesValues[];\n urlPrefix: string;\n};\n\nconst baseLocaleData = {\n defaultLocale: defaultLocale,\n locales,\n} satisfies Partial<LocaleData>;\n\n/**\n * Map the locale data to an array of objects\n *\n * @example\n * ```ts\n * const routes = localeMap((localizedData) =>\n * ({\n * path: localizedData.urlPrefix,\n * name: localizedData.locale,\n * isDefault: localizedData.isDefault,\n * locales: localizedData.locales,\n * defaultLocale: localizedData.defaultLocale,\n * }),\n * );\n *\n * // Result\n * [\n * { path: '/', name: 'en', isDefault: true, locales: ['en'], defaultLocale: 'en', urlPrefix: '' },\n * { path: '/fr', name: 'fr', isDefault: false, locales: ['fr'], defaultLocale: 'en', urlPrefix: '/fr' },\n * { path: '/es', name: 'es', isDefault: false, locales: ['es'], defaultLocale: 'en', urlPrefix: '/es' },\n * ]\n * ```\n *\n * @param mapper - The mapper function that returns an object\n * @returns An array of objects\n */\nexport const localeMap = <T extends object>(\n mapper: (locale: LocaleData) => T\n): T[] =>\n locales.map((locale) =>\n mapper({\n ...baseLocaleData,\n locale,\n isDefault: locale === defaultLocale,\n urlPrefix: locale === defaultLocale && !prefixDefault ? '' : `/${locale}`,\n })\n );\n\n/**\n * Flatten the locale map into a single array of objects\n *\n * @example\n * ```ts\n * const routes = localeMap((localizedData) =>\n * [{\n * path: localizedData.urlPrefix,\n * name: localizedData.locale,\n * isDefault: localizedData.isDefault,\n * locales: localizedData.locales,\n * defaultLocale: localizedData.defaultLocale,\n * }],\n * );\n *\n * // Result\n * [\n * { path: '/', name: 'en', isDefault: true, locales: ['en'], defaultLocale: 'en', urlPrefix: '' },\n * { path: '/fr', name: 'fr', isDefault: false, locales: ['fr'], defaultLocale: 'en', urlPrefix: '/fr' },\n * { path: '/es', name: 'es', isDefault: false, locales: ['es'], defaultLocale: 'en', urlPrefix: '/es' },\n * ]\n * ```\n *\n * @param mapper - The mapper function that returns an array of objects\n * @returns An array of objects\n */\nexport const localeFlatMap = <T>(mapper: (locale: LocaleData) => T[]): T[] =>\n locales.flatMap((locale) =>\n mapper({\n ...baseLocaleData,\n locale,\n isDefault: locale === defaultLocale,\n urlPrefix: locale === defaultLocale && !prefixDefault ? '' : `/${locale}`,\n })\n );\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAA0B;AAG1B,MAAM,EAAE,sBAAsB,WAAW,IAAI,aAAAA;AAC7C,MAAM,EAAE,cAAc,IAAI;AAC1B,MAAM,EAAE,SAAS,cAAc,IAAI;AAUnC,MAAM,iBAAiB;AAAA,EACrB;AAAA,EACA;AACF;AA4BO,MAAM,YAAY,CACvB,WAEA,QAAQ;AAAA,EAAI,CAAC,WACX,OAAO;AAAA,IACL,GAAG;AAAA,IACH;AAAA,IACA,WAAW,WAAW;AAAA,IACtB,WAAW,WAAW,iBAAiB,CAAC,gBAAgB,KAAK,IAAI,MAAM;AAAA,EACzE,CAAC;AACH;AA4BK,MAAM,gBAAgB,CAAI,WAC/B,QAAQ;AAAA,EAAQ,CAAC,WACf,OAAO;AAAA,IACL,GAAG;AAAA,IACH;AAAA,IACA,WAAW,WAAW;AAAA,IACtB,WAAW,WAAW,iBAAiB,CAAC,gBAAgB,KAAK,IAAI,MAAM;AAAA,EACzE,CAAC;AACH;","names":["configuration"]}
@@ -1,9 +1,9 @@
1
- export * from "./transpiler/index.mjs";
2
- export * from "./interpreter/index.mjs";
3
1
  export * from "./dictionaryManipulator/index.mjs";
2
+ export * from "./interpreter/index.mjs";
3
+ export * from "./localization/index.mjs";
4
+ export * from "./transpiler/index.mjs";
4
5
  export * from "./types/index.mjs";
5
- export * from "./utils/isSameKeyPath.mjs";
6
6
  export * from "./utils/checkIsURLAbsolute.mjs";
7
+ export * from "./utils/isSameKeyPath.mjs";
7
8
  export * from "./utils/isValidReactElement.mjs";
8
- export * from "./localization/index.mjs";
9
9
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/index.ts"],"sourcesContent":["export * from './transpiler/index';\nexport * from './interpreter/index';\nexport * from './dictionaryManipulator/index';\nexport * from './types/index';\nexport * from './utils/isSameKeyPath';\nexport * from './utils/checkIsURLAbsolute';\nexport * from './utils/isValidReactElement';\nexport * from './localization/index';\n"],"mappings":"AAAA,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;","names":[]}
1
+ {"version":3,"sources":["../../src/index.ts"],"sourcesContent":["export * from './dictionaryManipulator/index';\nexport * from './interpreter/index';\nexport * from './localization/index';\nexport * from './transpiler/index';\nexport * from './types/index';\nexport * from './utils/checkIsURLAbsolute';\nexport * from './utils/isSameKeyPath';\nexport * from './utils/isValidReactElement';\n"],"mappings":"AAAA,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;","names":[]}
@@ -0,0 +1,25 @@
1
+ import configuration from "@intlayer/config/built";
2
+ import { checkIsURLAbsolute } from "../utils/checkIsURLAbsolute.mjs";
3
+ const getLocaleFromPath = (inputUrl) => {
4
+ const { defaultLocale, locales } = configuration.internationalization;
5
+ const isAbsoluteUrl = checkIsURLAbsolute(inputUrl);
6
+ let fixedInputUrl = inputUrl;
7
+ if (inputUrl.endsWith("/")) {
8
+ fixedInputUrl = inputUrl.slice(0, -1);
9
+ }
10
+ const url = isAbsoluteUrl ? new URL(fixedInputUrl) : new URL(fixedInputUrl, "http://example.com");
11
+ const pathname = url.pathname;
12
+ if (!pathname.startsWith("/")) {
13
+ return defaultLocale;
14
+ }
15
+ const pathSegments = pathname.split("/");
16
+ const firstSegment = pathSegments[1];
17
+ if (firstSegment && locales.includes(firstSegment)) {
18
+ return firstSegment;
19
+ }
20
+ return defaultLocale;
21
+ };
22
+ export {
23
+ getLocaleFromPath
24
+ };
25
+ //# sourceMappingURL=getLocaleFromPath.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/localization/getLocaleFromPath.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport type { Locales } from '@intlayer/config/client';\nimport { checkIsURLAbsolute } from '../utils/checkIsURLAbsolute';\n\n/**\n * Extracts the locale segment from the given URL or pathname if present.\n * If no locale is present, returns the default locale (en).\n *\n * Example:\n *\n * ```ts\n * getLocaleFromPath('/en/dashboard') // Returns 'en'\n * getLocaleFromPath('/fr/dashboard') // Returns 'fr'\n * getLocaleFromPath('/dashboard') // Returns 'en'\n * getLocaleFromPath('dashboard') // Returns 'en'\n * getLocaleFromPath('https://example.com/es/dashboard') // Returns 'es'\n * getLocaleFromPath('https://example.com/fr/dashboard') // Returns 'fr'\n * getLocaleFromPath('https://example.com/dashboard') // Returns 'en'\n * ```\n *\n * @param inputUrl - The complete URL string or pathname to process.\n * @returns The detected locale or default (en) if no locale is found\n */\nexport const getLocaleFromPath = (inputUrl: string): Locales => {\n // Define supported locales array\n const { defaultLocale, locales } = configuration.internationalization;\n\n // Determine if the original URL is absolute (includes protocol)\n const isAbsoluteUrl = checkIsURLAbsolute(inputUrl);\n\n let fixedInputUrl = inputUrl;\n\n if (inputUrl.endsWith('/')) {\n fixedInputUrl = inputUrl.slice(0, -1);\n }\n\n // Initialize a URL object if the URL is absolute\n // For relative URLs, use a dummy base to leverage the URL API\n const url = isAbsoluteUrl\n ? new URL(fixedInputUrl)\n : new URL(fixedInputUrl, 'http://example.com');\n\n const pathname = url.pathname;\n\n // Ensure the pathname starts with '/'\n if (!pathname.startsWith('/')) {\n // If not, return the default locale\n return defaultLocale;\n }\n\n // Split the pathname to extract the first segment\n const pathSegments = pathname.split('/');\n const firstSegment = pathSegments[1]; // The segment after the first '/'\n\n // Check if the first segment is a supported locale\n if (firstSegment && locales.includes(firstSegment as Locales)) {\n // Return the detected locale\n return firstSegment as Locales;\n }\n\n // Return the default locale if no locale is found in the path\n return defaultLocale;\n};\n"],"mappings":"AAAA,OAAO,mBAAmB;AAE1B,SAAS,0BAA0B;AAqB5B,MAAM,oBAAoB,CAAC,aAA8B;AAE9D,QAAM,EAAE,eAAe,QAAQ,IAAI,cAAc;AAGjD,QAAM,gBAAgB,mBAAmB,QAAQ;AAEjD,MAAI,gBAAgB;AAEpB,MAAI,SAAS,SAAS,GAAG,GAAG;AAC1B,oBAAgB,SAAS,MAAM,GAAG,EAAE;AAAA,EACtC;AAIA,QAAM,MAAM,gBACR,IAAI,IAAI,aAAa,IACrB,IAAI,IAAI,eAAe,oBAAoB;AAE/C,QAAM,WAAW,IAAI;AAGrB,MAAI,CAAC,SAAS,WAAW,GAAG,GAAG;AAE7B,WAAO;AAAA,EACT;AAGA,QAAM,eAAe,SAAS,MAAM,GAAG;AACvC,QAAM,eAAe,aAAa,CAAC;AAGnC,MAAI,gBAAgB,QAAQ,SAAS,YAAuB,GAAG;AAE7D,WAAO;AAAA,EACT;AAGA,SAAO;AACT;","names":[]}
@@ -1,21 +1,26 @@
1
- import { getLocaleName } from "./getLocaleName.mjs";
2
1
  import { getHTMLTextDir } from "./getHTMLTextDir.mjs";
2
+ import { getLocaleFromPath } from "./getLocaleFromPath.mjs";
3
3
  import { getLocaleLang } from "./getLocaleLang.mjs";
4
+ import { getLocaleName } from "./getLocaleName.mjs";
5
+ import { getLocalizedUrl } from "./getLocalizedUrl.mjs";
6
+ import { getMultilingualUrls } from "./getMultilingualUrls.mjs";
7
+ import { getPathWithoutLocale } from "./getPathWithoutLocale.mjs";
8
+ import { localeDetector } from "./localeDetector.mjs";
4
9
  import { localeList } from "./localeList.mjs";
10
+ import { localeFlatMap, localeMap } from "./localeMapper.mjs";
5
11
  import { localeResolver } from "./localeResolver.mjs";
6
- import { localeDetector } from "./localeDetector.mjs";
7
- import { getPathWithoutLocale } from "./getPathWithoutLocale.mjs";
8
- import { getMultilingualUrls } from "./getMultilingualUrls.mjs";
9
- import { getLocalizedUrl } from "./getLocalizedUrl.mjs";
10
12
  export {
11
13
  getHTMLTextDir,
14
+ getLocaleFromPath,
12
15
  getLocaleLang,
13
16
  getLocaleName,
14
17
  getLocalizedUrl,
15
18
  getMultilingualUrls,
16
19
  getPathWithoutLocale,
17
20
  localeDetector,
21
+ localeFlatMap,
18
22
  localeList,
23
+ localeMap,
19
24
  localeResolver
20
25
  };
21
26
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/localization/index.ts"],"sourcesContent":["export { getLocaleName } from './getLocaleName';\nexport { getHTMLTextDir } from './getHTMLTextDir';\nexport { getLocaleLang } from './getLocaleLang';\nexport { localeList } from './localeList';\nexport { localeResolver } from './localeResolver';\nexport { localeDetector } from './localeDetector';\nexport { getPathWithoutLocale } from './getPathWithoutLocale';\nexport { getMultilingualUrls } from './getMultilingualUrls';\nexport { getLocalizedUrl } from './getLocalizedUrl';\n"],"mappings":"AAAA,SAAS,qBAAqB;AAC9B,SAAS,sBAAsB;AAC/B,SAAS,qBAAqB;AAC9B,SAAS,kBAAkB;AAC3B,SAAS,sBAAsB;AAC/B,SAAS,sBAAsB;AAC/B,SAAS,4BAA4B;AACrC,SAAS,2BAA2B;AACpC,SAAS,uBAAuB;","names":[]}
1
+ {"version":3,"sources":["../../../src/localization/index.ts"],"sourcesContent":["export { getHTMLTextDir } from './getHTMLTextDir';\nexport { getLocaleFromPath } from './getLocaleFromPath';\nexport { getLocaleLang } from './getLocaleLang';\nexport { getLocaleName } from './getLocaleName';\nexport { getLocalizedUrl } from './getLocalizedUrl';\nexport { getMultilingualUrls } from './getMultilingualUrls';\nexport { getPathWithoutLocale } from './getPathWithoutLocale';\nexport { localeDetector } from './localeDetector';\nexport { localeList } from './localeList';\nexport { localeFlatMap, localeMap } from './localeMapper';\nexport { localeResolver } from './localeResolver';\n"],"mappings":"AAAA,SAAS,sBAAsB;AAC/B,SAAS,yBAAyB;AAClC,SAAS,qBAAqB;AAC9B,SAAS,qBAAqB;AAC9B,SAAS,uBAAuB;AAChC,SAAS,2BAA2B;AACpC,SAAS,4BAA4B;AACrC,SAAS,sBAAsB;AAC/B,SAAS,kBAAkB;AAC3B,SAAS,eAAe,iBAAiB;AACzC,SAAS,sBAAsB;","names":[]}
@@ -0,0 +1,29 @@
1
+ import configuration from "@intlayer/config/built";
2
+ const { internationalization, middleware } = configuration;
3
+ const { prefixDefault } = middleware;
4
+ const { locales, defaultLocale } = internationalization;
5
+ const baseLocaleData = {
6
+ defaultLocale,
7
+ locales
8
+ };
9
+ const localeMap = (mapper) => locales.map(
10
+ (locale) => mapper({
11
+ ...baseLocaleData,
12
+ locale,
13
+ isDefault: locale === defaultLocale,
14
+ urlPrefix: locale === defaultLocale && !prefixDefault ? "" : `/${locale}`
15
+ })
16
+ );
17
+ const localeFlatMap = (mapper) => locales.flatMap(
18
+ (locale) => mapper({
19
+ ...baseLocaleData,
20
+ locale,
21
+ isDefault: locale === defaultLocale,
22
+ urlPrefix: locale === defaultLocale && !prefixDefault ? "" : `/${locale}`
23
+ })
24
+ );
25
+ export {
26
+ localeFlatMap,
27
+ localeMap
28
+ };
29
+ //# sourceMappingURL=localeMapper.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/localization/localeMapper.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport { LocalesValues } from '@intlayer/config/client';\n\nconst { internationalization, middleware } = configuration;\nconst { prefixDefault } = middleware;\nconst { locales, defaultLocale } = internationalization;\n\nexport type LocaleData = {\n locale: LocalesValues;\n defaultLocale: LocalesValues;\n isDefault: boolean;\n locales: LocalesValues[];\n urlPrefix: string;\n};\n\nconst baseLocaleData = {\n defaultLocale: defaultLocale,\n locales,\n} satisfies Partial<LocaleData>;\n\n/**\n * Map the locale data to an array of objects\n *\n * @example\n * ```ts\n * const routes = localeMap((localizedData) =>\n * ({\n * path: localizedData.urlPrefix,\n * name: localizedData.locale,\n * isDefault: localizedData.isDefault,\n * locales: localizedData.locales,\n * defaultLocale: localizedData.defaultLocale,\n * }),\n * );\n *\n * // Result\n * [\n * { path: '/', name: 'en', isDefault: true, locales: ['en'], defaultLocale: 'en', urlPrefix: '' },\n * { path: '/fr', name: 'fr', isDefault: false, locales: ['fr'], defaultLocale: 'en', urlPrefix: '/fr' },\n * { path: '/es', name: 'es', isDefault: false, locales: ['es'], defaultLocale: 'en', urlPrefix: '/es' },\n * ]\n * ```\n *\n * @param mapper - The mapper function that returns an object\n * @returns An array of objects\n */\nexport const localeMap = <T extends object>(\n mapper: (locale: LocaleData) => T\n): T[] =>\n locales.map((locale) =>\n mapper({\n ...baseLocaleData,\n locale,\n isDefault: locale === defaultLocale,\n urlPrefix: locale === defaultLocale && !prefixDefault ? '' : `/${locale}`,\n })\n );\n\n/**\n * Flatten the locale map into a single array of objects\n *\n * @example\n * ```ts\n * const routes = localeMap((localizedData) =>\n * [{\n * path: localizedData.urlPrefix,\n * name: localizedData.locale,\n * isDefault: localizedData.isDefault,\n * locales: localizedData.locales,\n * defaultLocale: localizedData.defaultLocale,\n * }],\n * );\n *\n * // Result\n * [\n * { path: '/', name: 'en', isDefault: true, locales: ['en'], defaultLocale: 'en', urlPrefix: '' },\n * { path: '/fr', name: 'fr', isDefault: false, locales: ['fr'], defaultLocale: 'en', urlPrefix: '/fr' },\n * { path: '/es', name: 'es', isDefault: false, locales: ['es'], defaultLocale: 'en', urlPrefix: '/es' },\n * ]\n * ```\n *\n * @param mapper - The mapper function that returns an array of objects\n * @returns An array of objects\n */\nexport const localeFlatMap = <T>(mapper: (locale: LocaleData) => T[]): T[] =>\n locales.flatMap((locale) =>\n mapper({\n ...baseLocaleData,\n locale,\n isDefault: locale === defaultLocale,\n urlPrefix: locale === defaultLocale && !prefixDefault ? '' : `/${locale}`,\n })\n );\n"],"mappings":"AAAA,OAAO,mBAAmB;AAG1B,MAAM,EAAE,sBAAsB,WAAW,IAAI;AAC7C,MAAM,EAAE,cAAc,IAAI;AAC1B,MAAM,EAAE,SAAS,cAAc,IAAI;AAUnC,MAAM,iBAAiB;AAAA,EACrB;AAAA,EACA;AACF;AA4BO,MAAM,YAAY,CACvB,WAEA,QAAQ;AAAA,EAAI,CAAC,WACX,OAAO;AAAA,IACL,GAAG;AAAA,IACH;AAAA,IACA,WAAW,WAAW;AAAA,IACtB,WAAW,WAAW,iBAAiB,CAAC,gBAAgB,KAAK,IAAI,MAAM;AAAA,EACzE,CAAC;AACH;AA4BK,MAAM,gBAAgB,CAAI,WAC/B,QAAQ;AAAA,EAAQ,CAAC,WACf,OAAO;AAAA,IACL,GAAG;AAAA,IACH;AAAA,IACA,WAAW,WAAW;AAAA,IACtB,WAAW,WAAW,iBAAiB,CAAC,gBAAgB,KAAK,IAAI,MAAM;AAAA,EACzE,CAAC;AACH;","names":[]}
@@ -1,9 +1,9 @@
1
- export * from './transpiler/index';
2
- export * from './interpreter/index';
3
1
  export * from './dictionaryManipulator/index';
2
+ export * from './interpreter/index';
3
+ export * from './localization/index';
4
+ export * from './transpiler/index';
4
5
  export * from './types/index';
5
- export * from './utils/isSameKeyPath';
6
6
  export * from './utils/checkIsURLAbsolute';
7
+ export * from './utils/isSameKeyPath';
7
8
  export * from './utils/isValidReactElement';
8
- export * from './localization/index';
9
9
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC;AACnC,cAAc,qBAAqB,CAAC;AACpC,cAAc,+BAA+B,CAAC;AAC9C,cAAc,eAAe,CAAC;AAC9B,cAAc,uBAAuB,CAAC;AACtC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,sBAAsB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,+BAA+B,CAAC;AAC9C,cAAc,qBAAqB,CAAC;AACpC,cAAc,sBAAsB,CAAC;AACrC,cAAc,oBAAoB,CAAC;AACnC,cAAc,eAAe,CAAC;AAC9B,cAAc,4BAA4B,CAAC;AAC3C,cAAc,uBAAuB,CAAC;AACtC,cAAc,6BAA6B,CAAC"}
@@ -0,0 +1,22 @@
1
+ import type { Locales } from '@intlayer/config/client';
2
+ /**
3
+ * Extracts the locale segment from the given URL or pathname if present.
4
+ * If no locale is present, returns the default locale (en).
5
+ *
6
+ * Example:
7
+ *
8
+ * ```ts
9
+ * getLocaleFromPath('/en/dashboard') // Returns 'en'
10
+ * getLocaleFromPath('/fr/dashboard') // Returns 'fr'
11
+ * getLocaleFromPath('/dashboard') // Returns 'en'
12
+ * getLocaleFromPath('dashboard') // Returns 'en'
13
+ * getLocaleFromPath('https://example.com/es/dashboard') // Returns 'es'
14
+ * getLocaleFromPath('https://example.com/fr/dashboard') // Returns 'fr'
15
+ * getLocaleFromPath('https://example.com/dashboard') // Returns 'en'
16
+ * ```
17
+ *
18
+ * @param inputUrl - The complete URL string or pathname to process.
19
+ * @returns The detected locale or default (en) if no locale is found
20
+ */
21
+ export declare const getLocaleFromPath: (inputUrl: string) => Locales;
22
+ //# sourceMappingURL=getLocaleFromPath.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getLocaleFromPath.d.ts","sourceRoot":"","sources":["../../../src/localization/getLocaleFromPath.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAC;AAGvD;;;;;;;;;;;;;;;;;;GAkBG;AACH,eAAO,MAAM,iBAAiB,GAAI,UAAU,MAAM,KAAG,OAuCpD,CAAC"}
@@ -1,10 +1,12 @@
1
- export { getLocaleName } from './getLocaleName';
2
1
  export { getHTMLTextDir } from './getHTMLTextDir';
2
+ export { getLocaleFromPath } from './getLocaleFromPath';
3
3
  export { getLocaleLang } from './getLocaleLang';
4
+ export { getLocaleName } from './getLocaleName';
5
+ export { getLocalizedUrl } from './getLocalizedUrl';
6
+ export { getMultilingualUrls } from './getMultilingualUrls';
7
+ export { getPathWithoutLocale } from './getPathWithoutLocale';
8
+ export { localeDetector } from './localeDetector';
4
9
  export { localeList } from './localeList';
10
+ export { localeFlatMap, localeMap } from './localeMapper';
5
11
  export { localeResolver } from './localeResolver';
6
- export { localeDetector } from './localeDetector';
7
- export { getPathWithoutLocale } from './getPathWithoutLocale';
8
- export { getMultilingualUrls } from './getMultilingualUrls';
9
- export { getLocalizedUrl } from './getLocalizedUrl';
10
12
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/localization/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAC9D,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/localization/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAC9D,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC1D,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC"}
@@ -0,0 +1,63 @@
1
+ import { LocalesValues } from '@intlayer/config/client';
2
+ export type LocaleData = {
3
+ locale: LocalesValues;
4
+ defaultLocale: LocalesValues;
5
+ isDefault: boolean;
6
+ locales: LocalesValues[];
7
+ urlPrefix: string;
8
+ };
9
+ /**
10
+ * Map the locale data to an array of objects
11
+ *
12
+ * @example
13
+ * ```ts
14
+ * const routes = localeMap((localizedData) =>
15
+ * ({
16
+ * path: localizedData.urlPrefix,
17
+ * name: localizedData.locale,
18
+ * isDefault: localizedData.isDefault,
19
+ * locales: localizedData.locales,
20
+ * defaultLocale: localizedData.defaultLocale,
21
+ * }),
22
+ * );
23
+ *
24
+ * // Result
25
+ * [
26
+ * { path: '/', name: 'en', isDefault: true, locales: ['en'], defaultLocale: 'en', urlPrefix: '' },
27
+ * { path: '/fr', name: 'fr', isDefault: false, locales: ['fr'], defaultLocale: 'en', urlPrefix: '/fr' },
28
+ * { path: '/es', name: 'es', isDefault: false, locales: ['es'], defaultLocale: 'en', urlPrefix: '/es' },
29
+ * ]
30
+ * ```
31
+ *
32
+ * @param mapper - The mapper function that returns an object
33
+ * @returns An array of objects
34
+ */
35
+ export declare const localeMap: <T extends object>(mapper: (locale: LocaleData) => T) => T[];
36
+ /**
37
+ * Flatten the locale map into a single array of objects
38
+ *
39
+ * @example
40
+ * ```ts
41
+ * const routes = localeMap((localizedData) =>
42
+ * [{
43
+ * path: localizedData.urlPrefix,
44
+ * name: localizedData.locale,
45
+ * isDefault: localizedData.isDefault,
46
+ * locales: localizedData.locales,
47
+ * defaultLocale: localizedData.defaultLocale,
48
+ * }],
49
+ * );
50
+ *
51
+ * // Result
52
+ * [
53
+ * { path: '/', name: 'en', isDefault: true, locales: ['en'], defaultLocale: 'en', urlPrefix: '' },
54
+ * { path: '/fr', name: 'fr', isDefault: false, locales: ['fr'], defaultLocale: 'en', urlPrefix: '/fr' },
55
+ * { path: '/es', name: 'es', isDefault: false, locales: ['es'], defaultLocale: 'en', urlPrefix: '/es' },
56
+ * ]
57
+ * ```
58
+ *
59
+ * @param mapper - The mapper function that returns an array of objects
60
+ * @returns An array of objects
61
+ */
62
+ export declare const localeFlatMap: <T>(mapper: (locale: LocaleData) => T[]) => T[];
63
+ //# sourceMappingURL=localeMapper.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"localeMapper.d.ts","sourceRoot":"","sources":["../../../src/localization/localeMapper.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAMxD,MAAM,MAAM,UAAU,GAAG;IACvB,MAAM,EAAE,aAAa,CAAC;IACtB,aAAa,EAAE,aAAa,CAAC;IAC7B,SAAS,EAAE,OAAO,CAAC;IACnB,OAAO,EAAE,aAAa,EAAE,CAAC;IACzB,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC;AAOF;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,eAAO,MAAM,SAAS,GAAI,CAAC,SAAS,MAAM,EACxC,QAAQ,CAAC,MAAM,EAAE,UAAU,KAAK,CAAC,KAChC,CAAC,EAQD,CAAC;AAEJ;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,eAAO,MAAM,aAAa,GAAI,CAAC,EAAE,QAAQ,CAAC,MAAM,EAAE,UAAU,KAAK,CAAC,EAAE,KAAG,CAAC,EAQrE,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@intlayer/core",
3
- "version": "5.3.12",
3
+ "version": "5.4.0-canary.0",
4
4
  "private": false,
5
5
  "description": "Includes core Intlayer functions like translation, dictionary, and utility functions shared across multiple packages.",
6
6
  "keywords": [
@@ -75,9 +75,9 @@
75
75
  ],
76
76
  "dependencies": {
77
77
  "negotiator": "^1.0.0",
78
- "@intlayer/config": "5.3.12",
79
- "@intlayer/dictionaries-entry": "5.3.12",
80
- "@intlayer/api": "5.3.12"
78
+ "@intlayer/api": "5.4.0-canary.0",
79
+ "@intlayer/config": "5.4.0-canary.0",
80
+ "@intlayer/dictionaries-entry": "5.4.0-canary.0"
81
81
  },
82
82
  "devDependencies": {
83
83
  "@types/negotiator": "^0.6.3",
@@ -90,16 +90,16 @@
90
90
  "tsc-alias": "^1.8.11",
91
91
  "tsup": "^8.4.0",
92
92
  "typescript": "^5.8.2",
93
- "@utils/eslint-config": "1.0.4",
94
- "@utils/ts-config": "1.0.4",
95
93
  "@utils/ts-config-types": "1.0.4",
96
- "@utils/tsup-config": "1.0.4"
94
+ "@utils/tsup-config": "1.0.4",
95
+ "@utils/ts-config": "1.0.4",
96
+ "@utils/eslint-config": "1.0.4"
97
97
  },
98
98
  "peerDependencies": {
99
- "@intlayer/api": "5.3.12",
100
- "@intlayer/config": "5.3.12",
101
- "@intlayer/dictionaries-entry": "5.3.12",
102
- "intlayer": "5.3.12"
99
+ "@intlayer/config": "5.4.0-canary.0",
100
+ "@intlayer/dictionaries-entry": "5.4.0-canary.0",
101
+ "@intlayer/api": "5.4.0-canary.0",
102
+ "intlayer": "5.4.0-canary.0"
103
103
  },
104
104
  "engines": {
105
105
  "node": ">=14.18"