]> git.ipfire.org Git - thirdparty/Chart.js.git/commitdiff
Split adapter types to their own definition file (#8205)
authorJukka Kurkela <jukka.kurkela@gmail.com>
Sat, 19 Dec 2020 19:03:26 +0000 (21:03 +0200)
committerGitHub <noreply@github.com>
Sat, 19 Dec 2020 19:03:26 +0000 (14:03 -0500)
* Split adapter types to their own definition file
* Sort & separate

types/adapters.d.ts [new file with mode: 0644]
types/index.esm.d.ts

diff --git a/types/adapters.d.ts b/types/adapters.d.ts
new file mode 100644 (file)
index 0000000..8429fd6
--- /dev/null
@@ -0,0 +1,69 @@
+export type TimeUnit = 'millisecond' | 'second' | 'minute' | 'hour' | 'day' | 'week' | 'month' | 'quarter' | 'year';
+
+export interface DateAdapterBase {
+       /**
+        * Returns a map of time formats for the supported formatting units defined
+        * in Unit as well as 'datetime' representing a detailed date/time string.
+        * @returns {{string: string}}
+        */
+       formats(): { [key: string]: string };
+       /**
+        * Parses the given `value` and return the associated timestamp.
+        * @param {any} value - the value to parse (usually comes from the data)
+        * @param {string} [format] - the expected data format
+        */
+       parse(value: any, format?: TimeUnit): number | null;
+       /**
+        * Returns the formatted date in the specified `format` for a given `timestamp`.
+        * @param {number} timestamp - the timestamp to format
+        * @param {string} format - the date/time token
+        * @return {string}
+        */
+       format(timestamp: number, format: TimeUnit): string;
+       /**
+        * Adds the specified `amount` of `unit` to the given `timestamp`.
+        * @param {number} timestamp - the input timestamp
+        * @param {number} amount - the amount to add
+        * @param {Unit} unit - the unit as string
+        * @return {number}
+        */
+       add(timestamp: number, amount: number, unit: TimeUnit): number;
+       /**
+        * Returns the number of `unit` between the given timestamps.
+        * @param {number} a - the input timestamp (reference)
+        * @param {number} b - the timestamp to subtract
+        * @param {Unit} unit - the unit as string
+        * @return {number}
+        */
+       diff(a: number, b: number, unit: TimeUnit): number;
+       /**
+        * Returns start of `unit` for the given `timestamp`.
+        * @param {number} timestamp - the input timestamp
+        * @param {Unit|'isoWeek'} unit - the unit as string
+        * @param {number} [weekday] - the ISO day of the week with 1 being Monday
+        * and 7 being Sunday (only needed if param *unit* is `isoWeek`).
+        * @return {number}
+        */
+       startOf(timestamp: number, unit: TimeUnit | 'isoWeek', weekday?: number): number;
+       /**
+        * Returns end of `unit` for the given `timestamp`.
+        * @param {number} timestamp - the input timestamp
+        * @param {Unit|'isoWeek'} unit - the unit as string
+        * @return {number}
+        */
+       endOf(timestamp: number, unit: TimeUnit | 'isoWeek'): number;
+}
+
+export interface DateAdapter extends DateAdapterBase {
+       readonly options: any;
+}
+
+export const DateAdapter: {
+       prototype: DateAdapter;
+       new(options: any): DateAdapter;
+       override(members: Partial<DateAdapter>): void;
+};
+
+export const _adapters: {
+       _date: DateAdapter;
+};
index 17fc4c53e339f4c28f3787700f0b92db38b74e2d..56cbe4b0fc4d27c31228de3b63edcaf66b0791b1 100644 (file)
  * }
  */
 
+import { TimeUnit } from "./adapters";
 import { ChartArea, Point } from './geometric';
+
+export { DateAdapterBase, DateAdapter, TimeUnit, _adapters } from './adapters';
 export { ChartArea, Point } from './geometric';
 
 export interface ParsingOptions {
@@ -346,73 +349,6 @@ export const RadarController: ChartComponent & {
   prototype: RadarController;
   new (chart: Chart, datasetIndex: number): RadarController;
 };
-export interface DateAdapterBase {
-       /**
-        * Returns a map of time formats for the supported formatting units defined
-        * in Unit as well as 'datetime' representing a detailed date/time string.
-        * @returns {{string: string}}
-        */
-       formats(): { [key: string]: string };
-       /**
-        * Parses the given `value` and return the associated timestamp.
-        * @param {any} value - the value to parse (usually comes from the data)
-        * @param {string} [format] - the expected data format
-        */
-       parse(value: any, format?: TimeUnit): number | null;
-       /**
-        * Returns the formatted date in the specified `format` for a given `timestamp`.
-        * @param {number} timestamp - the timestamp to format
-        * @param {string} format - the date/time token
-        * @return {string}
-        */
-       format(timestamp: number, format: TimeUnit): string;
-       /**
-        * Adds the specified `amount` of `unit` to the given `timestamp`.
-        * @param {number} timestamp - the input timestamp
-        * @param {number} amount - the amount to add
-        * @param {Unit} unit - the unit as string
-        * @return {number}
-        */
-       add(timestamp: number, amount: number, unit: TimeUnit): number;
-       /**
-        * Returns the number of `unit` between the given timestamps.
-        * @param {number} a - the input timestamp (reference)
-        * @param {number} b - the timestamp to subtract
-        * @param {Unit} unit - the unit as string
-        * @return {number}
-        */
-       diff(a: number, b: number, unit: TimeUnit): number;
-       /**
-        * Returns start of `unit` for the given `timestamp`.
-        * @param {number} timestamp - the input timestamp
-        * @param {Unit|'isoWeek'} unit - the unit as string
-        * @param {number} [weekday] - the ISO day of the week with 1 being Monday
-        * and 7 being Sunday (only needed if param *unit* is `isoWeek`).
-        * @return {number}
-        */
-       startOf(timestamp: number, unit: TimeUnit | 'isoWeek', weekday?: number): number;
-       /**
-        * Returns end of `unit` for the given `timestamp`.
-        * @param {number} timestamp - the input timestamp
-        * @param {Unit|'isoWeek'} unit - the unit as string
-        * @return {number}
-        */
-       endOf(timestamp: number, unit: TimeUnit | 'isoWeek'): number;
-}
-
-export interface DateAdapter extends DateAdapterBase {
-       readonly options: any;
-}
-
-export const DateAdapter: {
-       prototype: DateAdapter;
-       new(options: any): DateAdapter;
-       override(members: Partial<DateAdapter>): void;
-};
-
-export const _adapters: {
-       _date: DateAdapter;
-};
 
 export class Animation {
        constructor(cfg: any, target: any, prop: string, to?: any);
@@ -1466,7 +1402,6 @@ export interface ChartComponent {
   afterUnregister?(): void;
 }
 
-export type TimeUnit = 'millisecond' | 'second' | 'minute' | 'hour' | 'day' | 'week' | 'month' | 'quarter' | 'year';
 
 export interface ScriptableContext {
   chart: Chart;
@@ -3186,7 +3121,7 @@ export const RadialLinearScale: ChartComponent & {
   prototype: RadialLinearScale;
   new <O extends RadialLinearScaleOptions = RadialLinearScaleOptions>(cfg: any): RadialLinearScale<O>;
 };
-  
+
 // DeepPartial implementation taken from the utility-types NPM package, which is
 // Copyright (c) 2016 Piotr Witek <piotrek.witek@gmail.com> (http://piotrwitek.github.io)
 // and used under the terms of the MIT license
@@ -3201,7 +3136,7 @@ export type DeepPartial<T> = T extends Function
   type _DeepPartialObject<T> = { [P in keyof T]?: DeepPartial<T[P]> };
 
 export type DistributiveArray<T> = T extends unknown ? T[] : never
-  
+
 export interface CartesianScaleTypeRegistry {
   linear: {
     options: LinearScaleOptions;
@@ -3343,4 +3278,3 @@ export interface ChartConfiguration<
   options?: ChartOptions<TType>;
   plugins?: Plugin[];
 }
-  
\ No newline at end of file