Merge pull request #24254 from SanderDeWaal1992/excel-style-dataformatter

Add 'excel-style-dataformatter' package
This commit is contained in:
Arthur Ozga
2018-03-15 12:51:05 -07:00
committed by GitHub
6 changed files with 130 additions and 0 deletions
@@ -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");
+63
View File
@@ -0,0 +1,63 @@
// Type definitions for excel-style-dataformatter 2.0
// Project: https://github.com/fakundo/Excel-Style-Javascript-DataFormatter
// Definitions by: SanderDeWaal1992 <https://github.com/SanderDeWaal1992>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
declare class DataFormatter {
constructor(options?: DataFormatter.FormatterOptions);
/**
* 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[];
}
interface FormatResult {
value: string;
align: string;
color: string;
pattern: string;
}
}
export = DataFormatter;
@@ -0,0 +1,4 @@
import * as DataFormatter from "../../index";
declare const locale: DataFormatter.LocalesOptions;
export = locale;
+4
View File
@@ -0,0 +1,4 @@
import * as DataFormatter from "../../index";
declare const locale: DataFormatter.LocalesOptions;
export = locale;
@@ -0,0 +1,25 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"lib/locales/en-US.d.ts",
"lib/locales/ru.d.ts",
"excel-style-dataformatter-tests.ts"
]
}
@@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }