@messagevisor/types 0.0.1 → 0.2.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/CHANGELOG.md +29 -0
- package/LICENSE +21 -0
- package/README.md +9 -0
- package/package.json +39 -13
- package/src/datafile.d.ts +49 -0
- package/src/entities.d.ts +312 -0
- package/src/format.d.ts +184 -0
- package/src/index.d.ts +5 -0
- package/src/index.js +1 -0
- package/src/tests.d.ts +124 -0
- package/tsconfig.json +8 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# Change Log
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
|
+
|
|
6
|
+
# [0.2.0](https://github.com/messagevisor/messagevisor/compare/v0.1.0...v0.2.0) (2026-06-02)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @messagevisor/types
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
# [0.1.0](https://github.com/messagevisor/messagevisor/compare/v0.0.2...v0.1.0) (2026-05-31)
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
### Features
|
|
18
|
+
|
|
19
|
+
* trigger publish ([4699bda](https://github.com/messagevisor/messagevisor/commit/4699bdad7d077858e90aa754afefb4815c9d58c1))
|
|
20
|
+
* trigger publish ([fb7ad48](https://github.com/messagevisor/messagevisor/commit/fb7ad48f01986e683588c298acdebfbcc58346d8))
|
|
21
|
+
* type updates ([4006311](https://github.com/messagevisor/messagevisor/commit/4006311d2269e11342327b4c7da9572c93b64a24))
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
## 0.0.2 (2026-05-31)
|
|
28
|
+
|
|
29
|
+
**Note:** Version bump only for package @messagevisor/types
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Fahad Heylaal (https://fahad19.com)
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
package/README.md
ADDED
package/package.json
CHANGED
|
@@ -1,15 +1,41 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
2
|
+
"name": "@messagevisor/types",
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "Common Typescript types for Messagevisor",
|
|
5
|
+
"main": "src/index.js",
|
|
6
|
+
"module": "src/index.js",
|
|
7
|
+
"types": "src/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./src/index.d.ts",
|
|
11
|
+
"import": "./src/index.js",
|
|
12
|
+
"require": "./src/index.js"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"scripts": {
|
|
16
|
+
"transpile": "echo 'Nothing to transpile'",
|
|
17
|
+
"dist": "echo 'Nothing to dist'",
|
|
18
|
+
"build": "tsc ./src/index.d.ts",
|
|
19
|
+
"test": "echo 'Nothing to test in types package'",
|
|
20
|
+
"typecheck": "tsc --noEmit --skipLibCheck -p tsconfig.json"
|
|
21
|
+
},
|
|
22
|
+
"author": {
|
|
23
|
+
"name": "Fahad Heylaal",
|
|
24
|
+
"url": "https://fahad19.com"
|
|
25
|
+
},
|
|
26
|
+
"homepage": "https://messagevisor.com",
|
|
27
|
+
"keywords": [],
|
|
28
|
+
"repository": {
|
|
29
|
+
"type": "git",
|
|
30
|
+
"url": "https://github.com/messagevisor/messagevisor.git"
|
|
31
|
+
},
|
|
32
|
+
"publishConfig": {
|
|
33
|
+
"access": "public",
|
|
34
|
+
"registry": "https://registry.npmjs.org/"
|
|
35
|
+
},
|
|
36
|
+
"bugs": {
|
|
37
|
+
"url": "https://github.com/messagevisor/messagevisor/issues"
|
|
38
|
+
},
|
|
39
|
+
"license": "MIT",
|
|
40
|
+
"gitHead": "53cfef1a5ae28724b24226dd3a32ff813b063ce3"
|
|
15
41
|
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
Condition,
|
|
3
|
+
GroupSegment,
|
|
4
|
+
TargetKey,
|
|
5
|
+
SegmentKey,
|
|
6
|
+
LocaleKey,
|
|
7
|
+
LocaleDirection,
|
|
8
|
+
MessageKey,
|
|
9
|
+
MessageMeta,
|
|
10
|
+
Segment,
|
|
11
|
+
Translation,
|
|
12
|
+
} from "./entities";
|
|
13
|
+
import type { FormatPresets } from "./format";
|
|
14
|
+
|
|
15
|
+
export interface MessageOverride {
|
|
16
|
+
key: string;
|
|
17
|
+
|
|
18
|
+
// one of them need to be provided
|
|
19
|
+
conditions?: Condition | Condition[] | "*"; // string can be "*" or stringified datafile condition
|
|
20
|
+
segments?: GroupSegment | GroupSegment[] | "*"; // string can be "*", segment key, or stringified datafile segment group
|
|
21
|
+
|
|
22
|
+
translation: Translation;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export interface DatafileMessage {
|
|
26
|
+
deprecated?: boolean;
|
|
27
|
+
deprecationWarning?: string;
|
|
28
|
+
meta?: MessageMeta;
|
|
29
|
+
overrides?: MessageOverride[];
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export interface DatafileContent {
|
|
33
|
+
schemaVersion: string;
|
|
34
|
+
messagevisorVersion: string;
|
|
35
|
+
revision: string;
|
|
36
|
+
target: TargetKey;
|
|
37
|
+
locale: LocaleKey;
|
|
38
|
+
direction?: LocaleDirection;
|
|
39
|
+
formats?: FormatPresets;
|
|
40
|
+
segments: {
|
|
41
|
+
[key: SegmentKey]: Segment;
|
|
42
|
+
};
|
|
43
|
+
messages: {
|
|
44
|
+
[key: MessageKey]: DatafileMessage;
|
|
45
|
+
};
|
|
46
|
+
translations: {
|
|
47
|
+
[key: MessageKey]: Translation;
|
|
48
|
+
};
|
|
49
|
+
}
|
|
@@ -0,0 +1,312 @@
|
|
|
1
|
+
import type { FormatPresets } from "./format";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Common
|
|
5
|
+
*/
|
|
6
|
+
export type Matrix = Record<string, unknown[]>;
|
|
7
|
+
|
|
8
|
+
export type ExampleKey = string;
|
|
9
|
+
|
|
10
|
+
export interface ExampleBase {
|
|
11
|
+
matrix?: Matrix;
|
|
12
|
+
index?: number; // based on matrix
|
|
13
|
+
|
|
14
|
+
description?: string;
|
|
15
|
+
values?: Record<string, unknown>;
|
|
16
|
+
context?: Context;
|
|
17
|
+
formats?: FormatPresets;
|
|
18
|
+
timeZone?: string;
|
|
19
|
+
currency?: string;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Locales
|
|
24
|
+
*/
|
|
25
|
+
export type LocaleKey = string;
|
|
26
|
+
export type LocaleDirection = "ltr" | "rtl";
|
|
27
|
+
|
|
28
|
+
export type LocaleExample = ExampleBase & {
|
|
29
|
+
// one of them below needs to be provided
|
|
30
|
+
rawMessage?: string;
|
|
31
|
+
message?: MessageKey;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
export interface Locale {
|
|
35
|
+
key?: LocaleKey;
|
|
36
|
+
promotable?: boolean;
|
|
37
|
+
description?: string;
|
|
38
|
+
direction?: LocaleDirection;
|
|
39
|
+
inheritFormatsFrom?: string;
|
|
40
|
+
inheritTranslationsFrom?: string;
|
|
41
|
+
mergeExamplesFrom?: string;
|
|
42
|
+
formats?: FormatPresets;
|
|
43
|
+
examples?: LocaleExample[];
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Attributes
|
|
48
|
+
*/
|
|
49
|
+
export type AttributeKey = string;
|
|
50
|
+
|
|
51
|
+
export interface AttributeObjectValue {
|
|
52
|
+
[key: AttributeKey]: AttributeValue;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export type AttributeValue =
|
|
56
|
+
| string
|
|
57
|
+
| number
|
|
58
|
+
| boolean
|
|
59
|
+
| Date
|
|
60
|
+
| null
|
|
61
|
+
| undefined
|
|
62
|
+
| string[]
|
|
63
|
+
| AttributeObjectValue
|
|
64
|
+
| Record<string, unknown>;
|
|
65
|
+
|
|
66
|
+
export type AttributeType =
|
|
67
|
+
| "boolean"
|
|
68
|
+
| "string"
|
|
69
|
+
| "integer"
|
|
70
|
+
| "double"
|
|
71
|
+
| "date"
|
|
72
|
+
| "object"
|
|
73
|
+
| "array";
|
|
74
|
+
|
|
75
|
+
export interface AttributeSchema {
|
|
76
|
+
description?: string; // only available in YAML files
|
|
77
|
+
enum?: AttributeValue[];
|
|
78
|
+
const?: AttributeValue;
|
|
79
|
+
maximum?: number;
|
|
80
|
+
minimum?: number;
|
|
81
|
+
maxLength?: number;
|
|
82
|
+
minLength?: number;
|
|
83
|
+
pattern?: string;
|
|
84
|
+
items?: AttributeSchema;
|
|
85
|
+
maxItems?: number;
|
|
86
|
+
minItems?: number;
|
|
87
|
+
uniqueItems?: boolean;
|
|
88
|
+
required?: string[];
|
|
89
|
+
properties?: {
|
|
90
|
+
[key: AttributeKey]: AttributeSchema;
|
|
91
|
+
};
|
|
92
|
+
additionalProperties?: AttributeSchema;
|
|
93
|
+
oneOf?: AttributeSchema[];
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export type Attribute = AttributeSchema & {
|
|
97
|
+
key?: AttributeKey;
|
|
98
|
+
archived?: boolean; // only available in YAML files
|
|
99
|
+
promotable?: boolean;
|
|
100
|
+
type?: AttributeType; // required when not using oneOf
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Context
|
|
105
|
+
*/
|
|
106
|
+
export interface Context {
|
|
107
|
+
[key: AttributeKey]: AttributeValue;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Conditions
|
|
112
|
+
*/
|
|
113
|
+
export type Operator =
|
|
114
|
+
| "equals"
|
|
115
|
+
| "notEquals"
|
|
116
|
+
| "exists"
|
|
117
|
+
| "notExists"
|
|
118
|
+
|
|
119
|
+
// numeric
|
|
120
|
+
| "greaterThan"
|
|
121
|
+
| "greaterThanOrEquals"
|
|
122
|
+
| "lessThan"
|
|
123
|
+
| "lessThanOrEquals"
|
|
124
|
+
|
|
125
|
+
// string
|
|
126
|
+
| "contains"
|
|
127
|
+
| "notContains"
|
|
128
|
+
| "startsWith"
|
|
129
|
+
| "endsWith"
|
|
130
|
+
|
|
131
|
+
// date comparisons
|
|
132
|
+
| "before"
|
|
133
|
+
| "after"
|
|
134
|
+
|
|
135
|
+
// array of strings
|
|
136
|
+
| "includes"
|
|
137
|
+
| "notIncludes"
|
|
138
|
+
|
|
139
|
+
// feature
|
|
140
|
+
| "isEnabled"
|
|
141
|
+
| "isDisabled"
|
|
142
|
+
|
|
143
|
+
// experiment
|
|
144
|
+
| "hasVariation"
|
|
145
|
+
|
|
146
|
+
// array of strings
|
|
147
|
+
| "in"
|
|
148
|
+
| "notIn";
|
|
149
|
+
|
|
150
|
+
export type ConditionValue =
|
|
151
|
+
| string
|
|
152
|
+
| number
|
|
153
|
+
| boolean
|
|
154
|
+
| Date
|
|
155
|
+
| null
|
|
156
|
+
| undefined
|
|
157
|
+
| Array<string | number | boolean | null>;
|
|
158
|
+
|
|
159
|
+
export interface AttributeCondition {
|
|
160
|
+
attribute: AttributeKey;
|
|
161
|
+
|
|
162
|
+
operator:
|
|
163
|
+
| "equals"
|
|
164
|
+
| "notEquals"
|
|
165
|
+
| "exists"
|
|
166
|
+
| "notExists"
|
|
167
|
+
| "greaterThan"
|
|
168
|
+
| "greaterThanOrEquals"
|
|
169
|
+
| "lessThan"
|
|
170
|
+
| "lessThanOrEquals"
|
|
171
|
+
| "contains"
|
|
172
|
+
| "notContains"
|
|
173
|
+
| "startsWith"
|
|
174
|
+
| "endsWith"
|
|
175
|
+
| "before"
|
|
176
|
+
| "after"
|
|
177
|
+
| "includes"
|
|
178
|
+
| "notIncludes"
|
|
179
|
+
| "in"
|
|
180
|
+
| "notIn";
|
|
181
|
+
value?: ConditionValue; // for all operators, except for "exists" and "notExists"
|
|
182
|
+
regexFlags?: string; // for regex operators only (matches, notMatches)
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
export interface FeatureCondition {
|
|
186
|
+
feature: string;
|
|
187
|
+
operator: "isEnabled" | "isDisabled";
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
export interface ExperimentCondition {
|
|
191
|
+
experiment: string;
|
|
192
|
+
operator: "hasVariation";
|
|
193
|
+
value: string;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
export type PlainCondition = AttributeCondition | FeatureCondition | ExperimentCondition;
|
|
197
|
+
|
|
198
|
+
export interface AndCondition {
|
|
199
|
+
and: Condition[];
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
export interface OrCondition {
|
|
203
|
+
or: Condition[];
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
export interface NotCondition {
|
|
207
|
+
not: Condition[];
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
export type AndOrNotCondition = AndCondition | OrCondition | NotCondition;
|
|
211
|
+
|
|
212
|
+
export type Condition = PlainCondition | AndOrNotCondition | string;
|
|
213
|
+
|
|
214
|
+
/**
|
|
215
|
+
* Segments
|
|
216
|
+
*/
|
|
217
|
+
|
|
218
|
+
export type SegmentKey = string;
|
|
219
|
+
|
|
220
|
+
export interface Segment {
|
|
221
|
+
archived?: boolean; // only available in YAML files
|
|
222
|
+
key?: SegmentKey; // needed for supporting v1 datafile generation
|
|
223
|
+
promotable?: boolean;
|
|
224
|
+
conditions: Condition | Condition[]; // string can be "*" or stringified for datafile
|
|
225
|
+
description?: string; // only available in YAML files
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
export type PlainGroupSegment = SegmentKey;
|
|
229
|
+
|
|
230
|
+
export interface AndGroupSegment {
|
|
231
|
+
and: GroupSegment[];
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
export interface OrGroupSegment {
|
|
235
|
+
or: GroupSegment[];
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
export interface NotGroupSegment {
|
|
239
|
+
not: GroupSegment[];
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
export type AndOrNotGroupSegment = AndGroupSegment | OrGroupSegment | NotGroupSegment;
|
|
243
|
+
|
|
244
|
+
// group of segment keys with and/or conditions, or just string
|
|
245
|
+
export type GroupSegment = PlainGroupSegment | AndOrNotGroupSegment;
|
|
246
|
+
|
|
247
|
+
/**
|
|
248
|
+
* Overrides
|
|
249
|
+
*/
|
|
250
|
+
export interface Override {
|
|
251
|
+
key: string;
|
|
252
|
+
description?: string;
|
|
253
|
+
summary?: string;
|
|
254
|
+
|
|
255
|
+
// one of them need to be provided
|
|
256
|
+
conditions?: Condition | Condition[] | "*"; // string can be "*" or stringified datafile condition
|
|
257
|
+
segments?: GroupSegment | GroupSegment[] | "*"; // string can be "*", segment key, or stringified datafile segment group
|
|
258
|
+
|
|
259
|
+
translations: {
|
|
260
|
+
[locale: LocaleKey]: Translation;
|
|
261
|
+
};
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
/**
|
|
265
|
+
* Messages
|
|
266
|
+
*/
|
|
267
|
+
export type MessageKey = string;
|
|
268
|
+
|
|
269
|
+
export type Translation = string;
|
|
270
|
+
export type MessageMeta = Record<string, unknown>;
|
|
271
|
+
|
|
272
|
+
export type MessageExample = ExampleBase & {
|
|
273
|
+
locale: LocaleKey;
|
|
274
|
+
};
|
|
275
|
+
|
|
276
|
+
export interface Message {
|
|
277
|
+
key?: MessageKey;
|
|
278
|
+
|
|
279
|
+
// only in YAML files
|
|
280
|
+
archived?: boolean;
|
|
281
|
+
promotable?: boolean;
|
|
282
|
+
deprecated?: boolean;
|
|
283
|
+
deprecationWarning?: string;
|
|
284
|
+
description?: string;
|
|
285
|
+
summary?: string;
|
|
286
|
+
meta?: MessageMeta;
|
|
287
|
+
examples?: MessageExample[];
|
|
288
|
+
|
|
289
|
+
// rest
|
|
290
|
+
translations: {
|
|
291
|
+
[locale: LocaleKey]: Translation;
|
|
292
|
+
};
|
|
293
|
+
overrides?: Override[];
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
/**
|
|
297
|
+
* Targets
|
|
298
|
+
*/
|
|
299
|
+
export type TargetKey = string;
|
|
300
|
+
|
|
301
|
+
export interface Target {
|
|
302
|
+
key?: TargetKey;
|
|
303
|
+
promotable?: boolean;
|
|
304
|
+
stringify?: boolean;
|
|
305
|
+
pretty?: boolean;
|
|
306
|
+
revisionFromHash?: boolean;
|
|
307
|
+
includeMessages?: string[];
|
|
308
|
+
excludeMessages?: string[];
|
|
309
|
+
locales?: LocaleKey[];
|
|
310
|
+
context?: Context;
|
|
311
|
+
formats?: { [locale: LocaleKey]: FormatPresets };
|
|
312
|
+
}
|
package/src/format.d.ts
ADDED
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ECMA-402 / ICU-related format preset types (for `Intl.*Format` and skeleton strings).
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Digit, grouping, notation, and rounding fields shared by all `Intl.NumberFormat` style variants (ECMA-402).
|
|
7
|
+
*/
|
|
8
|
+
export interface FormatNumberPresetShared {
|
|
9
|
+
useGrouping?: boolean | "min2" | "auto" | "always";
|
|
10
|
+
minimumIntegerDigits?: number;
|
|
11
|
+
minimumFractionDigits?: number;
|
|
12
|
+
maximumFractionDigits?: number;
|
|
13
|
+
minimumSignificantDigits?: number;
|
|
14
|
+
maximumSignificantDigits?: number;
|
|
15
|
+
notation?: "standard" | "scientific" | "engineering" | "compact";
|
|
16
|
+
compactDisplay?: "short" | "long";
|
|
17
|
+
signDisplay?: "auto" | "never" | "always" | "exceptZero" | "negative";
|
|
18
|
+
roundingPriority?: "auto" | "morePrecision" | "lessPrecision";
|
|
19
|
+
roundingIncrement?:
|
|
20
|
+
| 1
|
|
21
|
+
| 2
|
|
22
|
+
| 5
|
|
23
|
+
| 10
|
|
24
|
+
| 20
|
|
25
|
+
| 25
|
|
26
|
+
| 50
|
|
27
|
+
| 100
|
|
28
|
+
| 200
|
|
29
|
+
| 250
|
|
30
|
+
| 500
|
|
31
|
+
| 1000
|
|
32
|
+
| 2000
|
|
33
|
+
| 2500
|
|
34
|
+
| 5000;
|
|
35
|
+
roundingMode?:
|
|
36
|
+
| "ceil"
|
|
37
|
+
| "floor"
|
|
38
|
+
| "expand"
|
|
39
|
+
| "trunc"
|
|
40
|
+
| "halfCeil"
|
|
41
|
+
| "halfFloor"
|
|
42
|
+
| "halfExpand"
|
|
43
|
+
| "halfTrunc"
|
|
44
|
+
| "halfEven";
|
|
45
|
+
trailingZeroDisplay?: "auto" | "stripIfInteger";
|
|
46
|
+
numberingSystem?: string;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Default / plain number formatting (`style` omitted or `"decimal"`). Do not set `currency` or `unit` here — use {@link FormatNumberCurrencyPreset} or {@link FormatNumberUnitPreset}.
|
|
51
|
+
*/
|
|
52
|
+
export type FormatNumberDecimalPreset = FormatNumberPresetShared & {
|
|
53
|
+
style?: "decimal";
|
|
54
|
+
currency?: never;
|
|
55
|
+
currencyDisplay?: never;
|
|
56
|
+
currencySign?: never;
|
|
57
|
+
unit?: never;
|
|
58
|
+
unitDisplay?: never;
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Currency formatting. `currency` may be omitted when the application supplies one at runtime.
|
|
63
|
+
*/
|
|
64
|
+
export type FormatNumberCurrencyPreset = FormatNumberPresetShared & {
|
|
65
|
+
style: "currency";
|
|
66
|
+
currency?: string;
|
|
67
|
+
currencyDisplay?: "code" | "symbol" | "narrowSymbol" | "name";
|
|
68
|
+
currencySign?: "standard" | "accounting";
|
|
69
|
+
unit?: never;
|
|
70
|
+
unitDisplay?: never;
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Percent formatting (`style: "percent"`). Values are fractional (e.g. `0.12` → `"12%"` in `en-US`).
|
|
75
|
+
*/
|
|
76
|
+
export type FormatNumberPercentPreset = FormatNumberPresetShared & {
|
|
77
|
+
style: "percent";
|
|
78
|
+
currency?: never;
|
|
79
|
+
currencyDisplay?: never;
|
|
80
|
+
currencySign?: never;
|
|
81
|
+
unit?: never;
|
|
82
|
+
unitDisplay?: never;
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Unit formatting (`style: "unit"`). Requires a [sanctioned unit identifier](https://tc39.es/ecma402/#table-sanctioned-single-unit-identifiers) in `unit`.
|
|
87
|
+
*/
|
|
88
|
+
export type FormatNumberUnitPreset = FormatNumberPresetShared & {
|
|
89
|
+
style: "unit";
|
|
90
|
+
unit: string;
|
|
91
|
+
unitDisplay?: "short" | "narrow" | "long";
|
|
92
|
+
currency?: never;
|
|
93
|
+
currencyDisplay?: never;
|
|
94
|
+
currencySign?: never;
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Discriminated union on `style` so currency / unit options are valid only when applicable. Assignable to `Intl.NumberFormatOptions`.
|
|
99
|
+
*/
|
|
100
|
+
export type FormatNumberPresetOptions =
|
|
101
|
+
| FormatNumberDecimalPreset
|
|
102
|
+
| FormatNumberCurrencyPreset
|
|
103
|
+
| FormatNumberPercentPreset
|
|
104
|
+
| FormatNumberUnitPreset;
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Fields shared by both date/time preset shapes (time zone, calendar, etc.).
|
|
108
|
+
*/
|
|
109
|
+
export interface FormatDateTimePresetShared {
|
|
110
|
+
timeZone?: string;
|
|
111
|
+
calendar?: string;
|
|
112
|
+
numberingSystem?: string;
|
|
113
|
+
hour12?: boolean;
|
|
114
|
+
hourCycle?: "h11" | "h12" | "h23" | "h24";
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Use granular date/time fields (`year`, `hour`, …).
|
|
119
|
+
*/
|
|
120
|
+
export type FormatDateTimeFieldsPreset = FormatDateTimePresetShared & {
|
|
121
|
+
dateStyle?: never;
|
|
122
|
+
timeStyle?: never;
|
|
123
|
+
formatMatcher?: "basic" | "best fit";
|
|
124
|
+
weekday?: "long" | "short" | "narrow";
|
|
125
|
+
era?: "long" | "short" | "narrow";
|
|
126
|
+
year?: "numeric" | "2-digit";
|
|
127
|
+
month?: "numeric" | "2-digit" | "long" | "short" | "narrow";
|
|
128
|
+
day?: "numeric" | "2-digit";
|
|
129
|
+
dayPeriod?: "long" | "short" | "narrow";
|
|
130
|
+
hour?: "numeric" | "2-digit";
|
|
131
|
+
minute?: "numeric" | "2-digit";
|
|
132
|
+
second?: "numeric" | "2-digit";
|
|
133
|
+
fractionalSecondDigits?: 1 | 2 | 3;
|
|
134
|
+
timeZoneName?: "long" | "short" | "shortOffset" | "longOffset" | "shortGeneric" | "longGeneric";
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
export type FormatDateTimeStylePreset = FormatDateTimePresetShared & {
|
|
138
|
+
dateStyle?: "full" | "long" | "medium" | "short";
|
|
139
|
+
timeStyle?: "full" | "long" | "medium" | "short";
|
|
140
|
+
formatMatcher?: never;
|
|
141
|
+
weekday?: never;
|
|
142
|
+
era?: never;
|
|
143
|
+
year?: never;
|
|
144
|
+
month?: never;
|
|
145
|
+
day?: never;
|
|
146
|
+
dayPeriod?: never;
|
|
147
|
+
hour?: never;
|
|
148
|
+
minute?: never;
|
|
149
|
+
second?: never;
|
|
150
|
+
fractionalSecondDigits?: never;
|
|
151
|
+
timeZoneName?: never;
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* Assignable to the portable Messagevisor date/time subset and broadly compatible with `Intl.DateTimeFormatOptions`.
|
|
156
|
+
*/
|
|
157
|
+
export type FormatDateTimePresetOptions = FormatDateTimeFieldsPreset | FormatDateTimeStylePreset;
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* `Intl.RelativeTimeFormat` only exposes `numeric` and `style`; they are independent, so a single interface stays clearest.
|
|
161
|
+
* Same keys as `Intl.RelativeTimeFormatOptions` without `localeMatcher`.
|
|
162
|
+
*/
|
|
163
|
+
export interface FormatRelativeTimePresetOptions {
|
|
164
|
+
numeric?: "always" | "auto";
|
|
165
|
+
style?: "long" | "short" | "narrow";
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
export interface FormatPresets {
|
|
169
|
+
number?: Record<string, FormatNumberPresetOptions>;
|
|
170
|
+
date?: Record<string, FormatDateTimePresetOptions>;
|
|
171
|
+
time?: Record<string, FormatDateTimePresetOptions>;
|
|
172
|
+
relative?: Record<string, FormatRelativeTimePresetOptions>;
|
|
173
|
+
dateTimeRange?: Record<string, FormatDateTimePresetOptions>;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* Named ICU skeleton / compact format strings (e.g. UTS #35 date/time skeletons, compact number tokens for `::` in messages).
|
|
178
|
+
*/
|
|
179
|
+
// export interface IcuSkeletonFormats {
|
|
180
|
+
// number?: Record<string, string>;
|
|
181
|
+
// date?: Record<string, string>;
|
|
182
|
+
// time?: Record<string, string>;
|
|
183
|
+
// dateTime?: Record<string, string>;
|
|
184
|
+
// }
|
package/src/index.d.ts
ADDED
package/src/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
// empty line
|
package/src/tests.d.ts
ADDED
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
Context,
|
|
3
|
+
Matrix,
|
|
4
|
+
MessageKey,
|
|
5
|
+
SegmentKey,
|
|
6
|
+
TargetKey,
|
|
7
|
+
LocaleKey,
|
|
8
|
+
Translation,
|
|
9
|
+
} from "./entities";
|
|
10
|
+
import type { FormatPresets } from "./format";
|
|
11
|
+
|
|
12
|
+
export type ExpectedByRuntime = Record<string, string>;
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* MessageTest
|
|
16
|
+
*/
|
|
17
|
+
export interface MessageAssertion {
|
|
18
|
+
matrix?: Matrix;
|
|
19
|
+
description?: string;
|
|
20
|
+
context?: Context;
|
|
21
|
+
locale: LocaleKey;
|
|
22
|
+
target?: TargetKey;
|
|
23
|
+
values?: Record<string, unknown>;
|
|
24
|
+
withFlags?: Record<string, boolean>;
|
|
25
|
+
withVariations?: Record<string, string>;
|
|
26
|
+
currency?: string;
|
|
27
|
+
timeZone?: string;
|
|
28
|
+
formats?: FormatPresets;
|
|
29
|
+
expectedTranslation: Translation;
|
|
30
|
+
expectedByRuntime?: ExpectedByRuntime;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export interface MessageTest {
|
|
34
|
+
promotable?: boolean;
|
|
35
|
+
message: MessageKey;
|
|
36
|
+
assertions: MessageAssertion[];
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* SegmentTest
|
|
41
|
+
*/
|
|
42
|
+
export interface SegmentAssertion {
|
|
43
|
+
matrix?: Matrix;
|
|
44
|
+
description?: string;
|
|
45
|
+
segment: SegmentKey;
|
|
46
|
+
context?: Context;
|
|
47
|
+
expectedToMatch: boolean;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export interface SegmentTest {
|
|
51
|
+
promotable?: boolean;
|
|
52
|
+
segment: SegmentKey;
|
|
53
|
+
assertions: SegmentAssertion[];
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* LocaleTest
|
|
58
|
+
*/
|
|
59
|
+
export interface LocaleAssertion {
|
|
60
|
+
matrix?: Matrix;
|
|
61
|
+
description?: string;
|
|
62
|
+
target?: TargetKey;
|
|
63
|
+
expectedFormats?: FormatPresets;
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* When asserting raw message translation
|
|
67
|
+
*/
|
|
68
|
+
// optional, but need to be used together if one is used
|
|
69
|
+
rawMessage?: string;
|
|
70
|
+
expectedTranslation?: string;
|
|
71
|
+
expectedByRuntime?: ExpectedByRuntime;
|
|
72
|
+
|
|
73
|
+
// other optional params
|
|
74
|
+
values?: Record<string, unknown>;
|
|
75
|
+
context?: Record<string, unknown>;
|
|
76
|
+
formats?: FormatPresets;
|
|
77
|
+
currency?: string;
|
|
78
|
+
timeZone?: string;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export interface LocaleTest {
|
|
82
|
+
promotable?: boolean;
|
|
83
|
+
locale: LocaleKey;
|
|
84
|
+
assertions: LocaleAssertion[];
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* TargetTest
|
|
89
|
+
*/
|
|
90
|
+
export interface TargetAssertion {
|
|
91
|
+
matrix?: Matrix;
|
|
92
|
+
description?: string;
|
|
93
|
+
locale: LocaleKey;
|
|
94
|
+
expectedToIncludeMessages?: MessageKey[];
|
|
95
|
+
expectedToNotIncludeMessages?: MessageKey[];
|
|
96
|
+
expectedFormats?: FormatPresets;
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* When asserting raw message or message translation
|
|
100
|
+
*/
|
|
101
|
+
// optional, but need to be used together if one is used
|
|
102
|
+
rawMessage?: string; // either rawMessage or message must be used
|
|
103
|
+
message?: MessageKey;
|
|
104
|
+
expectedTranslation?: string; // if rawMessage or message is used, expectedTranslation must be used
|
|
105
|
+
expectedByRuntime?: ExpectedByRuntime;
|
|
106
|
+
|
|
107
|
+
// other optional params
|
|
108
|
+
values?: Record<string, unknown>;
|
|
109
|
+
context?: Record<string, unknown>;
|
|
110
|
+
formats?: FormatPresets;
|
|
111
|
+
currency?: string;
|
|
112
|
+
timeZone?: string;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
export interface TargetTest {
|
|
116
|
+
promotable?: boolean;
|
|
117
|
+
target: TargetKey;
|
|
118
|
+
assertions: TargetAssertion[];
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Combined
|
|
123
|
+
*/
|
|
124
|
+
export type Test = MessageTest | SegmentTest | LocaleTest | TargetTest;
|