bigval
Advanced tools
Comparing version 1.4.0 to 1.5.0
@@ -0,1 +1,9 @@ | ||
# [1.5.0](https://github.com/hiddentao/bigval/compare/v1.4.0...v1.5.0) (2022-03-02) | ||
### Features | ||
* add static construction methods ([c8bb453](https://github.com/hiddentao/bigval/commit/c8bb45396256200241e37c62ec7219ace1ea1cdb)) | ||
* add toMinStr() convenience method ([704e87e](https://github.com/hiddentao/bigval/commit/704e87e1836358dbd3600762e55714e5b0238058)) | ||
# [1.4.0](https://github.com/erdDEVcode/bigval/compare/v1.3.1...v1.4.0) (2021-02-04) | ||
@@ -2,0 +10,0 @@ |
@@ -12,2 +12,6 @@ import { Decimal } from 'decimal.js'; | ||
/** | ||
* Default config for `BigVal`. | ||
*/ | ||
export declare const DefaultBigValConfig: BigValConfig; | ||
/** | ||
* Get whether given value is a `BigVal` instance. | ||
@@ -95,2 +99,19 @@ * @param v A value. | ||
/** | ||
* Construct a `BigVal` instance. | ||
* | ||
* @param src Input number. If this is a `BigVal` instance then `scale` and `config` parameters will be ignored. | ||
* @param scale The scale of the input number. Default is `min`. | ||
* @param config Custom configuration for this instance. | ||
* @returns `BigVal` instance. | ||
*/ | ||
static from(src: any, scale?: string, config?: BigValConfig): BigVal; | ||
/** | ||
* Construct a `BigVal` instance. | ||
* | ||
* @param numScale String in form: `<number> <scale>`. If scale ommitted then `min` is assumed. | ||
* @param config Custom configuration for this instance. | ||
* @returns `BigVal` instance. | ||
*/ | ||
static fromStr(numScale: string, config?: BigValConfig): BigVal; | ||
/** | ||
* Get current scale. | ||
@@ -137,1 +158,11 @@ */ | ||
} | ||
/** | ||
* Get string representation of a `BigVal` in `min` scale. | ||
* | ||
* This internally calls `BigVal.fromStr(numScale, config).toMinScale().toString()`. | ||
* | ||
* @param numScale String in form: `<number> <scale>`. If scale ommitted then `min` is assumed. | ||
* @param config Custom configuration for this instance. | ||
* @returns string | ||
*/ | ||
export declare const toMinStr: (numScale: string, config?: BigValConfig) => string; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.BigVal = exports.isBigVal = void 0; | ||
exports.toMinStr = exports.BigVal = exports.isBigVal = exports.DefaultBigValConfig = void 0; | ||
const decimal_js_1 = require("decimal.js"); | ||
@@ -43,2 +43,6 @@ /** | ||
/** | ||
* Default config for `BigVal`. | ||
*/ | ||
exports.DefaultBigValConfig = { decimals: 18 }; | ||
/** | ||
* Get whether given value is a `BigVal` instance. | ||
@@ -79,3 +83,3 @@ * @param v A value. | ||
*/ | ||
constructor(src, scale = 'min', config = { decimals: 18 }) { | ||
constructor(src, scale = 'min', config = exports.DefaultBigValConfig) { | ||
if (exports.isBigVal(src)) { | ||
@@ -101,2 +105,24 @@ this._n = toDecimal(src._n); | ||
/** | ||
* Construct a `BigVal` instance. | ||
* | ||
* @param src Input number. If this is a `BigVal` instance then `scale` and `config` parameters will be ignored. | ||
* @param scale The scale of the input number. Default is `min`. | ||
* @param config Custom configuration for this instance. | ||
* @returns `BigVal` instance. | ||
*/ | ||
static from(src, scale = 'min', config = exports.DefaultBigValConfig) { | ||
return new BigVal(src, scale, config); | ||
} | ||
/** | ||
* Construct a `BigVal` instance. | ||
* | ||
* @param numScale String in form: `<number> <scale>`. If scale ommitted then `min` is assumed. | ||
* @param config Custom configuration for this instance. | ||
* @returns `BigVal` instance. | ||
*/ | ||
static fromStr(numScale, config = exports.DefaultBigValConfig) { | ||
const t = numScale.split(' '); | ||
return this.from(t[0], t[1], config); | ||
} | ||
/** | ||
* Get current scale. | ||
@@ -195,1 +221,14 @@ */ | ||
exports.BigVal = BigVal; | ||
/** | ||
* Get string representation of a `BigVal` in `min` scale. | ||
* | ||
* This internally calls `BigVal.fromStr(numScale, config).toMinScale().toString()`. | ||
* | ||
* @param numScale String in form: `<number> <scale>`. If scale ommitted then `min` is assumed. | ||
* @param config Custom configuration for this instance. | ||
* @returns string | ||
*/ | ||
const toMinStr = (numScale, config = exports.DefaultBigValConfig) => { | ||
return BigVal.fromStr(numScale, config).toMinScale().toString(); | ||
}; | ||
exports.toMinStr = toMinStr; |
@@ -12,2 +12,6 @@ import { Decimal } from 'decimal.js'; | ||
/** | ||
* Default config for `BigVal`. | ||
*/ | ||
export declare const DefaultBigValConfig: BigValConfig; | ||
/** | ||
* Get whether given value is a `BigVal` instance. | ||
@@ -95,2 +99,19 @@ * @param v A value. | ||
/** | ||
* Construct a `BigVal` instance. | ||
* | ||
* @param src Input number. If this is a `BigVal` instance then `scale` and `config` parameters will be ignored. | ||
* @param scale The scale of the input number. Default is `min`. | ||
* @param config Custom configuration for this instance. | ||
* @returns `BigVal` instance. | ||
*/ | ||
static from(src: any, scale?: string, config?: BigValConfig): BigVal; | ||
/** | ||
* Construct a `BigVal` instance. | ||
* | ||
* @param numScale String in form: `<number> <scale>`. If scale ommitted then `min` is assumed. | ||
* @param config Custom configuration for this instance. | ||
* @returns `BigVal` instance. | ||
*/ | ||
static fromStr(numScale: string, config?: BigValConfig): BigVal; | ||
/** | ||
* Get current scale. | ||
@@ -137,1 +158,11 @@ */ | ||
} | ||
/** | ||
* Get string representation of a `BigVal` in `min` scale. | ||
* | ||
* This internally calls `BigVal.fromStr(numScale, config).toMinScale().toString()`. | ||
* | ||
* @param numScale String in form: `<number> <scale>`. If scale ommitted then `min` is assumed. | ||
* @param config Custom configuration for this instance. | ||
* @returns string | ||
*/ | ||
export declare const toMinStr: (numScale: string, config?: BigValConfig) => string; |
@@ -40,2 +40,6 @@ import { Decimal } from 'decimal.js'; | ||
/** | ||
* Default config for `BigVal`. | ||
*/ | ||
export const DefaultBigValConfig = { decimals: 18 }; | ||
/** | ||
* Get whether given value is a `BigVal` instance. | ||
@@ -75,3 +79,3 @@ * @param v A value. | ||
*/ | ||
constructor(src, scale = 'min', config = { decimals: 18 }) { | ||
constructor(src, scale = 'min', config = DefaultBigValConfig) { | ||
if (isBigVal(src)) { | ||
@@ -97,2 +101,24 @@ this._n = toDecimal(src._n); | ||
/** | ||
* Construct a `BigVal` instance. | ||
* | ||
* @param src Input number. If this is a `BigVal` instance then `scale` and `config` parameters will be ignored. | ||
* @param scale The scale of the input number. Default is `min`. | ||
* @param config Custom configuration for this instance. | ||
* @returns `BigVal` instance. | ||
*/ | ||
static from(src, scale = 'min', config = DefaultBigValConfig) { | ||
return new BigVal(src, scale, config); | ||
} | ||
/** | ||
* Construct a `BigVal` instance. | ||
* | ||
* @param numScale String in form: `<number> <scale>`. If scale ommitted then `min` is assumed. | ||
* @param config Custom configuration for this instance. | ||
* @returns `BigVal` instance. | ||
*/ | ||
static fromStr(numScale, config = DefaultBigValConfig) { | ||
const t = numScale.split(' '); | ||
return this.from(t[0], t[1], config); | ||
} | ||
/** | ||
* Get current scale. | ||
@@ -190,1 +216,13 @@ */ | ||
} | ||
/** | ||
* Get string representation of a `BigVal` in `min` scale. | ||
* | ||
* This internally calls `BigVal.fromStr(numScale, config).toMinScale().toString()`. | ||
* | ||
* @param numScale String in form: `<number> <scale>`. If scale ommitted then `min` is assumed. | ||
* @param config Custom configuration for this instance. | ||
* @returns string | ||
*/ | ||
export const toMinStr = (numScale, config = DefaultBigValConfig) => { | ||
return BigVal.fromStr(numScale, config).toMinScale().toString(); | ||
}; |
{ | ||
"name": "bigval", | ||
"version": "1.4.0", | ||
"description": ".", | ||
"version": "1.5.0", | ||
"description": "Easier calculation and formatting of crypto values with decimals. Useful for smart contract interaction.", | ||
"main": "dist/cjs/index.js", | ||
"module": "dist/esm/index.js", | ||
"types": "dist/esm/index.d.ts", | ||
"author": "erdDEV team (https://erd.dev)", | ||
"homepage": "https://erddevcode.github.io/bigval/", | ||
"author": "Ramesh Nair <ram@hiddentao.com>", | ||
"homepage": "https://hiddentao.github.io/bigval/", | ||
"license": "MIT", | ||
@@ -19,6 +19,2 @@ "files": [ | ||
], | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/erdDEVcode/bigval.git" | ||
}, | ||
"devDependencies": { | ||
@@ -25,0 +21,0 @@ "@commitlint/cli": "^9.1.2", |
@@ -40,2 +40,3 @@ [![NPM module](https://badge.fury.io/js/bigval.svg)](https://badge.fury.io/js/bigval) | ||
Scaling: | ||
@@ -61,3 +62,3 @@ | ||
const v3 = v2.tominScale() | ||
const v3 = v2.toMinScale() | ||
@@ -82,2 +83,20 @@ console.log( v3.scale ) // 'min' | ||
Initializing using `from()` static convenience method: | ||
```js | ||
const v6 = BigVal::from('1', 'coins', { decimals: 2 }) | ||
const v6_1 = v6.toMinScale() | ||
console.log( v6_1.scale ) // 'min' | ||
console.log( v6_1.toString() ) // "100" | ||
``` | ||
Initializing using `fromStr()` static method: | ||
```js | ||
const v7 = BigVal::fromStr('2 coins') // same as BigVal::from(2, 'coins') | ||
const v8 = BigVal::fromStr('0.5 min') // same as BigVal::from(0.5, 'min') | ||
const v9 = BigVal::fromStr('0xff', { decimals: 2 }) // same as BigVal::from(0xff, undefined, { decimals: 2 }) | ||
``` | ||
Output in different types: | ||
@@ -84,0 +103,0 @@ |
Sorry, the diff of this file is too big to display
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
No website
QualityPackage does not have a website.
Found 1 instance in 1 package
411415
11783
0
201
1