@tetcoin/util
Version:
A collection of useful utilities for @tetcoin
38 lines (32 loc) • 1 kB
JavaScript
;
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = bnToBn;
var _bn = _interopRequireDefault(require("bn.js"));
// Copyright 2017-2019 @polkadot/util authors & contributors
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
/**
* @name bnToBn
* @summary Creates a BN value from a BN.js bignumber or number input.
* @description
* `null` inputs returns a `0x0` result, BN values returns the value, numnbers returns a BN representation.
* @example
* <BR>
*
* ```javascript
* import BN from 'bn.js';
* import { bnToBn } from '@tetcoin/util';
*
* bnToBn(0x1234); // => BN(0x1234)
* bnToBn(new BN(0x1234)); // => BN(0x1234)
* ```
*/
function bnToBn(value) {
if (!value) {
return new _bn.default(0);
}
return _bn.default.isBN(value) ? value : new _bn.default(value);
}