@ubeswap/token-math
Advanced tools
Comparing version 5.0.1 to 5.0.2
@@ -8,2 +8,5 @@ import _Big from "big.js"; | ||
export declare const Big: typeof _Big; | ||
/** | ||
* Formatting options for Decimal.js. | ||
*/ | ||
export interface NumberFormat { | ||
@@ -10,0 +13,0 @@ decimalSeparator?: string; |
@@ -22,5 +22,5 @@ "use strict"; | ||
const toFixedRounding = { | ||
[constants_1.Rounding.ROUND_DOWN]: 0 /* RoundDown */, | ||
[constants_1.Rounding.ROUND_HALF_UP]: 1 /* RoundHalfUp */, | ||
[constants_1.Rounding.ROUND_UP]: 3 /* RoundUp */, | ||
[constants_1.Rounding.ROUND_DOWN]: exports.Big.roundDown, | ||
[constants_1.Rounding.ROUND_HALF_UP]: exports.Big.roundHalfUp, | ||
[constants_1.Rounding.ROUND_UP]: exports.Big.roundUp, | ||
}; | ||
@@ -27,0 +27,0 @@ /** |
@@ -10,2 +10,10 @@ import { Rounding } from "./constants"; | ||
readonly scalar: Fraction; | ||
/** | ||
* Constructs a Price. | ||
* | ||
* denominator and numerator _must_ be raw, i.e. in the native representation | ||
* | ||
* @param denominator Units of base currency. E.g. 1 BTC would be 1_00000000 | ||
* @param numerator Units of quote currency. E.g. $30k at 6 decimals would be 30_000_000000 | ||
*/ | ||
constructor(baseCurrency: T, quoteCurrency: T, denominator: BigintIsh, numerator: BigintIsh); | ||
@@ -25,3 +33,11 @@ /** | ||
toFixed(decimalPlaces?: number, format?: NumberFormat, rounding?: Rounding): string; | ||
/** | ||
* Returns the price in terms of the quote currency. | ||
* @param format | ||
* @param rounding | ||
* @returns | ||
*/ | ||
toFixedQuote(format?: NumberFormat, rounding?: Rounding): string; | ||
get asNumber(): number; | ||
} | ||
//# sourceMappingURL=price.d.ts.map |
@@ -9,3 +9,10 @@ "use strict"; | ||
class Price extends fraction_1.Fraction { | ||
// denominator and numerator _must_ be raw, i.e. in the native representation | ||
/** | ||
* Constructs a Price. | ||
* | ||
* denominator and numerator _must_ be raw, i.e. in the native representation | ||
* | ||
* @param denominator Units of base currency. E.g. 1 BTC would be 1_00000000 | ||
* @param numerator Units of quote currency. E.g. $30k at 6 decimals would be 30_000_000000 | ||
*/ | ||
constructor(baseCurrency, quoteCurrency, denominator, numerator) { | ||
@@ -42,4 +49,16 @@ super((0, utils_1.parseBigintIsh)(numerator), (0, utils_1.parseBigintIsh)(denominator)); | ||
} | ||
/** | ||
* Returns the price in terms of the quote currency. | ||
* @param format | ||
* @param rounding | ||
* @returns | ||
*/ | ||
toFixedQuote(format = { groupSeparator: "" }, rounding) { | ||
return this.toFixed(this.quoteCurrency.decimals, format, rounding); | ||
} | ||
get asNumber() { | ||
return this.adjusted.asNumber; | ||
} | ||
} | ||
exports.Price = Price; | ||
//# sourceMappingURL=price.js.map |
@@ -21,3 +21,3 @@ "use strict"; | ||
exports.parseBigintIsh = parseBigintIsh; | ||
const decimalMultipliersCache = []; | ||
const decimalMultipliersCache = {}; | ||
/** | ||
@@ -24,0 +24,0 @@ * Creates the multiplier for an amount of decimals. |
@@ -8,2 +8,5 @@ import _Big from "big.js"; | ||
export declare const Big: typeof _Big; | ||
/** | ||
* Formatting options for Decimal.js. | ||
*/ | ||
export interface NumberFormat { | ||
@@ -10,0 +13,0 @@ decimalSeparator?: string; |
@@ -18,5 +18,5 @@ import _Big from "big.js"; | ||
const toFixedRounding = { | ||
[Rounding.ROUND_DOWN]: 0 /* RoundDown */, | ||
[Rounding.ROUND_HALF_UP]: 1 /* RoundHalfUp */, | ||
[Rounding.ROUND_UP]: 3 /* RoundUp */, | ||
[Rounding.ROUND_DOWN]: Big.roundDown, | ||
[Rounding.ROUND_HALF_UP]: Big.roundHalfUp, | ||
[Rounding.ROUND_UP]: Big.roundUp, | ||
}; | ||
@@ -23,0 +23,0 @@ /** |
@@ -10,2 +10,10 @@ import { Rounding } from "./constants"; | ||
readonly scalar: Fraction; | ||
/** | ||
* Constructs a Price. | ||
* | ||
* denominator and numerator _must_ be raw, i.e. in the native representation | ||
* | ||
* @param denominator Units of base currency. E.g. 1 BTC would be 1_00000000 | ||
* @param numerator Units of quote currency. E.g. $30k at 6 decimals would be 30_000_000000 | ||
*/ | ||
constructor(baseCurrency: T, quoteCurrency: T, denominator: BigintIsh, numerator: BigintIsh); | ||
@@ -25,3 +33,11 @@ /** | ||
toFixed(decimalPlaces?: number, format?: NumberFormat, rounding?: Rounding): string; | ||
/** | ||
* Returns the price in terms of the quote currency. | ||
* @param format | ||
* @param rounding | ||
* @returns | ||
*/ | ||
toFixedQuote(format?: NumberFormat, rounding?: Rounding): string; | ||
get asNumber(): number; | ||
} | ||
//# sourceMappingURL=price.d.ts.map |
@@ -5,3 +5,10 @@ import invariant from "tiny-invariant"; | ||
export class Price extends Fraction { | ||
// denominator and numerator _must_ be raw, i.e. in the native representation | ||
/** | ||
* Constructs a Price. | ||
* | ||
* denominator and numerator _must_ be raw, i.e. in the native representation | ||
* | ||
* @param denominator Units of base currency. E.g. 1 BTC would be 1_00000000 | ||
* @param numerator Units of quote currency. E.g. $30k at 6 decimals would be 30_000_000000 | ||
*/ | ||
constructor(baseCurrency, quoteCurrency, denominator, numerator) { | ||
@@ -38,3 +45,15 @@ super(parseBigintIsh(numerator), parseBigintIsh(denominator)); | ||
} | ||
/** | ||
* Returns the price in terms of the quote currency. | ||
* @param format | ||
* @param rounding | ||
* @returns | ||
*/ | ||
toFixedQuote(format = { groupSeparator: "" }, rounding) { | ||
return this.toFixed(this.quoteCurrency.decimals, format, rounding); | ||
} | ||
get asNumber() { | ||
return this.adjusted.asNumber; | ||
} | ||
} | ||
//# sourceMappingURL=price.js.map |
@@ -16,3 +16,3 @@ import BN from "bn.js"; | ||
} | ||
const decimalMultipliersCache = []; | ||
const decimalMultipliersCache = {}; | ||
/** | ||
@@ -19,0 +19,0 @@ * Creates the multiplier for an amount of decimals. |
@@ -5,3 +5,3 @@ { | ||
"license": "MIT", | ||
"version": "5.0.1", | ||
"version": "5.0.2", | ||
"description": "⚒️ A library for token math.", | ||
@@ -8,0 +8,0 @@ "website": "https://ubeswap.org", |
@@ -1,2 +0,2 @@ | ||
import _Big, { RoundingMode } from "big.js"; | ||
import _Big from "big.js"; | ||
import _Decimal from "decimal.js-light"; | ||
@@ -23,7 +23,10 @@ import JSBI from "jsbi"; | ||
const toFixedRounding = { | ||
[Rounding.ROUND_DOWN]: RoundingMode.RoundDown, | ||
[Rounding.ROUND_HALF_UP]: RoundingMode.RoundHalfUp, | ||
[Rounding.ROUND_UP]: RoundingMode.RoundUp, | ||
[Rounding.ROUND_DOWN]: Big.roundDown, | ||
[Rounding.ROUND_HALF_UP]: Big.roundHalfUp, | ||
[Rounding.ROUND_UP]: Big.roundUp, | ||
}; | ||
/** | ||
* Formatting options for Decimal.js. | ||
*/ | ||
export interface NumberFormat { | ||
@@ -30,0 +33,0 @@ decimalSeparator?: string; |
@@ -14,3 +14,10 @@ import invariant from "tiny-invariant"; | ||
// denominator and numerator _must_ be raw, i.e. in the native representation | ||
/** | ||
* Constructs a Price. | ||
* | ||
* denominator and numerator _must_ be raw, i.e. in the native representation | ||
* | ||
* @param denominator Units of base currency. E.g. 1 BTC would be 1_00000000 | ||
* @param numerator Units of quote currency. E.g. $30k at 6 decimals would be 30_000_000000 | ||
*/ | ||
constructor( | ||
@@ -102,2 +109,19 @@ baseCurrency: T, | ||
} | ||
/** | ||
* Returns the price in terms of the quote currency. | ||
* @param format | ||
* @param rounding | ||
* @returns | ||
*/ | ||
toFixedQuote( | ||
format: NumberFormat = { groupSeparator: "" }, | ||
rounding?: Rounding | ||
): string { | ||
return this.toFixed(this.quoteCurrency.decimals, format, rounding); | ||
} | ||
override get asNumber(): number { | ||
return this.adjusted.asNumber; | ||
} | ||
} |
@@ -24,3 +24,3 @@ import BN from "bn.js"; | ||
const decimalMultipliersCache: JSBI[] = []; | ||
const decimalMultipliersCache: Record<number, JSBI> = {}; | ||
@@ -27,0 +27,0 @@ /** |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
171101
79
3355