intor-translator 1.4.13 → 1.4.14

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/README.md CHANGED
@@ -1,16 +1,12 @@
1
1
  <h1 align="center">Intor Translator</h1>
2
2
 
3
- <div align="center">
4
-
5
- A modern **i18n engine** powered by a customizable, type-safe translation pipeline.
6
- Easy to use, modular at its core, and fully extensible.
7
-
8
- </div>
3
+ <p align="center">
4
+ The <a href="https://github.com/yiming-liao/intor">Intor</a> translation engine
5
+ </p>
9
6
 
10
7
  <div align="center">
11
8
 
12
9
  [![NPM version](https://img.shields.io/npm/v/intor-translator?style=flat&colorA=000000&colorB=000000)](https://www.npmjs.com/package/intor-translator)
13
- [![Bundle size](https://img.shields.io/bundlephobia/minzip/intor-translator?style=flat&colorA=000000&colorB=000000)](https://bundlephobia.com/package/intor-translator)
14
10
  [![Coverage Status](https://img.shields.io/coveralls/github/yiming-liao/intor-translator.svg?branch=main&style=flat&colorA=000000&colorB=000000)](https://coveralls.io/github/yiming-liao/intor-translator?branch=main)
15
11
  [![TypeScript](https://img.shields.io/badge/TypeScript-%E2%9C%94-blue?style=flat&colorA=000000&colorB=000000)](https://www.typescriptlang.org/)
16
12
  [![License](https://img.shields.io/npm/l/intor-translator?style=flat&colorA=000000&colorB=000000)](LICENSE)
@@ -19,9 +15,9 @@ Easy to use, modular at its core, and fully extensible.
19
15
 
20
16
  ## Features
21
17
 
22
- - 🔧 **Modular Pipeline** – A pluggable, hook-driven flow for any translation logic.
23
- - **Typed Autocomplete** – Inferred keys and locales with precise, reliable completion.
24
- - 🌐 **Framework-Agnostic** – A lightweight engine that runs anywhere in JavaScript.
18
+ - **Modular Pipeline** – A pluggable, hook-driven flow for any translation logic.
19
+ - **Typed Autocomplete** – Inferred keys and locales with precise, reliable completion.
20
+ - **Framework-Agnostic** – A lightweight engine that runs anywhere in JavaScript.
25
21
 
26
22
  ## Installation
27
23
 
@@ -94,7 +90,7 @@ Hooks run through the pipeline and can intercept any stage, use them to:
94
90
 
95
91
  ---
96
92
 
97
- # Rich Message Processing
93
+ ## Rich Message Processing
98
94
 
99
95
  This module provides a semantic message processing flow for **_translated rich-formatted strings_**.
100
96
 
@@ -107,3 +103,5 @@ Read the documentation: [Message Processing ↗](https://github.com/yiming-liao/
107
103
 
108
104
  **_For more advanced usage, see the full examples._**
109
105
  [View examples ↗](https://github.com/yiming-liao/intor-translator/tree/main/examples)
106
+
107
+ **_See full benchmark details:_** [bench ↗](https://github.com/yiming-liao/intor-translator/tree/main/bench)
package/dist/index.d.cts CHANGED
@@ -126,6 +126,8 @@ type AtPath<MessageSchema, PK extends string> = PK extends `${infer Head}.${infe
126
126
  type IfLocaleMessages<T, Then, Else> = T extends LocaleMessages ? Then : Else;
127
127
  /** Narrows a type to `MessageObject`, otherwise resolves to never. */
128
128
  type IfMessageObject<T> = T extends MessageObject ? T : never;
129
+ /** Detects whether `M` is the generic runtime `LocaleMessages` type. */
130
+ type IsRuntime<M> = [M] extends [LocaleMessages] ? [LocaleMessages] extends [M] ? true : false : false;
129
131
 
130
132
  /**
131
133
  * Dot-separated leaf keys derived from a single message object.
@@ -191,7 +193,7 @@ type Value<M, K extends string> = K extends `${infer Head}.${infer Tail}` ? Head
191
193
  * LocalizedValue<{ en: { a: { b: { c: string }; z: string } } }, "a.b.c">; // => string
192
194
  * ```
193
195
  */
194
- type LocalizedValue<M, K extends string> = IfLocaleMessages<M, Value<M[keyof M], K>, string>;
196
+ type LocalizedValue<M, K extends string> = IsRuntime<M> extends true ? string : M extends LocaleMessages ? Value<M[keyof M], K> : never;
195
197
  /**
196
198
  * Value resolved under a scoped prefix key.
197
199
  *
@@ -200,7 +202,7 @@ type LocalizedValue<M, K extends string> = IfLocaleMessages<M, Value<M[keyof M],
200
202
  * ScopedValue<{ en: { a: { b: { c: string }; z: string } } }, "a", "b.c">; // => string
201
203
  * ```
202
204
  */
203
- type ScopedValue<M, PK extends string, K extends string> = IfLocaleMessages<M, Value<AtPath<M[keyof M], PK>, K>, string>;
205
+ type ScopedValue<M, PK extends string, K extends string> = IsRuntime<M> extends true ? string : M extends LocaleMessages ? Value<AtPath<M[keyof M], PK>, K> : never;
204
206
 
205
207
  /**
206
208
  * Generic replacement object used when no schema is available.
package/dist/index.d.ts CHANGED
@@ -126,6 +126,8 @@ type AtPath<MessageSchema, PK extends string> = PK extends `${infer Head}.${infe
126
126
  type IfLocaleMessages<T, Then, Else> = T extends LocaleMessages ? Then : Else;
127
127
  /** Narrows a type to `MessageObject`, otherwise resolves to never. */
128
128
  type IfMessageObject<T> = T extends MessageObject ? T : never;
129
+ /** Detects whether `M` is the generic runtime `LocaleMessages` type. */
130
+ type IsRuntime<M> = [M] extends [LocaleMessages] ? [LocaleMessages] extends [M] ? true : false : false;
129
131
 
130
132
  /**
131
133
  * Dot-separated leaf keys derived from a single message object.
@@ -191,7 +193,7 @@ type Value<M, K extends string> = K extends `${infer Head}.${infer Tail}` ? Head
191
193
  * LocalizedValue<{ en: { a: { b: { c: string }; z: string } } }, "a.b.c">; // => string
192
194
  * ```
193
195
  */
194
- type LocalizedValue<M, K extends string> = IfLocaleMessages<M, Value<M[keyof M], K>, string>;
196
+ type LocalizedValue<M, K extends string> = IsRuntime<M> extends true ? string : M extends LocaleMessages ? Value<M[keyof M], K> : never;
195
197
  /**
196
198
  * Value resolved under a scoped prefix key.
197
199
  *
@@ -200,7 +202,7 @@ type LocalizedValue<M, K extends string> = IfLocaleMessages<M, Value<M[keyof M],
200
202
  * ScopedValue<{ en: { a: { b: { c: string }; z: string } } }, "a", "b.c">; // => string
201
203
  * ```
202
204
  */
203
- type ScopedValue<M, PK extends string, K extends string> = IfLocaleMessages<M, Value<AtPath<M[keyof M], PK>, K>, string>;
205
+ type ScopedValue<M, PK extends string, K extends string> = IsRuntime<M> extends true ? string : M extends LocaleMessages ? Value<AtPath<M[keyof M], PK>, K> : never;
204
206
 
205
207
  /**
206
208
  * Generic replacement object used when no schema is available.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "intor-translator",
3
- "version": "1.4.13",
4
- "description": "🤖 A modern, type-safe i18n engine.",
3
+ "version": "1.4.14",
4
+ "description": "The Intor translation engine",
5
5
  "author": {
6
6
  "name": "Yiming Liao",
7
7
  "email": "yimingliao.official@gmail.com",
@@ -59,7 +59,8 @@
59
59
  "build": "tsup",
60
60
  "prepublishOnly": "yarn build",
61
61
  "examples:html": "vite --config examples/html/basic/vite.config.ts",
62
- "examples:html:rich-message": "vite --config examples/html/rich-message/vite.config.ts"
62
+ "examples:html:rich-message": "vite --config examples/html/rich-message/vite.config.ts",
63
+ "bench:runtime": "tsx bench/runtime/index.ts"
63
64
  },
64
65
  "dependencies": {
65
66
  "rura": "^1.0.8"