From 858b86eb70b56f8bb1d20fe6ce320383d81161ce Mon Sep 17 00:00:00 2001 From: Sander de Waal Date: Tue, 13 Mar 2018 10:20:53 +0100 Subject: [PATCH 1/2] excel-style-dataformatter --- .../excel-style-dataformatter-tests.ts | 33 ++++++++ types/excel-style-dataformatter/index.d.ts | 77 +++++++++++++++++++ types/excel-style-dataformatter/tsconfig.json | 22 ++++++ types/excel-style-dataformatter/tslint.json | 1 + 4 files changed, 133 insertions(+) create mode 100644 types/excel-style-dataformatter/excel-style-dataformatter-tests.ts create mode 100644 types/excel-style-dataformatter/index.d.ts create mode 100644 types/excel-style-dataformatter/tsconfig.json create mode 100644 types/excel-style-dataformatter/tslint.json diff --git a/types/excel-style-dataformatter/excel-style-dataformatter-tests.ts b/types/excel-style-dataformatter/excel-style-dataformatter-tests.ts new file mode 100644 index 0000000000..828771242e --- /dev/null +++ b/types/excel-style-dataformatter/excel-style-dataformatter-tests.ts @@ -0,0 +1,33 @@ +import * as DataFormatter from "excel-style-dataformatter"; +import * as enLocales from "excel-style-dataformatter/lib/locales/en-US"; +import * as ruLocales from "excel-style-dataformatter/lib/locales/ru"; + +const localesOptions: DataFormatter.LocalesOptions = { + name: "test", + months: ['january', 'february', 'march', 'april', 'may', 'june', 'july', 'august', 'september', 'october', 'november', 'december'], + monthsShort: ['jan', 'feb', 'mar', 'apr', 'may', 'jun', 'jul', 'aug', 'sep', 'oct', 'nov', 'dec'], + days: ['sunday', 'monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday'], + daysShort: ['su', 'mo', 'tu', 'we', 'th', 'fr', 'sa'], + thousandSeparator: ',', + decimalSeparator: '.', + formats: { + 'Test format 1': '#.#', + 'Test format 2': '$ #,##0.00;[Red]$ -#,##0.00', + } +}; +const formatterOptions: DataFormatter.FormatterOptions = { + debug: true, + UTCOffset: 100, + locale: "test", + transformCode: (code: string): string => { + return code + "string"; + }, + locales: [localesOptions, ruLocales] +}; +const dataFormatter1 = new DataFormatter(formatterOptions); +const dataFormatter2 = new DataFormatter(); +dataFormatter2.defineLocales([enLocales, ruLocales]); +dataFormatter2.setLocale("ru"); +dataFormatter2.setUTCOffset(null); +dataFormatter2.setUTCOffset(100); +const result: DataFormatter.FormatResult = dataFormatter2.format("testValue", "testType", "testFormat"); diff --git a/types/excel-style-dataformatter/index.d.ts b/types/excel-style-dataformatter/index.d.ts new file mode 100644 index 0000000000..277d3b549f --- /dev/null +++ b/types/excel-style-dataformatter/index.d.ts @@ -0,0 +1,77 @@ +// Type definitions for excel-style-dataformatter v2.0.1 +// Project: https://github.com/fakundo/Excel-Style-Javascript-DataFormatter +// Definitions by: SanderDeWaal1992 +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +declare module "excel-style-dataformatter" { + class DataFormatter { + constructor(options?: DataFormatter.FormatterOptions); + + /** + * Format a value + * @param value + * @param type value type + * @param format format preset + */ + public format(value: any, type: string, format: string): DataFormatter.FormatResult; + /** + * Defines locales + * @param locales + */ + public defineLocales(locales: DataFormatter.LocalesOptions[]): void; + /** + * Sets locale + * If locale doesn't exist, sets default + * @param locale + */ + public setLocale(locale: string): void; + /** + * Sets UTC offset for dates + * @param offset in minutes + */ + public setUTCOffset(offset: number | null): void; + } + + namespace DataFormatter { + export interface LocalesOptions { + name: string, + months: string[], + monthsShort: string[], + days: string[], + daysShort: string[], + thousandSeparator: string, + decimalSeparator: string, + formats: { + [index: string]: string + } + } + export interface FormatterOptions { + debug?: boolean, + UTCOffset?: number | null, + locale?: string, + transformCode?: (code: any) => any, + locales?: LocalesOptions[] + } + + export interface FormatResult { + value: string, + align: string, + color: string, + pattern: string + } + } + + export = DataFormatter; +} + +declare module "excel-style-dataformatter/lib/locales/en-US" { + import * as DataFormatter from "excel-style-dataformatter"; + const locale: DataFormatter.LocalesOptions; + export = locale; +} + +declare module "excel-style-dataformatter/lib/locales/ru" { + import * as DataFormatter from "excel-style-dataformatter"; + const locale: DataFormatter.LocalesOptions; + export = locale; +} diff --git a/types/excel-style-dataformatter/tsconfig.json b/types/excel-style-dataformatter/tsconfig.json new file mode 100644 index 0000000000..ddb0837830 --- /dev/null +++ b/types/excel-style-dataformatter/tsconfig.json @@ -0,0 +1,22 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "excel-style-dataformatter-tests.ts" + ] +} diff --git a/types/excel-style-dataformatter/tslint.json b/types/excel-style-dataformatter/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/excel-style-dataformatter/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" } From e1f45b78869a73caa99cc1bc89f72b048511bc2a Mon Sep 17 00:00:00 2001 From: Sander de Waal Date: Tue, 13 Mar 2018 10:54:09 +0100 Subject: [PATCH 2/2] Fix problems for npm test --- types/excel-style-dataformatter/index.d.ts | 120 ++++++++---------- .../lib/locales/en-US.d.ts | 4 + .../lib/locales/ru.d.ts | 4 + types/excel-style-dataformatter/tsconfig.json | 3 + 4 files changed, 64 insertions(+), 67 deletions(-) create mode 100644 types/excel-style-dataformatter/lib/locales/en-US.d.ts create mode 100644 types/excel-style-dataformatter/lib/locales/ru.d.ts diff --git a/types/excel-style-dataformatter/index.d.ts b/types/excel-style-dataformatter/index.d.ts index 277d3b549f..7f76ee6987 100644 --- a/types/excel-style-dataformatter/index.d.ts +++ b/types/excel-style-dataformatter/index.d.ts @@ -1,77 +1,63 @@ -// Type definitions for excel-style-dataformatter v2.0.1 +// Type definitions for excel-style-dataformatter 2.0 // Project: https://github.com/fakundo/Excel-Style-Javascript-DataFormatter // Definitions by: SanderDeWaal1992 // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -declare module "excel-style-dataformatter" { - class DataFormatter { - constructor(options?: DataFormatter.FormatterOptions); +declare class DataFormatter { + constructor(options?: DataFormatter.FormatterOptions); - /** - * Format a value - * @param value - * @param type value type - * @param format format preset - */ - public format(value: any, type: string, format: string): DataFormatter.FormatResult; - /** - * Defines locales - * @param locales - */ - public defineLocales(locales: DataFormatter.LocalesOptions[]): void; - /** - * Sets locale - * If locale doesn't exist, sets default - * @param locale - */ - public setLocale(locale: string): void; - /** - * Sets UTC offset for dates - * @param offset in minutes - */ - public setUTCOffset(offset: number | null): void; + /** + * Format a value + * @param value + * @param type value type + * @param format format preset + */ + format(value: any, type: string, format: string): DataFormatter.FormatResult; + /** + * Defines locales + * @param locales + */ + defineLocales(locales: DataFormatter.LocalesOptions[]): void; + /** + * Sets locale + * If locale doesn't exist, sets default + * @param locale + */ + setLocale(locale: string): void; + /** + * Sets UTC offset for dates + * @param offset in minutes + */ + setUTCOffset(offset: number | null): void; +} + +declare namespace DataFormatter { + interface LocalesOptions { + name: string; + months: string[]; + monthsShort: string[]; + days: string[]; + daysShort: string[]; + thousandSeparator: string; + decimalSeparator: string; + formats: { + [index: string]: string + }; + } + interface FormatterOptions { + debug?: boolean; + UTCOffset?: number | null; + locale?: string; + transformCode?: (code: any) => any; + locales?: LocalesOptions[]; } - namespace DataFormatter { - export interface LocalesOptions { - name: string, - months: string[], - monthsShort: string[], - days: string[], - daysShort: string[], - thousandSeparator: string, - decimalSeparator: string, - formats: { - [index: string]: string - } - } - export interface FormatterOptions { - debug?: boolean, - UTCOffset?: number | null, - locale?: string, - transformCode?: (code: any) => any, - locales?: LocalesOptions[] - } - - export interface FormatResult { - value: string, - align: string, - color: string, - pattern: string - } + interface FormatResult { + value: string; + align: string; + color: string; + pattern: string; } - - export = DataFormatter; } -declare module "excel-style-dataformatter/lib/locales/en-US" { - import * as DataFormatter from "excel-style-dataformatter"; - const locale: DataFormatter.LocalesOptions; - export = locale; -} - -declare module "excel-style-dataformatter/lib/locales/ru" { - import * as DataFormatter from "excel-style-dataformatter"; - const locale: DataFormatter.LocalesOptions; - export = locale; -} +export = DataFormatter; diff --git a/types/excel-style-dataformatter/lib/locales/en-US.d.ts b/types/excel-style-dataformatter/lib/locales/en-US.d.ts new file mode 100644 index 0000000000..591678aea8 --- /dev/null +++ b/types/excel-style-dataformatter/lib/locales/en-US.d.ts @@ -0,0 +1,4 @@ +import * as DataFormatter from "../../index"; + +declare const locale: DataFormatter.LocalesOptions; +export = locale; diff --git a/types/excel-style-dataformatter/lib/locales/ru.d.ts b/types/excel-style-dataformatter/lib/locales/ru.d.ts new file mode 100644 index 0000000000..591678aea8 --- /dev/null +++ b/types/excel-style-dataformatter/lib/locales/ru.d.ts @@ -0,0 +1,4 @@ +import * as DataFormatter from "../../index"; + +declare const locale: DataFormatter.LocalesOptions; +export = locale; diff --git a/types/excel-style-dataformatter/tsconfig.json b/types/excel-style-dataformatter/tsconfig.json index ddb0837830..563681d3ac 100644 --- a/types/excel-style-dataformatter/tsconfig.json +++ b/types/excel-style-dataformatter/tsconfig.json @@ -7,6 +7,7 @@ "noImplicitAny": true, "noImplicitThis": true, "strictNullChecks": true, + "strictFunctionTypes": true, "baseUrl": "../", "typeRoots": [ "../" @@ -17,6 +18,8 @@ }, "files": [ "index.d.ts", + "lib/locales/en-US.d.ts", + "lib/locales/ru.d.ts", "excel-style-dataformatter-tests.ts" ] }