typed-locales 1.0.40 → 1.0.42

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.
@@ -1,5 +1,5 @@
1
1
  import type { ValueType } from './index.js';
2
- export type Formatter = (value: ValueType, locale: string) => string;
2
+ export type Formatter = (value: ValueType, locale: string) => ValueType;
3
3
  declare const formatters: {
4
4
  readonly lowercase: (value: ValueType) => string;
5
5
  readonly uppercase: (value: ValueType) => string;
@@ -1 +1 @@
1
- {"version":3,"file":"formatters.d.ts","sourceRoot":"","sources":["../src/formatters.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAE5C,MAAM,MAAM,SAAS,GAAG,CAAC,KAAK,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,KAAK,MAAM,CAAC;AAErE,QAAA,MAAM,UAAU;;;;;;;;;CAoB8B,CAAC;AAE/C,eAAe,UAAU,CAAC"}
1
+ {"version":3,"file":"formatters.d.ts","sourceRoot":"","sources":["../src/formatters.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAE5C,MAAM,MAAM,SAAS,GAAG,CAAC,KAAK,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,KAAK,SAAS,CAAC;AAExE,QAAA,MAAM,UAAU;;;;;;;;;CAoB8B,CAAC;AAE/C,eAAe,UAAU,CAAC"}
package/dist/index.js CHANGED
@@ -66,7 +66,7 @@ export const getTranslate = (translations, locale, extraFormatters, baseTranslat
66
66
  value = value.replaceAll(new RegExp(`{${parameter}(:\\w+)?(\\|[\\w|]+)?}`, 'g'), (match, _type, formatters_) => {
67
67
  const parsedFormatters = (formatters_?.split('|').filter(Boolean) ??
68
68
  []);
69
- let formattedValue = String(value_);
69
+ let formattedValue = value_;
70
70
  for (const formatter of parsedFormatters) {
71
71
  if (!formatters[formatter]) {
72
72
  console.error(`Non existing formatter "${formatter}" used in key "${key}"`);
@@ -74,7 +74,7 @@ export const getTranslate = (translations, locale, extraFormatters, baseTranslat
74
74
  }
75
75
  formattedValue = formatters[formatter](formattedValue, locale);
76
76
  }
77
- return formattedValue;
77
+ return String(formattedValue);
78
78
  });
79
79
  }
80
80
  }
package/dist/react.d.ts CHANGED
@@ -6,7 +6,9 @@ export interface TranslationContextType {
6
6
  setLocale: (locale: Locales) => Promise<Locales>;
7
7
  t: ReturnType<typeof getTranslate>;
8
8
  }
9
- export declare const initReact: (initialTranslation: TranslationType, initialLocale: Locales, allTranslations: Record<Locales, (() => Promise<TranslationType>) | TranslationType>, extraFormatters: ExtraFormatters) => {
9
+ export declare const initReact: (initialTranslation: TranslationType, initialLocale: Locales, allTranslations: Record<Locales, (() => Promise<{
10
+ default: TranslationType;
11
+ }>) | TranslationType>, extraFormatters: ExtraFormatters) => {
10
12
  TranslationProvider: ({ children }: {
11
13
  children: React.ReactNode;
12
14
  }) => import("react/jsx-runtime").JSX.Element;
@@ -1 +1 @@
1
- {"version":3,"file":"react.d.ts","sourceRoot":"","sources":["../src/react.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA2D,MAAM,OAAO,CAAC;AAEhF,OAAO,EAAE,YAAY,EAAE,KAAK,eAAe,EAAE,KAAK,OAAO,EAAE,KAAK,eAAe,EAAE,MAAM,YAAY,CAAC;AAEpG,MAAM,WAAW,sBAAsB;IACtC,SAAS,EAAE,OAAO,CAAC;IACnB,MAAM,EAAE,OAAO,CAAC;IAChB,SAAS,EAAE,CAAC,MAAM,EAAE,OAAO,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;IACjD,CAAC,EAAE,UAAU,CAAC,OAAO,YAAY,CAAC,CAAC;CACnC;AAGD,eAAO,MAAM,SAAS,GACrB,oBAAoB,eAAe,EACnC,eAAe,OAAO,EACtB,iBAAiB,MAAM,CAAC,OAAO,EAAE,CAAC,MAAM,OAAO,CAAC,eAAe,CAAC,CAAC,GAAG,eAAe,CAAC,EACpF,iBAAiB,eAAe;wCAKW;QAAE,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAA;KAAE;;CAkExE,CAAC"}
1
+ {"version":3,"file":"react.d.ts","sourceRoot":"","sources":["../src/react.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA2D,MAAM,OAAO,CAAC;AAEhF,OAAO,EAAE,YAAY,EAAE,KAAK,eAAe,EAAE,KAAK,OAAO,EAAE,KAAK,eAAe,EAAE,MAAM,YAAY,CAAC;AAEpG,MAAM,WAAW,sBAAsB;IACtC,SAAS,EAAE,OAAO,CAAC;IACnB,MAAM,EAAE,OAAO,CAAC;IAChB,SAAS,EAAE,CAAC,MAAM,EAAE,OAAO,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;IACjD,CAAC,EAAE,UAAU,CAAC,OAAO,YAAY,CAAC,CAAC;CACnC;AAGD,eAAO,MAAM,SAAS,GACrB,oBAAoB,eAAe,EACnC,eAAe,OAAO,EACtB,iBAAiB,MAAM,CAAC,OAAO,EAAE,CAAC,MAAM,OAAO,CAAC;IAAC,OAAO,EAAE,eAAe,CAAA;CAAC,CAAC,CAAC,GAAG,eAAe,CAAC,EAC/F,iBAAiB,eAAe;wCAKW;QAAE,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAA;KAAE;;CAkExE,CAAC"}
package/dist/react.js CHANGED
@@ -17,7 +17,7 @@ export const initReact = (initialTranslation, initialLocale, allTranslations, ex
17
17
  let translationData;
18
18
  if (typeof translationOrLoader === 'function') {
19
19
  setState(previous => ({ ...previous, isLoading: true }));
20
- translationData = await translationOrLoader();
20
+ translationData = await translationOrLoader().then(t => t.default);
21
21
  }
22
22
  else {
23
23
  translationData = translationOrLoader;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "typed-locales",
3
- "version": "1.0.40",
3
+ "version": "1.0.42",
4
4
  "description": "Type safe utilities for translating strings",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",