Socket
Socket
Sign inDemoInstall

@xchainjs/xchain-util

Package Overview
Dependencies
Maintainers
6
Versions
39
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@xchainjs/xchain-util - npm Package Compare versions

Comparing version 0.2.5 to 0.2.6

8

CHANGELOG.md

@@ -0,1 +1,9 @@

# v.0.2.6 (2021-03-16)
### Update
- Extend BaseAmount/AssetAmount to support basic arithmetic operations(add, minus, times, div)
- Extend BaseAmount/AssetAmount to support basic comparison
- Add type guard `isBigNumberValue` for BigNumber.Value
# v.0.2.5 (2021-03-04)

@@ -2,0 +10,0 @@

33

lib/asset.d.ts
import BigNumber from 'bignumber.js';
import { Denomination, AssetAmount, BaseAmount, Amounts, Asset } from './types';
import { AssetAmount, BaseAmount, Amounts, Asset } from './types';
/**
* Guard to check whether value is a BigNumber.Value or not
*
* @param {unknown} v
* @returns {boolean} `true` or `false`.
* */
export declare const isBigNumberValue: (v: unknown) => v is BigNumber.Value;
/**
* Factory to create values of assets (e.g. RUNE)

@@ -11,7 +18,3 @@ *

**/
export declare const assetAmount: (value: string | number | BigNumber | undefined, decimal?: number) => {
type: Denomination.ASSET;
amount: () => BigNumber;
decimal: number;
};
export declare const assetAmount: (value: BigNumber.Value | undefined, decimal?: number) => AssetAmount;
/**

@@ -24,7 +27,3 @@ * Factory to create base amounts (e.g. tor)

**/
export declare const baseAmount: (value: string | number | BigNumber | undefined, decimal?: number) => {
type: Denomination.BASE;
amount: () => BigNumber;
decimal: number;
};
export declare const baseAmount: (value: BigNumber.Value | undefined, decimal?: number) => BaseAmount;
/**

@@ -50,7 +49,3 @@ * Helper to convert values for a asset from base values (e.g. RUNE from tor)

* */
export declare const isAssetAmount: (v: Amounts) => v is {
type: Denomination.ASSET;
amount: () => BigNumber;
decimal: number;
};
export declare const isAssetAmount: (v: Amounts) => v is AssetAmount;
/**

@@ -62,7 +57,3 @@ * Guard to check whether value is an amount of a base value or not

* */
export declare const isBaseAmount: (v: Amounts) => v is {
type: Denomination.BASE;
amount: () => BigNumber;
decimal: number;
};
export declare const isBaseAmount: (v: Amounts) => v is BaseAmount;
/**

@@ -69,0 +60,0 @@ * Formats an `AssetAmount` into `string` based on decimal places

@@ -66,3 +66,3 @@ import BigNumber from 'bignumber.js';

* */
export declare const fixedBN: (value: number | string | BigNumber | undefined, decimalPlaces?: number) => BigNumber;
export declare const fixedBN: (value: BigNumber.Value | undefined, decimalPlaces?: number) => BigNumber;
export default bn;

@@ -212,2 +212,11 @@ import BigNumber from 'bignumber.js';

/**
* Guard to check whether value is a BigNumber.Value or not
*
* @param {unknown} v
* @returns {boolean} `true` or `false`.
* */
var isBigNumberValue = function (v) {
return typeof v === 'string' || typeof v === 'number' || v instanceof BigNumber;
};
/**
* Default number of asset decimals

@@ -233,7 +242,29 @@ * For history reason and by starting the project on Binance chain assets, it's 8 decimal.

if (decimal === void 0) { decimal = ASSET_DECIMAL; }
return ({
var amount = fixedBN(value, decimal);
return {
type: Denomination.ASSET,
amount: function () { return fixedBN(value, decimal); },
amount: function () { return amount; },
plus: function (v, d) {
if (d === void 0) { d = decimal; }
return assetAmount(amount.plus(isBigNumberValue(v) ? v : v.amount()), d);
},
minus: function (v, d) {
if (d === void 0) { d = decimal; }
return assetAmount(amount.minus(isBigNumberValue(v) ? v : v.amount()), d);
},
times: function (v, d) {
if (d === void 0) { d = decimal; }
return assetAmount(amount.times(isBigNumberValue(v) ? v : v.amount()), d);
},
div: function (v, d) {
if (d === void 0) { d = decimal; }
return assetAmount(amount.div(isBigNumberValue(v) ? v : v.amount()), d);
},
lt: function (v) { return amount.lt(isBigNumberValue(v) ? v : v.amount()); },
lte: function (v) { return amount.lte(isBigNumberValue(v) ? v : v.amount()); },
gt: function (v) { return amount.gt(isBigNumberValue(v) ? v : v.amount()); },
gte: function (v) { return amount.gte(isBigNumberValue(v) ? v : v.amount()); },
eq: function (v) { return amount.eq(isBigNumberValue(v) ? v : v.amount()); },
decimal: decimal,
});
};
};

@@ -249,7 +280,29 @@ /**

if (decimal === void 0) { decimal = ASSET_DECIMAL; }
return ({
var amount = fixedBN(value, 0);
return {
type: Denomination.BASE,
amount: function () { return fixedBN(value, 0); },
amount: function () { return amount; },
plus: function (v, d) {
if (d === void 0) { d = decimal; }
return baseAmount(amount.plus(isBigNumberValue(v) ? v : v.amount()), d);
},
minus: function (v, d) {
if (d === void 0) { d = decimal; }
return baseAmount(amount.minus(isBigNumberValue(v) ? v : v.amount()), d);
},
times: function (v, d) {
if (d === void 0) { d = decimal; }
return baseAmount(amount.times(isBigNumberValue(v) ? v : v.amount()), d);
},
div: function (v, d) {
if (d === void 0) { d = decimal; }
return baseAmount(amount.div(isBigNumberValue(v) ? v : v.amount()), d);
},
lt: function (v) { return amount.lt(isBigNumberValue(v) ? v : v.amount()); },
lte: function (v) { return amount.lte(isBigNumberValue(v) ? v : v.amount()); },
gt: function (v) { return amount.gt(isBigNumberValue(v) ? v : v.amount()); },
gte: function (v) { return amount.gte(isBigNumberValue(v) ? v : v.amount()); },
eq: function (v) { return amount.eq(isBigNumberValue(v) ? v : v.amount()); },
decimal: decimal,
});
};
};

@@ -549,3 +602,3 @@ /**

export { AssetBCH, AssetBNB, AssetBTC, AssetCurrencySymbol, AssetETH, AssetLTC, AssetRune67C, AssetRuneB1A, AssetRuneERC20, AssetRuneERC20Testnet, AssetRuneNative, BCHChain, BNBChain, BTCChain, CosmosChain, Denomination, ETHChain, LTCChain, PolkadotChain, RUNE_TICKER, THORChain, assetAmount, assetFromString, assetToBase, assetToString, baseAmount, baseToAsset, bn, bnOrZero, chainToString, chains, currencySymbolByAsset, delay, fixedBN, formatAssetAmount, formatAssetAmountCurrency, formatBN, formatBNCurrency, formatBaseAmount, formatBaseAsAssetAmount, isAssetAmount, isBaseAmount, isChain, isValidAsset, isValidBN, trimZeros, validBNOrZero };
export { AssetBCH, AssetBNB, AssetBTC, AssetCurrencySymbol, AssetETH, AssetLTC, AssetRune67C, AssetRuneB1A, AssetRuneERC20, AssetRuneERC20Testnet, AssetRuneNative, BCHChain, BNBChain, BTCChain, CosmosChain, Denomination, ETHChain, LTCChain, PolkadotChain, RUNE_TICKER, THORChain, assetAmount, assetFromString, assetToBase, assetToString, baseAmount, baseToAsset, bn, bnOrZero, chainToString, chains, currencySymbolByAsset, delay, fixedBN, formatAssetAmount, formatAssetAmountCurrency, formatBN, formatBNCurrency, formatBaseAmount, formatBaseAsAssetAmount, isAssetAmount, isBaseAmount, isBigNumberValue, isChain, isValidAsset, isValidBN, trimZeros, validBNOrZero };
//# sourceMappingURL=index.esm.js.map

@@ -219,2 +219,11 @@ 'use strict';

/**
* Guard to check whether value is a BigNumber.Value or not
*
* @param {unknown} v
* @returns {boolean} `true` or `false`.
* */
var isBigNumberValue = function (v) {
return typeof v === 'string' || typeof v === 'number' || v instanceof BigNumber__default['default'];
};
/**
* Default number of asset decimals

@@ -240,7 +249,29 @@ * For history reason and by starting the project on Binance chain assets, it's 8 decimal.

if (decimal === void 0) { decimal = ASSET_DECIMAL; }
return ({
var amount = fixedBN(value, decimal);
return {
type: exports.Denomination.ASSET,
amount: function () { return fixedBN(value, decimal); },
amount: function () { return amount; },
plus: function (v, d) {
if (d === void 0) { d = decimal; }
return assetAmount(amount.plus(isBigNumberValue(v) ? v : v.amount()), d);
},
minus: function (v, d) {
if (d === void 0) { d = decimal; }
return assetAmount(amount.minus(isBigNumberValue(v) ? v : v.amount()), d);
},
times: function (v, d) {
if (d === void 0) { d = decimal; }
return assetAmount(amount.times(isBigNumberValue(v) ? v : v.amount()), d);
},
div: function (v, d) {
if (d === void 0) { d = decimal; }
return assetAmount(amount.div(isBigNumberValue(v) ? v : v.amount()), d);
},
lt: function (v) { return amount.lt(isBigNumberValue(v) ? v : v.amount()); },
lte: function (v) { return amount.lte(isBigNumberValue(v) ? v : v.amount()); },
gt: function (v) { return amount.gt(isBigNumberValue(v) ? v : v.amount()); },
gte: function (v) { return amount.gte(isBigNumberValue(v) ? v : v.amount()); },
eq: function (v) { return amount.eq(isBigNumberValue(v) ? v : v.amount()); },
decimal: decimal,
});
};
};

@@ -256,7 +287,29 @@ /**

if (decimal === void 0) { decimal = ASSET_DECIMAL; }
return ({
var amount = fixedBN(value, 0);
return {
type: exports.Denomination.BASE,
amount: function () { return fixedBN(value, 0); },
amount: function () { return amount; },
plus: function (v, d) {
if (d === void 0) { d = decimal; }
return baseAmount(amount.plus(isBigNumberValue(v) ? v : v.amount()), d);
},
minus: function (v, d) {
if (d === void 0) { d = decimal; }
return baseAmount(amount.minus(isBigNumberValue(v) ? v : v.amount()), d);
},
times: function (v, d) {
if (d === void 0) { d = decimal; }
return baseAmount(amount.times(isBigNumberValue(v) ? v : v.amount()), d);
},
div: function (v, d) {
if (d === void 0) { d = decimal; }
return baseAmount(amount.div(isBigNumberValue(v) ? v : v.amount()), d);
},
lt: function (v) { return amount.lt(isBigNumberValue(v) ? v : v.amount()); },
lte: function (v) { return amount.lte(isBigNumberValue(v) ? v : v.amount()); },
gt: function (v) { return amount.gt(isBigNumberValue(v) ? v : v.amount()); },
gte: function (v) { return amount.gte(isBigNumberValue(v) ? v : v.amount()); },
eq: function (v) { return amount.eq(isBigNumberValue(v) ? v : v.amount()); },
decimal: decimal,
});
};
};

@@ -592,2 +645,3 @@ /**

exports.isBaseAmount = isBaseAmount;
exports.isBigNumberValue = isBigNumberValue;
exports.isChain = isChain;

@@ -594,0 +648,0 @@ exports.isValidAsset = isValidAsset;

@@ -16,2 +16,11 @@ import BigNumber from 'bignumber.js';

amount: () => BigNumber;
plus: (value: BigNumber.Value | Amount<T>, decimal?: number) => Amount<T>;
minus: (value: BigNumber.Value | Amount<T>, decimal?: number) => Amount<T>;
times: (value: BigNumber.Value | Amount<T>, decimal?: number) => Amount<T>;
div: (value: BigNumber.Value | Amount<T>, decimal?: number) => Amount<T>;
gt: (value: BigNumber.Value | Amount<T>) => boolean;
gte: (value: BigNumber.Value | Amount<T>) => boolean;
lt: (value: BigNumber.Value | Amount<T>) => boolean;
lte: (value: BigNumber.Value | Amount<T>) => boolean;
eq: (value: BigNumber.Value | Amount<T>) => boolean;
decimal: number;

@@ -18,0 +27,0 @@ };

{
"name": "@xchainjs/xchain-util",
"version": "0.2.5",
"version": "0.2.6",
"description": "Helper utilities for XChain clients",

@@ -5,0 +5,0 @@ "keywords": [

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc