Skip to content

Commit

Permalink
Merge pull request #4 from Gandi/feature/flow-declarations
Browse files Browse the repository at this point in the history
Add Flow declarations
  • Loading branch information
pascalduez authored Sep 9, 2024
2 parents 0a250db + 66849ed commit 6a3ecc0
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 0 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
### Added
- Add local Flow declarations (shipped with the package).
We don't necessarily want to contribute the fork definitions to flow-typed.

## [1.0.0] - 2024-09-06
### Changed
Expand Down
71 changes: 71 additions & 0 deletions index.js.flow
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
// @flow

export type Options = {
locale?: string,
fallbackLocale?: string,
separator?: string,
fallback?: string,
scope?: string | string[],
interpolate?: boolean,
format?: 'default' | string,
type?: 'datetime' | string,
// @TODO: check if other types than number are really allowed.
count?: number | string | null,
...
};

export type NotFoundHandler = (evt: {
...CustomEvent,
detail: { locale: string, key: string, fallback: string, scope: string },
...
}) => void;

export type LocaleChangeHandler = (evt: {
...CustomEvent,
detail: {
locale: string,
previous: string,
},
...
}) => void;

export type ErrorHandler = (evt: {
...CustomEvent,
detail: {
error: Error,
entry: string,
values: Options,
},
...
}) => void;

declare function translate(key: string | string[], options?: Options): string;

declare class Counterpart {
constructor(): this;

translate: typeof translate;
localize(date: Date, options: { ... }): string;
setSeparator(value: string): string;
setMissingEntryGenerator(callback: (value: string) => void): void;
getLocale(): string;
setLocale(value: string): string;
setFallbackLocale(value: string | string[]): void;
registerTranslations(locale: string, data: { ... }): void;
registerInterpolations(data: { ... }): void;
setKeyTransformer(
callback: (value: string, options: { ... }) => string,
): string;
onLocaleChange(callback: LocaleChangeHandler): void;
offLocaleChange(callback: LocaleChangeHandler): void;
onTranslationNotFound(callback: NotFoundHandler): void;
offTranslationNotFound(callback: NotFoundHandler): void;
onError(callback: ErrorHandler): void;
offError(callback: ErrorHandler): void;
}

declare module.exports: {
Instance: Class<Counterpart>,
Translator: Class<Counterpart>,
} & Counterpart &
typeof translate;
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
"files": [
"locales",
"index.js",
"index.js.flow",
"strftime.js",
"README.md",
"LICENSE"
Expand Down

0 comments on commit 6a3ecc0

Please sign in to comment.