diff --git a/types/javascript-time-ago/OTHER_FILES.txt b/types/javascript-time-ago/OTHER_FILES.txt index 5986a14d5e..5298783a92 100644 --- a/types/javascript-time-ago/OTHER_FILES.txt +++ b/types/javascript-time-ago/OTHER_FILES.txt @@ -128,4 +128,4 @@ locale/gu/index.d.ts locale/ms/index.d.ts locale/ro/index.d.ts locale/ka/index.d.ts -locale/ti/index.d.ts +locale/ti/index.d.ts \ No newline at end of file diff --git a/types/javascript-time-ago/gradation/canonical.d.ts b/types/javascript-time-ago/gradation/canonical.d.ts new file mode 100644 index 0000000000..a5f70b7e07 --- /dev/null +++ b/types/javascript-time-ago/gradation/canonical.d.ts @@ -0,0 +1,5 @@ +import { Gradation } from './'; + +declare const canonical: Gradation[]; + +export default canonical; diff --git a/types/javascript-time-ago/gradation/convenient.d.ts b/types/javascript-time-ago/gradation/convenient.d.ts new file mode 100644 index 0000000000..64d39c1467 --- /dev/null +++ b/types/javascript-time-ago/gradation/convenient.d.ts @@ -0,0 +1,5 @@ +import { Gradation } from './'; + +declare const convenient: Gradation[]; + +export default convenient; diff --git a/types/javascript-time-ago/gradation/helpers.d.ts b/types/javascript-time-ago/gradation/helpers.d.ts new file mode 100644 index 0000000000..618a002f99 --- /dev/null +++ b/types/javascript-time-ago/gradation/helpers.d.ts @@ -0,0 +1,9 @@ +import { Gradation, Unit } from '.'; + +export const minute: number; +export const hour: number; +export const day: number; +export const month: number; +export const year: number; +export function getStep(gradation: Gradation[], unit: Unit): Gradation | undefined; +export function getDate(value: Date | number): Date; diff --git a/types/javascript-time-ago/gradation/index.d.ts b/types/javascript-time-ago/gradation/index.d.ts new file mode 100644 index 0000000000..36c51b01df --- /dev/null +++ b/types/javascript-time-ago/gradation/index.d.ts @@ -0,0 +1,20 @@ +export type Unit = 'now' | 'second' | 'minute' | 'hour' | 'day' | 'week' | 'month' | 'year'; + +export interface Gradation { + unit?: Unit; + factor?: number; + granularity?: number; + threshold?: number; + threshold_for_now?: number; + threshold_for_second?: number; + threshold_for_minute?: number; + threshold_for_hour?: number; + threshold_for_day?: number; + threshold_for_week?: number; + threshold_for_month?: number; + threshold_for_year?: number; +} + +export { default as canonical } from './canonical'; +export { default as convenient } from './convenient'; +export { minute, hour, day, month, year, getStep, getDate } from './helpers'; diff --git a/types/javascript-time-ago/index.d.ts b/types/javascript-time-ago/index.d.ts index 0621d00899..add98f9ca9 100644 --- a/types/javascript-time-ago/index.d.ts +++ b/types/javascript-time-ago/index.d.ts @@ -2,16 +2,24 @@ // Project: https://github.com/catamphetamine/javascript-time-ago // Definitions by: Erik Burton // Henry Nguyen +// Luis Felipe Zaguini // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped - -import { Locale, TimeUnit, Duration, DefaultFormats, RTFFormatter, Formats, QuantifyType } from "./locale"; +import { + DefaultFormats, + Duration, + Formats, + Locale, + RTFFormatter, + TimeUnit +} from './locale'; +import { FormatStyle } from './style'; export = TimeAgo; declare class TimeAgo { constructor(locales?: string | string[]); - format(input: Date | number, style?: string): string; + format(input: Date | number, style?: string | FormatStyle): string; formatNumber(number: number): string; formatValue(value: Date | number, unit: TimeUnit, localeData: Duration): string; getFormatter(flavor: DefaultFormats): RTFFormatter; diff --git a/types/javascript-time-ago/style/default.d.ts b/types/javascript-time-ago/style/default.d.ts new file mode 100644 index 0000000000..5ae9d2802f --- /dev/null +++ b/types/javascript-time-ago/style/default.d.ts @@ -0,0 +1,3 @@ +import { FormatStyle } from './index'; + +export default FormatStyle; diff --git a/types/javascript-time-ago/style/index.d.ts b/types/javascript-time-ago/style/index.d.ts new file mode 100644 index 0000000000..4dc0423aae --- /dev/null +++ b/types/javascript-time-ago/style/index.d.ts @@ -0,0 +1,26 @@ +import { Gradation, Unit } from '../gradation'; +import { Locale } from '../locale'; + +export type Flavour = 'tiny' | 'short-time' | 'narrow' | 'short' | 'long'; + +export interface CustomFormatterOptions { + now: number; + date?: Date; + time: number; + elapsed: number; + locale: Locale; +} + +export type CustomFormatter = (options: CustomFormatterOptions) => string | undefined; + +export interface FormatStyle { + units?: Unit; + gradation?: Gradation[]; + flavour?: Flavour[]; + custom?: CustomFormatter; + format?(date: Date | number, locale: Locale): string; +} + +export { default as timeStyle } from './time'; +export { default as twitterStyle } from './twitter'; +export { default as defaultStyle } from './default'; diff --git a/types/javascript-time-ago/style/time.d.ts b/types/javascript-time-ago/style/time.d.ts new file mode 100644 index 0000000000..5ae9d2802f --- /dev/null +++ b/types/javascript-time-ago/style/time.d.ts @@ -0,0 +1,3 @@ +import { FormatStyle } from './index'; + +export default FormatStyle; diff --git a/types/javascript-time-ago/style/twitter.d.ts b/types/javascript-time-ago/style/twitter.d.ts new file mode 100644 index 0000000000..5ae9d2802f --- /dev/null +++ b/types/javascript-time-ago/style/twitter.d.ts @@ -0,0 +1,3 @@ +import { FormatStyle } from './index'; + +export default FormatStyle;