Skip to content

Commit

Permalink
Add TypeScript definitions
Browse files Browse the repository at this point in the history
Partially copied from wikimedia/banana-i18n#25
  • Loading branch information
siddharthvp committed Jan 14, 2021
1 parent b61d9a7 commit 7e94fed
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 0 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
57 changes: 57 additions & 0 deletions types/index.d.ts
Original file line number Diff line number Diff line change
@@ -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;
}

0 comments on commit 7e94fed

Please sign in to comment.