diff --git a/package.json b/package.json index 0f6e80d..c49d842 100644 --- a/package.json +++ b/package.json @@ -4,6 +4,7 @@ "description": "Banana Internationalization library", "main": "dist/banana-i18n.js", "type": "module", + "typings": "types/index.d.ts", "scripts": { "test": " node --experimental-vm-modules node_modules/.bin/jest test/banana.test.js", "build": "webpack --mode=production" diff --git a/types/index.d.ts b/types/index.d.ts new file mode 100644 index 0000000..4597a43 --- /dev/null +++ b/types/index.d.ts @@ -0,0 +1,57 @@ +export class Banana { + constructor(locale: string, options?: BananaOptions); + locale: string; + parser: BananaParser; + messageStore: BananaMessageStore; + finalFallback: string; + + load(messsageSource: MessageSource, locale?: string): void; + i18n(key: string, ...params: ParameterType[]): string; + setLocale(locale: string): void; + getFallbackLocales(): string[]; + getMessage(messageKey: string): string; +} + +export interface BananaOptions { + messages?: Messages; + finalFallback?: string; +} + +export interface Messages { + [messageKey: string]: string; +} + +export interface MessageSource { + [localizer: string]: Messages; +} + +export type ParameterType = string | object | number | undefined; + +export class BananaParser { + constructor (locale: string, options?: { wikilinks: boolean }); + locale: string; + wikilinks: boolean; + emitter: BananaEmitter; +} + +export class BananaEmitter { + constructor(locale: string); + emit(node: any, replacements: any): any; + concat(nodes: any): string; + replace (nodes: any, replacements: any): string; + plural(nodes: any): string; + gender(nodes: any): string; + grammar(nodes: any): string; + wikilink(nodes: any): string; + extlink(nodes: any): string; + bidi(nodes: any): string; + formatnum(nodes: any): string; +} + +export class BananaMessageStore { + constructor(); + load(messageSource: Messages, locale: string): void; + getMessage(key: string, locale: string): string; + hasLocale(locale: string): boolean; +} +