monaco-yaml/src/fillers/vscode-nls.ts
Remco Haszing ac7b6fe307
Introduce ESLint
The ESLint preset `eslint-config-remcohaszing` is used.
2021-07-17 17:12:17 +02:00

35 lines
862 B
TypeScript

export interface Options {
locale?: string;
cacheLanguageResolution?: boolean;
}
export interface LocalizeInfo {
key: string;
comment: string[];
}
export type LocalizeFunc = (
info: LocalizeInfo | string,
message: string,
...args: unknown[]
) => string;
export type LoadFunc = (file?: string) => LocalizeFunc;
function format(message: string, args: string[]): string {
return args.length === 0
? message
: message.replace(/{(\d+)}/g, (match, rest) => {
const [index] = rest;
return typeof args[index] === 'undefined' ? match : args[index];
});
}
function localize(key: LocalizeInfo | string, message: string, ...args: string[]): string {
return format(message, args);
}
export function loadMessageBundle(): LocalizeFunc {
return localize;
}
export function config(): LoadFunc {
return loadMessageBundle;
}