@nano_kit/intl 3.2.1 → 4.1.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/dist/format/markup.d.ts +10 -8
- package/dist/format/markup.d.ts.map +1 -1
- package/dist/format/match.d.ts +2 -1
- package/dist/format/match.d.ts.map +1 -1
- package/dist/format/params.d.ts +3 -3
- package/dist/format/params.d.ts.map +1 -1
- package/dist/format/rich.d.ts +13 -11
- package/dist/format/rich.d.ts.map +1 -1
- package/dist/format/text.d.ts +10 -7
- package/dist/format/text.d.ts.map +1 -1
- package/dist/format/types.d.ts +0 -1
- package/dist/format/types.d.ts.map +1 -1
- package/dist/format/wrap.d.ts +4 -2
- package/dist/format/wrap.d.ts.map +1 -1
- package/dist/index.development.js +72 -24
- package/dist/index.development.js.map +1 -1
- package/dist/index.production.js +72 -24
- package/dist/index.production.js.map +1 -1
- package/dist/types.d.ts +4 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +2 -2
package/dist/format/markup.d.ts
CHANGED
|
@@ -16,20 +16,22 @@ export declare function markup(tags: MarkupTags): Format<string | undefined, str
|
|
|
16
16
|
*/
|
|
17
17
|
export declare function markup(fallback: string, tags: MarkupTags): Format<string | undefined, string>;
|
|
18
18
|
/**
|
|
19
|
-
* Creates a markup formatter that
|
|
20
|
-
*
|
|
19
|
+
* Creates a markup formatter that fills values into the message through a preformat.
|
|
20
|
+
* The preformat gets the whole message, so it can be `params`, `plural`, `match` or a composition of them.
|
|
21
|
+
* Only the tags of the message are mapped: values filled in by the preformat are never parsed as tags.
|
|
21
22
|
* @param tags - Tag handlers used to map markup tags to strings.
|
|
22
|
-
* @param preformat - Formatter of
|
|
23
|
+
* @param preformat - Formatter of the message, like `params`, `plural` or `match`.
|
|
23
24
|
* @returns Formatter that returns a message function of the preformat parameters.
|
|
24
25
|
*/
|
|
25
|
-
export declare function markup<P>(tags: MarkupTags, preformat: RichPreformat<P>): Format<
|
|
26
|
+
export declare function markup<P, I = string | undefined>(tags: MarkupTags, preformat: RichPreformat<P, I>): Format<I, (params: P) => string | undefined>;
|
|
26
27
|
/**
|
|
27
|
-
* Creates a markup formatter with a fallback message that
|
|
28
|
-
*
|
|
28
|
+
* Creates a markup formatter with a fallback message that fills values into the message through a preformat.
|
|
29
|
+
* The preformat gets the whole message, so it can be `params`, `plural`, `match` or a composition of them.
|
|
30
|
+
* Only the tags of the message are mapped: values filled in by the preformat are never parsed as tags.
|
|
29
31
|
* @param fallback - Message used when the input is `undefined` or `null`.
|
|
30
32
|
* @param tags - Tag handlers used to map markup tags to strings.
|
|
31
|
-
* @param preformat - Formatter of
|
|
33
|
+
* @param preformat - Formatter of the message, like `params`, `plural` or `match`.
|
|
32
34
|
* @returns Formatter that returns a message function of the preformat parameters.
|
|
33
35
|
*/
|
|
34
|
-
export declare function markup<P>(fallback: string, tags: MarkupTags, preformat: RichPreformat<P>): Format<
|
|
36
|
+
export declare function markup<P, I = string | undefined>(fallback: string, tags: MarkupTags, preformat: RichPreformat<P, I>): Format<I, (params: P) => string>;
|
|
35
37
|
//# sourceMappingURL=markup.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"markup.d.ts","sourceRoot":"","sources":["../../src/format/markup.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,YAAY,CAAA;AACxC,OAAO,EACL,KAAK,aAAa,EAGnB,MAAM,WAAW,CAAA;AAElB,MAAM,MAAM,SAAS,GAAG,CAAC,MAAM,EAAE,MAAM,KAAK,MAAM,CAAA;AAElD,MAAM,MAAM,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,CAAA;AAElD;;;;GAIG;AACH,wBAAgB,MAAM,CACpB,IAAI,EAAE,UAAU,GACf,MAAM,CAAC,MAAM,GAAG,SAAS,EAAE,MAAM,GAAG,SAAS,CAAC,CAAA;AAEjD;;;;;GAKG;AACH,wBAAgB,MAAM,CACpB,QAAQ,EAAE,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
|
package/dist/format/match.d.ts
CHANGED
|
@@ -10,13 +10,14 @@ export type MatchFn<K extends string, B extends Partial<Record<string, AnyFormat
|
|
|
10
10
|
export type CasesFn<K extends string, B extends Partial<Record<string, AnyFormat>>> = ((ctx: FormatContext, input: FormatsInput<B> | undefined, resolvedCases: Record<string, string | undefined | MatchFn<K, B>>) => void) & {
|
|
11
11
|
s: true;
|
|
12
12
|
};
|
|
13
|
+
type CaseFormat = AnyFormat<string | undefined | FnWithParams<any>>;
|
|
13
14
|
type GetKey = (param: any, locale: string, cases: Record<string, unknown>) => string;
|
|
14
15
|
/**
|
|
15
16
|
* Creates a reusable cases resolver for `match`.
|
|
16
17
|
* @param cases - Case formatters keyed by possible resolved values.
|
|
17
18
|
* @returns Resolver that formats all cases for the current context and translation input.
|
|
18
19
|
*/
|
|
19
|
-
export declare function cases<const K extends string, const B extends Partial<Record<string,
|
|
20
|
+
export declare function cases<const K extends string, const B extends Partial<Record<string, CaseFormat>>>(cases: B): CasesFn<K, B>;
|
|
20
21
|
/**
|
|
21
22
|
* Creates a case key resolver that falls back to a known case when the parameter value is missing.
|
|
22
23
|
* @param key - Case key used when the parameter value does not exist in resolved cases.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"match.d.ts","sourceRoot":"","sources":["../../src/format/match.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,SAAS,EAIf,MAAM,iBAAiB,CAAA;AACxB,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAChD,OAAO,KAAK,EACV,SAAS,
|
|
1
|
+
{"version":3,"file":"match.d.ts","sourceRoot":"","sources":["../../src/format/match.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,SAAS,EAIf,MAAM,iBAAiB,CAAA;AACxB,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAChD,OAAO,KAAK,EACV,SAAS,EACT,YAAY,EACZ,MAAM,EACN,YAAY,EACZ,mBAAmB,E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nano_kit/store';
|
|
2
|
-
import type {
|
|
2
|
+
import type { Format, FormatInput, FormatOutput, FnWithParams, ParamsOf, UnionToIntersection } from './types.js';
|
|
3
3
|
export type ReplacementValue = string | number | boolean | bigint | undefined;
|
|
4
4
|
export type ParamsFormats = Record<string, Format<any, ReplacementValue>>;
|
|
5
5
|
export type RequiredParamKeys<P extends ParamsFormats> = {
|
|
@@ -12,7 +12,7 @@ export type ParamsValues<P extends ParamsFormats> = {
|
|
|
12
12
|
[K in OptionalParamKeys<P>]?: Signalish<FormatInput<P[K]> | undefined>;
|
|
13
13
|
};
|
|
14
14
|
export type ParamsFn<P extends ParamsFormats> = FnWithParams<ParamsValues<P>>;
|
|
15
|
-
type PreformatOutput = string | undefined |
|
|
15
|
+
type PreformatOutput = string | undefined | FnWithParams<any>;
|
|
16
16
|
type ComposedParamsFn<P extends ParamsFormats, O> = FnWithParams<ParamsValues<P> & UnionToIntersection<ParamsOf<O>>>;
|
|
17
17
|
/**
|
|
18
18
|
* Creates a parameter interpolation formatter.
|
|
@@ -23,7 +23,7 @@ export declare function params<const P extends ParamsFormats>(params: P): Format
|
|
|
23
23
|
/**
|
|
24
24
|
* Creates a parameter interpolation formatter that first applies another formatter.
|
|
25
25
|
* @param params - Parameter formatters keyed by placeholder name.
|
|
26
|
-
* @param preformat - Formatter applied before replacing placeholders. `match` and `plural` leave the placeholders of the parameters listed here to be replaced by these formatters.
|
|
26
|
+
* @param preformat - Formatter applied before replacing placeholders. `match` and `plural` inside it leave the placeholders of the parameters listed here to be replaced by these formatters.
|
|
27
27
|
* @returns Formatter that replaces `{key}` placeholders using provided parameter values.
|
|
28
28
|
*/
|
|
29
29
|
export declare function params<const P extends ParamsFormats, F = string | undefined, O extends PreformatOutput = string | undefined | ParamsFn<P>>(params: P, preformat: Format<F, O>): Format<F, ComposedParamsFn<P, O>>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"params.d.ts","sourceRoot":"","sources":["../../src/format/params.ts"],"names":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,aAAa,IAAI,YAAY,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,CAAA;AAE7E,KAAK,eAAe,GAAG,MAAM,GAAG,SAAS,GAAG,YAAY,CAAC,GAAG,CAAC,CAAA;AAE7D,KAAK,gBAAgB,CAAC,CAAC,SAAS,aAAa,EAAE,CAAC,IAAI,YAAY,CAAC,YAAY,CAAC,CAAC,CAAC,GAAG,mBAAmB,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;AAIpH;;;;GAIG;AACH,wBAAgB,MAAM,CAAC,KAAK,CAAC,CAAC,SAAS,aAAa,EAClD,MAAM,EAAE,CAAC,GACR,MAAM,CAAC,MAAM,GAAG,SAAS,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAA;AAE1C;;;;;GAKG;AACH,wBAAgB,MAAM,CACpB,KAAK,CAAC,CAAC,SAAS,aAAa,EAC7B,CAAC,GAAG,MAAM,GAAG,SAAS,EACtB,CAAC,SAAS,eAAe,GAAG,MAAM,GAAG,SAAS,GAAG,QAAQ,CAAC,CAAC,CAAC,EAE5D,MAAM,EAAE,CAAC,EACT,SAAS,EAAE,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,GACtB,MAAM,CAAC,CAAC,EAAE,gBAAgB,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAA"}
|
package/dist/format/rich.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import type { FnWithParams, Format } from './types.js';
|
|
|
2
2
|
export type RichChunks<T> = (string | T)[];
|
|
3
3
|
export type RichTag<T> = (chunks: RichChunks<T>, index: number) => T;
|
|
4
4
|
export type RichTags<T> = Record<string, RichTag<T>>;
|
|
5
|
-
export type RichPreformat<P
|
|
5
|
+
export type RichPreformat<P, I = string | undefined> = Format<I, FnWithParams<P>>;
|
|
6
6
|
/**
|
|
7
7
|
* Creates a rich-text formatter.
|
|
8
8
|
* @param tags - Tag handlers used to map rich-text tags to output chunks.
|
|
@@ -17,30 +17,32 @@ export declare function rich<T>(tags: RichTags<T>): Format<string | undefined, R
|
|
|
17
17
|
*/
|
|
18
18
|
export declare function rich<T>(fallback: string, tags: RichTags<T>): Format<string | undefined, RichChunks<T>>;
|
|
19
19
|
/**
|
|
20
|
-
* Creates a rich-text formatter that
|
|
21
|
-
*
|
|
20
|
+
* Creates a rich-text formatter that fills values into the message through a preformat.
|
|
21
|
+
* The preformat gets the whole message, so it can be `params`, `plural`, `match` or a composition of them.
|
|
22
|
+
* Only the tags of the message are mapped: values filled in by the preformat are never parsed as tags.
|
|
22
23
|
* @param tags - Tag handlers used to map rich-text tags to output chunks.
|
|
23
|
-
* @param preformat - Formatter of
|
|
24
|
+
* @param preformat - Formatter of the message, like `params`, `plural` or `match`.
|
|
24
25
|
* @returns Formatter that returns a message function of the preformat parameters.
|
|
25
26
|
*/
|
|
26
|
-
export declare function rich<T, P>(tags: RichTags<T>, preformat: RichPreformat<P>): Format<
|
|
27
|
+
export declare function rich<T, P, I = string | undefined>(tags: RichTags<T>, preformat: RichPreformat<P, I>): Format<I, (params: P) => RichChunks<T> | undefined>;
|
|
27
28
|
/**
|
|
28
|
-
* Creates a rich-text formatter with a fallback message that
|
|
29
|
-
*
|
|
29
|
+
* Creates a rich-text formatter with a fallback message that fills values into the message through a preformat.
|
|
30
|
+
* The preformat gets the whole message, so it can be `params`, `plural`, `match` or a composition of them.
|
|
31
|
+
* Only the tags of the message are mapped: values filled in by the preformat are never parsed as tags.
|
|
30
32
|
* @param fallback - Message used when the input is `undefined` or `null`.
|
|
31
33
|
* @param tags - Tag handlers used to map rich-text tags to output chunks.
|
|
32
|
-
* @param preformat - Formatter of
|
|
34
|
+
* @param preformat - Formatter of the message, like `params`, `plural` or `match`.
|
|
33
35
|
* @returns Formatter that returns a message function of the preformat parameters.
|
|
34
36
|
*/
|
|
35
|
-
export declare function rich<T, P>(fallback: string, tags: RichTags<T>, preformat: RichPreformat<P>): Format<
|
|
37
|
+
export declare function rich<T, P, I = string | undefined>(fallback: string, tags: RichTags<T>, preformat: RichPreformat<P, I>): Format<I, (params: P) => RichChunks<T>>;
|
|
36
38
|
/**
|
|
37
39
|
* Creates a rich-text formatter.
|
|
38
40
|
* @param fallbackOrTags - Fallback message or tag handlers.
|
|
39
41
|
* @param tagsOrPreformat - Tag handlers used when fallback is provided, or the preformat.
|
|
40
|
-
* @param maybePreformat - Formatter of
|
|
42
|
+
* @param maybePreformat - Formatter of the message used when fallback is provided.
|
|
41
43
|
* @returns Formatter that returns mapped chunks, a message function of them or `undefined`.
|
|
42
44
|
*/
|
|
43
|
-
export declare function rich<T, P>(fallbackOrTags: string | RichTags<T> | undefined, tagsOrPreformat?: RichTags<T> | RichPreformat<P>, maybePreformat?: RichPreformat<P>): Format<
|
|
45
|
+
export declare function rich<T, P, I = string | undefined>(fallbackOrTags: string | RichTags<T> | undefined, tagsOrPreformat?: RichTags<T> | RichPreformat<P, I>, maybePreformat?: RichPreformat<P, I>): Format<I, RichChunks<T> | ((params: P) => RichChunks<T> | undefined) | undefined>;
|
|
44
46
|
/**
|
|
45
47
|
* Maps rich-text tags in a string to chunks using provided tag handlers.
|
|
46
48
|
* Each handler call receives an unique index, usable as a key for framework nodes.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rich.d.ts","sourceRoot":"","sources":["../../src/format/rich.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,YAAY,EACZ,MAAM,EACP,MAAM,YAAY,CAAA;AAEnB,MAAM,MAAM,UAAU,CAAC,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,EAAE,CAAA;AAE1C,MAAM,MAAM,OAAO,CAAC,CAAC,IAAI,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,MAAM,KAAK,CAAC,CAAA;AAEpE,MAAM,MAAM,QAAQ,CAAC,CAAC,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC,CAAA;AAEpD,MAAM,MAAM,aAA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* Creates a string formatter.
|
|
4
4
|
* @returns Formatter that returns the input string or `undefined`.
|
|
@@ -11,24 +11,27 @@ export declare function text(): Format<string | undefined>;
|
|
|
11
11
|
*/
|
|
12
12
|
export declare function text(fallback: string): Format<string | undefined, string>;
|
|
13
13
|
/**
|
|
14
|
-
* Creates a formatter that uppercases
|
|
15
|
-
* @param format -
|
|
14
|
+
* Creates a formatter that uppercases the text of another formatter.
|
|
15
|
+
* @param format - Formatter of a text, or of a message function like `params` or `plural`.
|
|
16
16
|
* @returns Formatter with uppercased output.
|
|
17
17
|
*/
|
|
18
18
|
export declare function uppercase<T>(format: Format<T, string | undefined>): Format<T, string | undefined>;
|
|
19
19
|
export declare function uppercase<T>(format: Format<T, string>): Format<T, string>;
|
|
20
|
+
export declare function uppercase<T, P>(format: Format<T, FnWithParams<P>>): Format<T, FnWithParams<P>>;
|
|
20
21
|
/**
|
|
21
|
-
* Creates a formatter that lowercases
|
|
22
|
-
* @param format -
|
|
22
|
+
* Creates a formatter that lowercases the text of another formatter.
|
|
23
|
+
* @param format - Formatter of a text, or of a message function like `params` or `plural`.
|
|
23
24
|
* @returns Formatter with lowercased output.
|
|
24
25
|
*/
|
|
25
26
|
export declare function lowercase<T>(format: Format<T, string | undefined>): Format<T, string | undefined>;
|
|
26
27
|
export declare function lowercase<T>(format: Format<T, string>): Format<T, string>;
|
|
28
|
+
export declare function lowercase<T, P>(format: Format<T, FnWithParams<P>>): Format<T, FnWithParams<P>>;
|
|
27
29
|
/**
|
|
28
|
-
* Creates a formatter that capitalizes
|
|
29
|
-
* @param format -
|
|
30
|
+
* Creates a formatter that capitalizes the text of another formatter.
|
|
31
|
+
* @param format - Formatter of a text, or of a message function like `params` or `plural`.
|
|
30
32
|
* @returns Formatter with the first character uppercased.
|
|
31
33
|
*/
|
|
32
34
|
export declare function capitalize<T>(format: Format<T, string | undefined>): Format<T, string | undefined>;
|
|
33
35
|
export declare function capitalize<T>(format: Format<T, string>): Format<T, string>;
|
|
36
|
+
export declare function capitalize<T, P>(format: Format<T, FnWithParams<P>>): Format<T, FnWithParams<P>>;
|
|
34
37
|
//# sourceMappingURL=text.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"text.d.ts","sourceRoot":"","sources":["../../src/format/text.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"text.d.ts","sourceRoot":"","sources":["../../src/format/text.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,YAAY,EACZ,MAAM,EACP,MAAM,YAAY,CAAA;AAGnB;;;GAGG;AACH,wBAAgB,IAAI,IAAI,MAAM,CAAC,MAAM,GAAG,SAAS,CAAC,CAAA;AAElD;;;;GAIG;AACH,wBAAgB,IAAI,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,GAAG,SAAS,EAAE,MAAM,CAAC,CAAA;AA8B1E;;;;GAIG;AACH,wBAAgB,SAAS,CAAC,CAAC,EACzB,MAAM,EAAE,MAAM,CAAC,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC,GACpC,MAAM,CAAC,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC,CAAA;AAEhC,wBAAgB,SAAS,CAAC,CAAC,EACzB,MAAM,EAAE,MAAM,CAAC,CAAC,EAAE,MAAM,CAAC,GACxB,MAAM,CAAC,CAAC,EAAE,MAAM,CAAC,CAAA;AAEpB,wBAAgB,SAAS,CAAC,CAAC,EAAE,CAAC,EAC5B,MAAM,EAAE,MAAM,CAAC,CAAC,EAAE,YAAY,CAAC,CAAC,CAAC,CAAC,GACjC,MAAM,CAAC,CAAC,EAAE,YAAY,CAAC,CAAC,CAAC,CAAC,CAAA;AAS7B;;;;GAIG;AACH,wBAAgB,SAAS,CAAC,CAAC,EACzB,MAAM,EAAE,MAAM,CAAC,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC,GACpC,MAAM,CAAC,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC,CAAA;AAEhC,wBAAgB,SAAS,CAAC,CAAC,EACzB,MAAM,EAAE,MAAM,CAAC,CAAC,EAAE,MAAM,CAAC,GACxB,MAAM,CAAC,CAAC,EAAE,MAAM,CAAC,CAAA;AAEpB,wBAAgB,SAAS,CAAC,CAAC,EAAE,CAAC,EAC5B,MAAM,EAAE,MAAM,CAAC,CAAC,EAAE,YAAY,CAAC,CAAC,CAAC,CAAC,GACjC,MAAM,CAAC,CAAC,EAAE,YAAY,CAAC,CAAC,CAAC,CAAC,CAAA;AAS7B;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,CAAC,EAC1B,MAAM,EAAE,MAAM,CAAC,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC,GACpC,MAAM,CAAC,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC,CAAA;AAEhC,wBAAgB,UAAU,CAAC,CAAC,EAC1B,MAAM,EAAE,MAAM,CAAC,CAAC,EAAE,MAAM,CAAC,GACxB,MAAM,CAAC,CAAC,EAAE,MAAM,CAAC,CAAA;AAEpB,wBAAgB,UAAU,CAAC,CAAC,EAAE,CAAC,EAC7B,MAAM,EAAE,MAAM,CAAC,CAAC,EAAE,YAAY,CAAC,CAAC,CAAC,CAAC,GACjC,MAAM,CAAC,CAAC,EAAE,YAAY,CAAC,CAAC,CAAC,CAAC,CAAA"}
|
package/dist/format/types.d.ts
CHANGED
|
@@ -11,7 +11,6 @@ export type FormatsInput<T extends Partial<Record<PropertyKey, AnyFormat>>> = Pa
|
|
|
11
11
|
[K in keyof T]: FormatInput<T[K]>;
|
|
12
12
|
}>;
|
|
13
13
|
export type FnWithParams<P> = (params: P) => string | undefined;
|
|
14
|
-
export type FnWithAnyParams = (params: any, formats?: Record<string, unknown>) => string | undefined;
|
|
15
14
|
export interface IntlFormat<T> {
|
|
16
15
|
format(value: T, ...args: unknown[]): string;
|
|
17
16
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/format/types.ts"],"names":[],"mappings":"AAAA,O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AI,CAAC,MAAM,EAAE,CAAC,KAAK,MAAM,GAAG,SAAS,CAAA;AAE/D,MAAM,WAAW,UAAU,CAAC,CAAC;IAC3B,MAAM,CAAC,KAAK,EAAE,CAAC,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,MAAM,CAAA;CAC7C;AAED,MAAM,WAAW,eAAe,CAAC,CAAC,CAAE,SAAQ,UAAU,CAAC,CAAC,CAAC;IACvD,WAAW,CAAC,IAAI,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC,GAAG,MAAM,CAAA;CACpC"}
|
package/dist/format/wrap.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { type Accessor
|
|
1
|
+
import { type Accessor } from '@nano_kit/store';
|
|
2
2
|
import type { Format } from './types.js';
|
|
3
|
+
type ReadValue<T> = Exclude<T, Accessor<any>>;
|
|
3
4
|
export type WrapValues<A> = A extends Accessor<infer V> ? V : A extends Record<string, unknown> ? {
|
|
4
|
-
[K in keyof A]:
|
|
5
|
+
[K in keyof A]: ReadValue<A[K]>;
|
|
5
6
|
} : A;
|
|
6
7
|
export type WrapArgs<R> = [R] extends [(arg: infer A) => unknown] ? [message: R, values: WrapValues<A>, locale: string] : [message: R, locale: string];
|
|
7
8
|
export type Wrapped<R, O> = [R] extends [(arg: infer A) => unknown] ? (arg: A) => O : O;
|
|
@@ -12,4 +13,5 @@ export type Wrapped<R, O> = [R] extends [(arg: infer A) => unknown] ? (arg: A) =
|
|
|
12
13
|
* @returns Formatter that returns what `fn` returns, or a message function returning it.
|
|
13
14
|
*/
|
|
14
15
|
export declare function wrap<I, R, O>(format: Format<I, R>, fn: (...args: WrapArgs<R>) => O): Format<I, Wrapped<R, O>>;
|
|
16
|
+
export {};
|
|
15
17
|
//# sourceMappingURL=wrap.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wrap.d.ts","sourceRoot":"","sources":["../../src/format/wrap.ts"],"names":[],"mappings":"AAAA,OAA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AAC,CAAC,CAAC,KAAK,CAAC,GAC9B,MAAM,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAA"}
|
|
@@ -10,20 +10,31 @@ function raw(fallback) {
|
|
|
10
10
|
function text(fallback) {
|
|
11
11
|
return /* @__PURE__ */ raw(fallback);
|
|
12
12
|
}
|
|
13
|
+
/**
|
|
14
|
+
* Applies a text transform to the output of a formatter, or to the text of the message function it returns.
|
|
15
|
+
* @param format - Formatter to transform.
|
|
16
|
+
* @param fn - Text transform.
|
|
17
|
+
* @returns Formatter with transformed output.
|
|
18
|
+
*/
|
|
19
|
+
/* @__NO_SIDE_EFFECTS__ */
|
|
20
|
+
function transform(format, fn) {
|
|
21
|
+
return (ctx, input) => {
|
|
22
|
+
const message = format(ctx, input);
|
|
23
|
+
const locale = ctx.$locale();
|
|
24
|
+
return isFunction(message) ? (params) => fn(message(params), locale) : fn(message, locale);
|
|
25
|
+
};
|
|
26
|
+
}
|
|
13
27
|
/* @__NO_SIDE_EFFECTS__ */
|
|
14
28
|
function uppercase(format) {
|
|
15
|
-
return
|
|
29
|
+
return /* @__PURE__ */ transform(format, (message, locale) => message?.toLocaleUpperCase(locale));
|
|
16
30
|
}
|
|
17
31
|
/* @__NO_SIDE_EFFECTS__ */
|
|
18
32
|
function lowercase(format) {
|
|
19
|
-
return
|
|
20
|
-
}
|
|
21
|
-
function toCapitalize(message, locale) {
|
|
22
|
-
return message === void 0 ? message : message.charAt(0).toLocaleUpperCase(locale) + message.slice(1);
|
|
33
|
+
return /* @__PURE__ */ transform(format, (message, locale) => message?.toLocaleLowerCase(locale));
|
|
23
34
|
}
|
|
24
35
|
/* @__NO_SIDE_EFFECTS__ */
|
|
25
36
|
function capitalize(format) {
|
|
26
|
-
return (
|
|
37
|
+
return /* @__PURE__ */ transform(format, (message, locale) => message === void 0 ? message : message.charAt(0).toLocaleUpperCase(locale) + message.slice(1));
|
|
27
38
|
}
|
|
28
39
|
//#endregion
|
|
29
40
|
//#region src/utils.ts
|
|
@@ -146,24 +157,42 @@ function rich(fallbackOrTags, tagsOrPreformat, maybePreformat) {
|
|
|
146
157
|
tags = tagsOrPreformat;
|
|
147
158
|
}
|
|
148
159
|
return (ctx, input) => {
|
|
149
|
-
const text = input ?? fallback;
|
|
150
|
-
if (preformat)
|
|
151
|
-
|
|
160
|
+
const text = /* @__PURE__ */ markTags(input ?? fallback);
|
|
161
|
+
if (preformat) {
|
|
162
|
+
const message = preformat(ctx, text);
|
|
163
|
+
return (params) => {
|
|
164
|
+
const filled = message(params);
|
|
165
|
+
return filled === void 0 ? filled : /* @__PURE__ */ parseTags(filled, tags);
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
return text === void 0 ? text : /* @__PURE__ */ parseTags(text, tags);
|
|
152
169
|
};
|
|
153
170
|
}
|
|
154
|
-
const tagRegex =
|
|
171
|
+
const tagRegex = /(\0?)<(\/?)([A-Za-z][\w.-]*)\s*(\/?)>/g;
|
|
155
172
|
/**
|
|
156
|
-
*
|
|
157
|
-
*
|
|
158
|
-
*
|
|
159
|
-
|
|
160
|
-
|
|
173
|
+
* Marks the tags of a message, nested in forms and cases at any depth, before values are filled into it.
|
|
174
|
+
* @param input - Message, or forms and cases of messages.
|
|
175
|
+
* @returns Message with marked tags.
|
|
176
|
+
*/
|
|
177
|
+
/* @__NO_SIDE_EFFECTS__ */
|
|
178
|
+
function markTags(input) {
|
|
179
|
+
if (typeof input === "string") return input.replace(tagRegex, "\0$&");
|
|
180
|
+
if (input && typeof input === "object") {
|
|
181
|
+
const marked = {};
|
|
182
|
+
for (const key in input) marked[key] = /* @__PURE__ */ markTags(input[key]);
|
|
183
|
+
return marked;
|
|
184
|
+
}
|
|
185
|
+
return input;
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* Maps the marked tags of a message to chunks. Other tags stay text.
|
|
189
|
+
* @param input - Message with marked tags.
|
|
161
190
|
* @param tags - Tag handlers used to map known tags.
|
|
162
191
|
* @param formatText - Formatter of each text piece between the tags, applied before the tag handlers get it.
|
|
163
192
|
* @returns Mapped chunks.
|
|
164
193
|
*/
|
|
165
194
|
/* @__NO_SIDE_EFFECTS__ */
|
|
166
|
-
function
|
|
195
|
+
function parseTags(input, tags, formatText = String) {
|
|
167
196
|
const root = {
|
|
168
197
|
tag: "",
|
|
169
198
|
chunks: []
|
|
@@ -174,7 +203,8 @@ function mapTags(input, tags, formatText = String) {
|
|
|
174
203
|
let match;
|
|
175
204
|
tagRegex.lastIndex = 0;
|
|
176
205
|
while (match = tagRegex.exec(input)) {
|
|
177
|
-
const [, closing, tag, selfClosing] = match;
|
|
206
|
+
const [, marked, closing, tag, selfClosing] = match;
|
|
207
|
+
if (!marked) continue;
|
|
178
208
|
const current = stack[stack.length - 1];
|
|
179
209
|
if (match.index > lastIndex) current.chunks.push(formatText(input.slice(lastIndex, match.index)));
|
|
180
210
|
lastIndex = tagRegex.lastIndex;
|
|
@@ -199,6 +229,20 @@ function mapTags(input, tags, formatText = String) {
|
|
|
199
229
|
}
|
|
200
230
|
return root.chunks;
|
|
201
231
|
}
|
|
232
|
+
/**
|
|
233
|
+
* Maps rich-text tags in a string to chunks using provided tag handlers.
|
|
234
|
+
* Each handler call receives an unique index, usable as a key for framework nodes.
|
|
235
|
+
* Self-closing tags are mapped with empty chunks.
|
|
236
|
+
* Unknown or malformed tags are ignored as markup and only their text content is kept.
|
|
237
|
+
* @param input - Rich-text input string.
|
|
238
|
+
* @param tags - Tag handlers used to map known tags.
|
|
239
|
+
* @param formatText - Formatter of each text piece between the tags, applied before the tag handlers get it.
|
|
240
|
+
* @returns Mapped chunks.
|
|
241
|
+
*/
|
|
242
|
+
/* @__NO_SIDE_EFFECTS__ */
|
|
243
|
+
function mapTags(input, tags, formatText) {
|
|
244
|
+
return /* @__PURE__ */ parseTags(/* @__PURE__ */ markTags(input), tags, formatText);
|
|
245
|
+
}
|
|
202
246
|
//#endregion
|
|
203
247
|
//#region src/format/markup.ts
|
|
204
248
|
/* @__NO_SIDE_EFFECTS__ */
|
|
@@ -239,7 +283,7 @@ function params(params, preformat) {
|
|
|
239
283
|
return formatted;
|
|
240
284
|
};
|
|
241
285
|
}
|
|
242
|
-
const re = new RegExp(`{${key}}`, "
|
|
286
|
+
const re = new RegExp(`{${key}}`, "gi");
|
|
243
287
|
const replace = (ctx, text, params) => text.replace(re, () => format(ctx, $get(params[key])));
|
|
244
288
|
if (replaceAll) {
|
|
245
289
|
const prevReplace = replaceAll;
|
|
@@ -247,9 +291,12 @@ function params(params, preformat) {
|
|
|
247
291
|
} else replaceAll = replace;
|
|
248
292
|
}
|
|
249
293
|
return (ctx, input) => {
|
|
250
|
-
const preformatted = preformat ? preformat(
|
|
294
|
+
const preformatted = preformat ? preformat({
|
|
295
|
+
...ctx,
|
|
296
|
+
f: params
|
|
297
|
+
}, input) : input;
|
|
251
298
|
if (isFunction(preformatted)) return (values) => {
|
|
252
|
-
const text = preformatted(values
|
|
299
|
+
const text = preformatted(values);
|
|
253
300
|
if (text === void 0 || !replaceAll) return text;
|
|
254
301
|
return replaceAll(ctx, text, values);
|
|
255
302
|
};
|
|
@@ -312,7 +359,7 @@ function other(key) {
|
|
|
312
359
|
*/
|
|
313
360
|
/* @__NO_SIDE_EFFECTS__ */
|
|
314
361
|
function match(param, casesOrGetKey, maybeGetKey) {
|
|
315
|
-
const valuePattern = new RegExp(`{${param}}`, "
|
|
362
|
+
const valuePattern = new RegExp(`{${param}}`, "gi");
|
|
316
363
|
let cases;
|
|
317
364
|
let getKey;
|
|
318
365
|
if (casesOrGetKey?.s) {
|
|
@@ -322,16 +369,17 @@ function match(param, casesOrGetKey, maybeGetKey) {
|
|
|
322
369
|
return (ctx, input) => {
|
|
323
370
|
const locale = ctx.$locale();
|
|
324
371
|
const isString = typeof input === "string";
|
|
372
|
+
const filled = ctx.f?.[param];
|
|
325
373
|
let resolvedCases = input ?? {};
|
|
326
374
|
if (cases && !isString) {
|
|
327
375
|
resolvedCases = { ...resolvedCases };
|
|
328
376
|
cases(ctx, input, resolvedCases);
|
|
329
377
|
}
|
|
330
|
-
return (params
|
|
378
|
+
return (params) => {
|
|
331
379
|
const value = $get(typeof params === "object" ? params[param] : params);
|
|
332
380
|
const resolvedCase = isString ? input : resolvedCases[getKey(value, locale, resolvedCases)];
|
|
333
|
-
const message = isFunction(resolvedCase) ? resolvedCase(params
|
|
334
|
-
return
|
|
381
|
+
const message = isFunction(resolvedCase) ? resolvedCase(params) : resolvedCase;
|
|
382
|
+
return filled ? message : message?.replace(valuePattern, value);
|
|
335
383
|
};
|
|
336
384
|
};
|
|
337
385
|
}
|