From 8e32bbb4b6dcae495caf723a87f18b0bd1a9ddca Mon Sep 17 00:00:00 2001 From: taoqf Date: Tue, 28 Aug 2018 17:02:01 +0800 Subject: [PATCH] add typedefinition money-math --- types/money-math/index.d.ts | 21 +++++++++++++++++++++ types/money-math/money-math-tests.ts | 18 ++++++++++++++++++ types/money-math/tsconfig.json | 23 +++++++++++++++++++++++ types/money-math/tslint.json | 1 + 4 files changed, 63 insertions(+) create mode 100644 types/money-math/index.d.ts create mode 100644 types/money-math/money-math-tests.ts create mode 100644 types/money-math/tsconfig.json create mode 100644 types/money-math/tslint.json diff --git a/types/money-math/index.d.ts b/types/money-math/index.d.ts new file mode 100644 index 0000000000..95b5f846d7 --- /dev/null +++ b/types/money-math/index.d.ts @@ -0,0 +1,21 @@ +// Type definitions for money-math 2.5 +// Project: https://github.com/ikr/money-math#readme +// Definitions by: taoqf +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +export as namespace Money; + +export function add(a: string, b: string): string; +export function subtract(a: string, b: string): string; +export function mul(a: string, b: string): string; +export function div(a: string, b: string): string; +export function percent(a: string, b: string): string; +export function cmp(a: string, b: string): 0 | 1 | -1; +export function isEqual(a: string, b: string): boolean; +export function isZero(value: string): boolean; +export function isNegative(value: string): boolean; +export function isPositive(value: string): boolean; +export function floatToAmount(value: number): string; +export function format(currency: 'CHF' | 'CNY' | 'EUR' | 'GBP' | 'JPY' | 'LTL' | 'PLN' | 'SEK' | 'SKK' | 'UAH' | 'USD' | string, value: string): string; +export function roundUpTo5Cents(value: string): string; +export function roundTo5Cents(value: string): string; diff --git a/types/money-math/money-math-tests.ts b/types/money-math/money-math-tests.ts new file mode 100644 index 0000000000..9b93824ca1 --- /dev/null +++ b/types/money-math/money-math-tests.ts @@ -0,0 +1,18 @@ +import * as money from 'money-math'; + +money.add("16.11", "17.07"); // "33.18" +money.subtract("16.00", "7.00"); // "9.00" +money.mul("24.00", "0.25"); // "6.00" +money.div("64.00", "2.00"); // "32.00" +money.percent("200.00", "3.25"); // "6.50" +money.cmp("100.00", "200.00"); // -1 +money.isEqual("100.00", "100.00"); // true +money.isZero("0.00"); // true +money.isNegative("-1.00"); // true +money.isPositive("-1.00"); // false + +money.format("JPY", "236800.00"); // "236,800" +money.floatToAmount(56.345); // "56.35" + +money.roundUpTo5Cents("42.02"); // "42.05" +money.roundTo5Cents("442.26"); // "442.25" diff --git a/types/money-math/tsconfig.json b/types/money-math/tsconfig.json new file mode 100644 index 0000000000..fd8b7d167d --- /dev/null +++ b/types/money-math/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "strictFunctionTypes": true, + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "money-math-tests.ts" + ] +} \ No newline at end of file diff --git a/types/money-math/tslint.json b/types/money-math/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/money-math/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }