typed-locales 1.0.2 → 1.0.4

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/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import baseFormatters from './formatters';
2
- import type { Formatter } from './formatters';
1
+ import baseFormatters from './src/formatters';
2
+ import type { Formatter } from './src/formatters';
3
3
  type ValueType = null | number | string | undefined | object;
4
4
  export type BaseFormatters = keyof typeof baseFormatters;
5
5
  export type InternalDeepStringify<T> = {
@@ -42,4 +42,4 @@ type DeepOmitNever<T> = {
42
42
  } extends infer U ? keyof U extends never ? never : U : never;
43
43
  export type Simplify<T> = InternalSimplify<DeepOmitNever<T>>;
44
44
  export declare const getTranslate: <Translations, ExtraFormattersType extends string = string, ExtraFormatters extends Record<ExtraFormattersType, Formatter> = Record<ExtraFormattersType, Formatter>>(translations: Translations, locale: string, extraFormatters?: ExtraFormatters) => <Key extends DotNestedLeafKeys<Translations>>(key: Key, ...arguments_: InterpolationProperties<GetValue<Translations, Key> & string, IsPlural<Translations, Key>> extends Record<string, never> ? [] : [params: Simplify<InterpolationProperties<GetValue<Translations, Key> & string, IsPlural<Translations, Key>>>]) => GetValue<Translations, Key>;
45
- export {};
45
+ export { initReact } from './src/react';
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import baseFormatters from './formatters';
1
+ import baseFormatters from './src/formatters';
2
2
  // Given a translations object returns a function that can be used to translate keys
3
3
  export const getTranslate = (translations, locale, extraFormatters) => {
4
4
  const formatters = { ...baseFormatters, ...extraFormatters };
@@ -80,3 +80,4 @@ export const getTranslate = (translations, locale, extraFormatters) => {
80
80
  }
81
81
  return translate;
82
82
  };
83
+ export { initReact } from './src/react';
@@ -1,6 +1,6 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import { createContext, useContext, useState } from 'react';
3
- import { getTranslate } from './index';
3
+ import { getTranslate } from '../index';
4
4
  // Initial translation always should be loaded
5
5
  export const initReact = (translations, initialLocale, extraFormatters) => {
6
6
  const TranslationContext = createContext(undefined);
@@ -1,4 +1,4 @@
1
- import { initReact } from './react';
1
+ import { initReact } from '../react';
2
2
  import en from './translations/en';
3
3
  const customFormatters = {
4
4
  myCustomFormatter: () => 'Hello im custom',
@@ -1,4 +1,4 @@
1
- import type { BaseFormatters, RemoveReadonlyDeep } from ".";
1
+ import type { BaseFormatters, RemoveReadonlyDeep } from "..";
2
2
  type ErrorMessage<Value extends string, T extends string> = `You are using an invalid formatter: ${T} in: "${Value}"`;
3
3
  type ExtractFormatter<T extends string> = T extends `${string}{${string}|${infer F}}${string}` ? F : never;
4
4
  type CountOpenBraces<T extends string, Count extends readonly unknown[] = []> = T extends `${infer First}${infer Rest}` ? First extends '{' ? CountOpenBraces<Rest, [...Count, unknown]> : CountOpenBraces<Rest, Count> : Count['length'];
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "typed-locales",
3
- "version": "1.0.2",
3
+ "version": "1.0.4",
4
4
  "description": "Type safe utilities for translating strings",
5
- "main": "index.js",
5
+ "main": "dist/index.js",
6
6
  "type": "module",
7
7
  "scripts": {
8
- "build": "tsc",
8
+ "build": "rimraf dist && tsc",
9
9
  "dev": "tsx watch src/test.tsx"
10
10
  },
11
11
  "keywords": [],
@@ -15,6 +15,7 @@
15
15
  "dependencies": {
16
16
  "react": "^19.1.0",
17
17
  "react-dom": "^19.1.0",
18
+ "rimraf": "^6.0.1",
18
19
  "tsx": "^4.19.4",
19
20
  "typescript": "^5.8.3"
20
21
  },
package/dist/test.d.ts DELETED
@@ -1 +0,0 @@
1
- export {};
package/dist/test.js DELETED
@@ -1,6 +0,0 @@
1
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { useTranslation } from './config';
3
- const Test = () => {
4
- const { t, locale, setLocale } = useTranslation();
5
- return _jsxs("div", { children: [t('test'), t('nested.test', { translation: 'translated text' }), t('nested.deep.again', { value: 'someValue', otherValue: 'anotherValue' }), t('withValue', { value: 'myValue' }), t('multipleValues', { one: '1', two: '2', three: '3' }), t('examplePlural', { count: 0 }), t('examplePlural', { count: 1 }), t('examplePlural', { count: 5 }), t('examplePluralWithOtherValues', { count: 0, user: 'Alice', otherUser: undefined }), t('examplePluralWithOtherValues', { count: 1, user: 'Alice', otherUser: undefined }), t('examplePluralWithOtherValues', { count: 123, user: 'Alice', otherUser: 'Bob' }), t('exampleWithFormatting', { value: 'TEXT', other: 'Text' }), t('exampleWithJSONFormatter', { data: { key: 'value' } }), t('pluralWithNestedSubstitution', { count: 0, query: 'search', user: undefined }), t('pluralWithNestedSubstitution', { count: 1, query: 'search', user: 'john' }), t('pluralWithNestedSubstitution', { count: 5, query: 'search', user: 'john' }), t('mixedPluralNested', { count: 0, itemType: 'book', location: 'shelf' }), t('mixedPluralNested', { count: 1, itemType: 'book', location: 'shelf' }), t('mixedPluralNested', { count: 10, itemType: 'book', location: 'shelf' }), t('onlyFormat', { value: 'capitalize this' }), t('escapeBraces'), locale, _jsx("button", { onClick: () => setLocale('es'), children: "Change locale" })] });
6
- };
@@ -1 +0,0 @@
1
- {"root":["../src/formatters.ts","../src/index.ts","../src/react.tsx","../src/test.tsx","../src/translations/en.ts","../src/translations/es.ts"],"errors":true,"version":"5.8.2"}
File without changes
File without changes
File without changes