add typedefinition money-math

This commit is contained in:
taoqf 2018-08-28 17:02:01 +08:00
parent 73218af4d7
commit 8e32bbb4b6
4 changed files with 63 additions and 0 deletions

21
types/money-math/index.d.ts vendored Normal file
View File

@ -0,0 +1,21 @@
// Type definitions for money-math 2.5
// Project: https://github.com/ikr/money-math#readme
// Definitions by: taoqf <https://github.com/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;

View File

@ -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"

View File

@ -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"
]
}

View File

@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }