mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-08-12 21:10:23 +00:00
Add type definitions for features added between Dinero.js v1.4 and v1.6. (#38856)
* Accept promises in ExchangeRatesApiOptions' endpoint property. * Accept promises in ExchangeRatesApiOptions' endpoint property. https://github.com/sarahdayan/dinero.js/releases/tag/v1.6.0 * Update dinero.js version. * Add toJson() alias to Dinero. https://github.com/sarahdayan/dinero.js/releases/tag/v1.5.0 * Correct code formatting. * Assert that promises can be used in Dinero globalExchangeRatesApi. * Assert that the Dinero toJson() alias returns a Dinero object.
This commit is contained in:
committed by
Andrew Branch
parent
5d1074409c
commit
ba3797e984
@@ -10,22 +10,35 @@ Dinero.globalFormat = '0,0 dollar';
|
||||
Dinero.globalRoundingMode = 'HALF_UP';
|
||||
Dinero.globalFormatRoundingMode = '0,0 dollar';
|
||||
Dinero.globalExchangeRatesApi = {
|
||||
endpoint: 'https://yourexchangerates.api/latest?base={{from}}',
|
||||
propertyPath: 'data.rates.{{to}}',
|
||||
headers: {
|
||||
'user-key': 'xxxxxxxxx',
|
||||
},
|
||||
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',
|
||||
endpoint: 'https://yourexchangerates.api/latest?base={{from}}',
|
||||
propertyPath: 'data.rates.{{to}}',
|
||||
roundingMode: 'HALF_UP',
|
||||
};
|
||||
Dinero.globalExchangeRatesApi = {
|
||||
endpoint: new Promise((resolve) =>
|
||||
resolve({
|
||||
data: {
|
||||
rates: {
|
||||
USD: 1.337,
|
||||
},
|
||||
},
|
||||
}),
|
||||
),
|
||||
propertyPath: 'data.rates.{{to}}',
|
||||
roundingMode: 'HALF_UP',
|
||||
};
|
||||
|
||||
Dinero();
|
||||
Dinero({ amount: 1 });
|
||||
Dinero({ currency: 'USD' });
|
||||
Dinero({ precision: 2 });
|
||||
Dinero({amount: 1});
|
||||
Dinero({currency: 'USD'});
|
||||
Dinero({precision: 2});
|
||||
|
||||
let number: number;
|
||||
let string: string;
|
||||
@@ -40,8 +53,8 @@ string = dinero.getCurrency();
|
||||
string = dinero.setLocale('fr-FR').getLocale();
|
||||
number = dinero.convertPrecision(4).getPrecision();
|
||||
number = dinero.convertPrecision(4, 'HALF_DOWN').getPrecision();
|
||||
dinero = dinero.add(Dinero({ amount: 104545, precision: 4 }));
|
||||
dinero = dinero.subtract(Dinero({ amount: 104545, precision: 4 }));
|
||||
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);
|
||||
@@ -50,32 +63,33 @@ 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',
|
||||
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.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' }));
|
||||
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();
|
||||
dineroObject = dinero.toJson();
|
||||
dineroArr = Dinero.normalizePrecision([
|
||||
Dinero({ amount: 100, precision: 2 }),
|
||||
Dinero({ amount: 1000, precision: 3 }),
|
||||
Dinero({amount: 100, precision: 2}),
|
||||
Dinero({amount: 1000, precision: 3}),
|
||||
]);
|
||||
|
||||
Vendored
+2
-1
@@ -61,6 +61,7 @@ declare namespace DineroFactory {
|
||||
toUnit(): number;
|
||||
toRoundedUnit(digits: number, roundingMode?: RoundingMode): number;
|
||||
toObject(): DineroObject;
|
||||
toJson(): DineroObject;
|
||||
}
|
||||
|
||||
type RoundingMode =
|
||||
@@ -72,7 +73,7 @@ declare namespace DineroFactory {
|
||||
| 'HALF_AWAY_FROM_ZERO';
|
||||
|
||||
interface ExchangeRatesApiOptions {
|
||||
endpoint: string;
|
||||
endpoint: string | Promise<{[key: string]: any}>;
|
||||
propertyPath: string;
|
||||
headers?: { [header: string]: string };
|
||||
roundingMode?: RoundingMode;
|
||||
|
||||
Reference in New Issue
Block a user