Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Flow declarations #4

Merged
merged 1 commit into from
Sep 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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