mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-10-07 08:17:05 +00:00
Merge pull request #30637 from BendingBender/dinero.js
types for dinero.js
This commit is contained in:
@@ -0,0 +1,71 @@
|
||||
import Dinero = require("dinero.js");
|
||||
|
||||
Dinero.globalExchangeRatesApi = {
|
||||
endpoint: "https://yourexchangerates.api/latest?base={{from}}",
|
||||
propertyPath: "data.rates.{{to}}",
|
||||
headers: {
|
||||
"user-key": "xxxxxxxxx",
|
||||
},
|
||||
};
|
||||
Dinero.globalExchangeRatesApi = {
|
||||
endpoint: "https://yourexchangerates.api/latest?base={{from}}",
|
||||
propertyPath: "data.rates.{{to}}",
|
||||
roundingMode: "HALF_UP",
|
||||
};
|
||||
|
||||
Dinero();
|
||||
Dinero({ amount: 1 });
|
||||
Dinero({ currency: "USD" });
|
||||
Dinero({ precision: 2 });
|
||||
|
||||
let number: number;
|
||||
let string: string;
|
||||
let boolean: boolean;
|
||||
|
||||
let dinero: Dinero.Dinero = Dinero();
|
||||
let dineroArr: Dinero.Dinero[];
|
||||
let dineroObject: Dinero.DineroObject;
|
||||
|
||||
number = dinero.getAmount();
|
||||
string = dinero.getCurrency();
|
||||
string = dinero.setLocale("fr-FR").getLocale();
|
||||
number = dinero.convertPrecision(4).getPrecision();
|
||||
dinero = dinero.add(Dinero({ amount: 104545, precision: 4 }));
|
||||
dinero = dinero.subtract(Dinero({ amount: 104545, precision: 4 }));
|
||||
dinero = dinero.multiply(2.00125);
|
||||
dinero = dinero.multiply(2.00125, "HALF_UP");
|
||||
dinero = dinero.divide(2);
|
||||
dinero = dinero.divide(2, "HALF_UP");
|
||||
dinero = dinero.percentage(50);
|
||||
dineroArr = dinero.allocate([50, 50]);
|
||||
dinero.convert("EUR").then(d => (dinero = d));
|
||||
dinero.convert("XBT", {
|
||||
endpoint: "https://yourexchangerates.api/latest?base={{from}}",
|
||||
propertyPath: "data.rates.{{to}}",
|
||||
headers: {
|
||||
"user-key": "xxxxxxxxx",
|
||||
},
|
||||
roundingMode: "HALF_UP",
|
||||
});
|
||||
boolean = dinero.equalsTo(Dinero({ amount: 500, currency: "EUR" }));
|
||||
boolean = dinero.lessThan(Dinero({ amount: 800 }));
|
||||
boolean = dinero.lessThanOrEqual(Dinero({ amount: 800 }));
|
||||
boolean = dinero.greaterThan(Dinero({ amount: 800 }));
|
||||
boolean = dinero.greaterThanOrEqual(Dinero({ amount: 800 }));
|
||||
boolean = dinero.isZero();
|
||||
boolean = dinero.isPositive();
|
||||
boolean = dinero.isNegative();
|
||||
boolean = dinero.hasSubUnits();
|
||||
boolean = dinero.hasCents();
|
||||
boolean = dinero.hasSameCurrency(Dinero({ amount: 1000, currency: "EUR" }));
|
||||
boolean = dinero.hasSameAmount(Dinero({ amount: 1000, currency: "EUR" }));
|
||||
string = dinero.toFormat("0,0 dollar");
|
||||
string = dinero.toFormat("0,0 dollar", "HALF_EVEN");
|
||||
number = dinero.toUnit();
|
||||
number = dinero.toRoundedUnit(1);
|
||||
number = dinero.toRoundedUnit(1, "HALF_EVEN");
|
||||
dineroObject = dinero.toObject();
|
||||
dineroArr = Dinero.normalizePrecision([
|
||||
Dinero({ amount: 100, precision: 2 }),
|
||||
Dinero({ amount: 1000, precision: 3 }),
|
||||
]);
|
||||
Vendored
+78
@@ -0,0 +1,78 @@
|
||||
// Type definitions for dinero.js 1.4
|
||||
// Project: https://sarahdayan.github.io/dinero.js
|
||||
// Definitions by: BendingBender <https://github.com/BendingBender>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.1
|
||||
|
||||
export as namespace Dinero;
|
||||
|
||||
export = DineroFactory;
|
||||
|
||||
declare function DineroFactory(options?: Dinero.Options): DineroFactory.Dinero;
|
||||
|
||||
declare namespace DineroFactory {
|
||||
let globalExchangeRatesApi: ExchangeRatesApiOptions;
|
||||
function normalizePrecision(objects: Dinero[]): Dinero[];
|
||||
|
||||
interface Options {
|
||||
amount?: number;
|
||||
currency?: string;
|
||||
precision?: number;
|
||||
}
|
||||
|
||||
interface Dinero {
|
||||
getAmount(): number;
|
||||
getCurrency(): string;
|
||||
getLocale(): string;
|
||||
setLocale(newLocale: string): Dinero;
|
||||
getPrecision(): number;
|
||||
convertPrecision(newPrecision: number): Dinero;
|
||||
add(addend: Dinero): Dinero;
|
||||
subtract(subtrahend: Dinero): Dinero;
|
||||
multiply(multiplier: number, roundingMode?: RoundingMode): Dinero;
|
||||
divide(divisor: number, roundingMode?: RoundingMode): Dinero;
|
||||
percentage(percentage: number): Dinero;
|
||||
allocate(ratios: number[]): Dinero[];
|
||||
convert(currency: string, options?: ExchangeRatesApiOptions): Promise<Dinero>;
|
||||
equalsTo(comparator: Dinero): boolean;
|
||||
lessThan(comparator: Dinero): boolean;
|
||||
lessThanOrEqual(comparator: Dinero): boolean;
|
||||
greaterThan(comparator: Dinero): boolean;
|
||||
greaterThanOrEqual(comparator: Dinero): boolean;
|
||||
isZero(): boolean;
|
||||
isPositive(): boolean;
|
||||
isNegative(): boolean;
|
||||
hasSubUnits(): boolean;
|
||||
/**
|
||||
* @deprecated since version 2.0
|
||||
*/
|
||||
hasCents(): boolean;
|
||||
hasSameCurrency(comparator: Dinero): boolean;
|
||||
hasSameAmount(comparator: Dinero): boolean;
|
||||
toFormat(format?: string, roundingMode?: RoundingMode): string;
|
||||
toUnit(): number;
|
||||
toRoundedUnit(digits: number, roundingMode?: RoundingMode): number;
|
||||
toObject(): DineroObject;
|
||||
}
|
||||
|
||||
type RoundingMode =
|
||||
| "HALF_ODD"
|
||||
| "HALF_EVEN"
|
||||
| "HALF_UP"
|
||||
| "HALF_DOWN"
|
||||
| "HALF_TOWARDS_ZERO"
|
||||
| "HALF_AWAY_FROM_ZERO";
|
||||
|
||||
interface ExchangeRatesApiOptions {
|
||||
endpoint: string;
|
||||
propertyPath: string;
|
||||
headers?: { [header: string]: string };
|
||||
roundingMode?: RoundingMode;
|
||||
}
|
||||
|
||||
interface DineroObject {
|
||||
amount: number;
|
||||
currency: string;
|
||||
precision: number;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": [
|
||||
"es6"
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": true,
|
||||
"strictFunctionTypes": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"dinero.js-tests.ts"
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
Reference in New Issue
Block a user