Skip to content

Commit

Permalink
Simplify format() signature with MsgPath
Browse files Browse the repository at this point in the history
  • Loading branch information
eemeli committed Feb 4, 2022
1 parent 4d508ba commit fb5d3ec
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,16 +69,22 @@ The interfaces for
will depend on the final MF2 data model.
`MessageFormatOptions` contains configuration options
for the creation of `MessageFormat` instances.
The `Scope` object is used to lookup variable references used in the `Message`.
The `ResolvedOptions` object contains the options
resolved during the construction of the `MessageFormat` instance.

The `msgPath` argument identifies the message from those available in the current resources.
If all added resources share the same `id` value,
the path may be given as a string or a string array.
The `scope` argument is used to lookup variable references used in the `Message`.

```ts
interface MessageFormatOptions {
localeMatcher?: 'best fit' | 'lookup';
...
}

type MsgPath = string | string[] | { resId: string, path: string[] }

type Scope = Record<string, unknown>

interface Intl.MessageFormat {
Expand All @@ -90,14 +96,9 @@ interface Intl.MessageFormat {

addResources(...resources: Resource[]);

format(msgPath: string | string[], scope?: Scope): string;
format(resId: string, msgPath: string | string[], scope?: Scope): string;
format(msgPath: MsgPath, scope?: Scope): string;

formatToParts(
resId: string,
msgPath: string | string[],
scope?: Scope
): MessageFormatPart[];
formatToParts(msgPath: MsgPath, scope?: Scope): MessageFormatPart[];

resolvedOptions(): ResolvedOptions;
}
Expand Down

0 comments on commit fb5d3ec

Please sign in to comment.