@agrozyme/numeric 1.0.8 → 1.0.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/jasmine.json +2 -6
- package/out/index.d.ts +2 -3
- package/out/index.js +19 -18
- package/out/index.mjs +7 -6
- package/package.json +5 -2
- package/root/index.ts +9 -7
package/jasmine.json
CHANGED
|
@@ -1,11 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"spec_dir": "test",
|
|
3
|
-
"spec_files": [
|
|
4
|
-
|
|
5
|
-
],
|
|
6
|
-
"requires": [
|
|
7
|
-
"ts-node/register"
|
|
8
|
-
],
|
|
3
|
+
"spec_files": ["**/*.test.ts"],
|
|
4
|
+
"requires": ["node_modules/ts-node/register/index.js"],
|
|
9
5
|
"stopSpecOnExpectationFailure": false,
|
|
10
6
|
"random": true
|
|
11
7
|
}
|
package/out/index.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { BigNumber, BigNumberish } from '@ethersproject/bignumber';
|
|
|
3
3
|
import bigInt from 'big-integer';
|
|
4
4
|
import BN from 'bn.js';
|
|
5
5
|
import { Decimal } from 'decimal.js';
|
|
6
|
-
import
|
|
6
|
+
import { InspectOptionsStylized } from 'util';
|
|
7
7
|
export declare type NumericValue = Numeric | Decimal.Value | bigInt.BigNumber | BigNumberish;
|
|
8
8
|
export interface IFormatNumberOptions {
|
|
9
9
|
negativeType?: 'right' | 'left' | 'brackets' | 'none';
|
|
@@ -23,7 +23,6 @@ export interface IFormatNumberOptions {
|
|
|
23
23
|
}
|
|
24
24
|
export declare class Numeric extends Decimal {
|
|
25
25
|
constructor(value: NumericValue);
|
|
26
|
-
get [Symbol.toStringTag](): string;
|
|
27
26
|
static abs(value: NumericValue): Numeric;
|
|
28
27
|
static acos(value: NumericValue): Numeric;
|
|
29
28
|
static acosh(value: NumericValue): Numeric;
|
|
@@ -136,7 +135,7 @@ export declare class Numeric extends Decimal {
|
|
|
136
135
|
toSignificantDigits(decimalPlaces?: number, rounding?: Decimal.Rounding): Numeric;
|
|
137
136
|
trunc(): Numeric;
|
|
138
137
|
truncated(): Numeric;
|
|
139
|
-
|
|
138
|
+
inspect(depth: number, options: InspectOptionsStylized): string;
|
|
140
139
|
}
|
|
141
140
|
export declare const toNumeric: (value: NumericValue) => Numeric;
|
|
142
141
|
export declare const toNumerics: (values: NumericValue[]) => Numeric[];
|
package/out/index.js
CHANGED
|
@@ -7,9 +7,9 @@ const bytes_1 = require("@ethersproject/bytes");
|
|
|
7
7
|
const constants = tslib_1.__importStar(require("@ethersproject/constants"));
|
|
8
8
|
const big_integer_1 = tslib_1.__importDefault(require("big-integer"));
|
|
9
9
|
const bn_js_1 = tslib_1.__importDefault(require("bn.js"));
|
|
10
|
+
const browser_or_node_1 = require("browser-or-node");
|
|
10
11
|
const decimal_js_1 = require("decimal.js");
|
|
11
12
|
const format_number_1 = tslib_1.__importDefault(require("format-number"));
|
|
12
|
-
const util_1 = tslib_1.__importDefault(require("util"));
|
|
13
13
|
//noinspection FunctionNamingConventionJS
|
|
14
14
|
class Numeric extends decimal_js_1.Decimal {
|
|
15
15
|
constructor(value) {
|
|
@@ -29,8 +29,8 @@ class Numeric extends decimal_js_1.Decimal {
|
|
|
29
29
|
if (big_integer_1.default.isInstance(value) || bignumber_1.BigNumber.isBigNumber(value) || bn_js_1.default.isBN(value)) {
|
|
30
30
|
super(value.toString());
|
|
31
31
|
}
|
|
32
|
-
else if (bytes_1.isBytesLike(value)) {
|
|
33
|
-
super(bytes_1.hexlify(value));
|
|
32
|
+
else if ((0, bytes_1.isBytesLike)(value)) {
|
|
33
|
+
super((0, bytes_1.hexlify)(value));
|
|
34
34
|
}
|
|
35
35
|
else {
|
|
36
36
|
super(value);
|
|
@@ -39,9 +39,9 @@ class Numeric extends decimal_js_1.Decimal {
|
|
|
39
39
|
}
|
|
40
40
|
}
|
|
41
41
|
}
|
|
42
|
-
get [Symbol.toStringTag]() {
|
|
43
|
-
|
|
44
|
-
}
|
|
42
|
+
// get [Symbol.toStringTag]() {
|
|
43
|
+
// return 'Numeric';
|
|
44
|
+
// }
|
|
45
45
|
static abs(value) {
|
|
46
46
|
return new Numeric(value).abs();
|
|
47
47
|
}
|
|
@@ -91,7 +91,7 @@ class Numeric extends decimal_js_1.Decimal {
|
|
|
91
91
|
return new Numeric(value).floor();
|
|
92
92
|
}
|
|
93
93
|
static hypot(...values) {
|
|
94
|
-
return new Numeric(decimal_js_1.Decimal.hypot(...exports.toNumerics(values)));
|
|
94
|
+
return new Numeric(decimal_js_1.Decimal.hypot(...(0, exports.toNumerics)(values)));
|
|
95
95
|
}
|
|
96
96
|
static ln(value) {
|
|
97
97
|
return new Numeric(value).ln();
|
|
@@ -106,10 +106,10 @@ class Numeric extends decimal_js_1.Decimal {
|
|
|
106
106
|
return new Numeric(value).log(2);
|
|
107
107
|
}
|
|
108
108
|
static max(...values) {
|
|
109
|
-
return new Numeric(decimal_js_1.Decimal.max(...exports.toNumerics(values)));
|
|
109
|
+
return new Numeric(decimal_js_1.Decimal.max(...(0, exports.toNumerics)(values)));
|
|
110
110
|
}
|
|
111
111
|
static min(...values) {
|
|
112
|
-
return new Numeric(decimal_js_1.Decimal.min(...exports.toNumerics(values)));
|
|
112
|
+
return new Numeric(decimal_js_1.Decimal.min(...(0, exports.toNumerics)(values)));
|
|
113
113
|
}
|
|
114
114
|
static mod(x, y) {
|
|
115
115
|
return new Numeric(x).mod(y);
|
|
@@ -362,7 +362,7 @@ class Numeric extends decimal_js_1.Decimal {
|
|
|
362
362
|
: super.toDecimalPlaces(decimalPlaces));
|
|
363
363
|
}
|
|
364
364
|
toFraction(maxDenominator) {
|
|
365
|
-
return exports.toNumerics(super.toFraction(undefined === maxDenominator ? undefined : new Numeric(maxDenominator)));
|
|
365
|
+
return (0, exports.toNumerics)(super.toFraction(undefined === maxDenominator ? undefined : new Numeric(maxDenominator)));
|
|
366
366
|
}
|
|
367
367
|
toNearest(value, rounding) {
|
|
368
368
|
return new Numeric(super.toNearest(new Numeric(value), rounding));
|
|
@@ -386,8 +386,9 @@ class Numeric extends decimal_js_1.Decimal {
|
|
|
386
386
|
truncated() {
|
|
387
387
|
return new Numeric(super.truncated());
|
|
388
388
|
}
|
|
389
|
-
|
|
390
|
-
|
|
389
|
+
inspect(depth, options) {
|
|
390
|
+
const value = this.toFixed();
|
|
391
|
+
return browser_or_node_1.isNode ? options.stylize(value, 'bigint') : value;
|
|
391
392
|
}
|
|
392
393
|
}
|
|
393
394
|
exports.Numeric = Numeric;
|
|
@@ -400,23 +401,23 @@ const toNumerics = (values) => {
|
|
|
400
401
|
};
|
|
401
402
|
exports.toNumerics = toNumerics;
|
|
402
403
|
const toIntegerString = (value) => {
|
|
403
|
-
return exports.toNumeric(value).toFixed(0);
|
|
404
|
+
return (0, exports.toNumeric)(value).toFixed(0);
|
|
404
405
|
};
|
|
405
406
|
exports.toIntegerString = toIntegerString;
|
|
406
407
|
const toBigInt = (value) => {
|
|
407
|
-
return BigInt(exports.toIntegerString(value));
|
|
408
|
+
return BigInt((0, exports.toIntegerString)(value));
|
|
408
409
|
};
|
|
409
410
|
exports.toBigInt = toBigInt;
|
|
410
411
|
const toBN = (value) => {
|
|
411
|
-
return new bn_js_1.default(exports.toIntegerString(value));
|
|
412
|
+
return new bn_js_1.default((0, exports.toIntegerString)(value));
|
|
412
413
|
};
|
|
413
414
|
exports.toBN = toBN;
|
|
414
415
|
const toBigInteger = (value) => {
|
|
415
|
-
return big_integer_1.default(exports.toIntegerString(value));
|
|
416
|
+
return (0, big_integer_1.default)((0, exports.toIntegerString)(value));
|
|
416
417
|
};
|
|
417
418
|
exports.toBigInteger = toBigInteger;
|
|
418
419
|
const toBigNumber = (value) => {
|
|
419
|
-
return bignumber_1.BigNumber.from(exports.toIntegerString(value));
|
|
420
|
+
return bignumber_1.BigNumber.from((0, exports.toIntegerString)(value));
|
|
420
421
|
};
|
|
421
422
|
exports.toBigNumber = toBigNumber;
|
|
422
423
|
const createArrayCompareFunction = (ascending = true) => {
|
|
@@ -427,7 +428,7 @@ const createArrayCompareFunction = (ascending = true) => {
|
|
|
427
428
|
};
|
|
428
429
|
exports.createArrayCompareFunction = createArrayCompareFunction;
|
|
429
430
|
const formatValue = (value, options) => {
|
|
430
|
-
const format = format_number_1.default(options);
|
|
431
|
+
const format = (0, format_number_1.default)(options);
|
|
431
432
|
const text = new Numeric(value).toFixed();
|
|
432
433
|
return format(text);
|
|
433
434
|
};
|
package/out/index.mjs
CHANGED
|
@@ -3,9 +3,9 @@ import { hexlify, isBytesLike } from '@ethersproject/bytes';
|
|
|
3
3
|
import * as constants from '@ethersproject/constants';
|
|
4
4
|
import bigInt from 'big-integer';
|
|
5
5
|
import BN from 'bn.js';
|
|
6
|
+
import { isNode } from 'browser-or-node';
|
|
6
7
|
import { Decimal } from 'decimal.js';
|
|
7
8
|
import formatter from 'format-number';
|
|
8
|
-
import util from 'util';
|
|
9
9
|
//noinspection FunctionNamingConventionJS
|
|
10
10
|
export class Numeric extends Decimal {
|
|
11
11
|
constructor(value) {
|
|
@@ -35,9 +35,9 @@ export class Numeric extends Decimal {
|
|
|
35
35
|
}
|
|
36
36
|
}
|
|
37
37
|
}
|
|
38
|
-
get [Symbol.toStringTag]() {
|
|
39
|
-
|
|
40
|
-
}
|
|
38
|
+
// get [Symbol.toStringTag]() {
|
|
39
|
+
// return 'Numeric';
|
|
40
|
+
// }
|
|
41
41
|
static abs(value) {
|
|
42
42
|
return new Numeric(value).abs();
|
|
43
43
|
}
|
|
@@ -382,8 +382,9 @@ export class Numeric extends Decimal {
|
|
|
382
382
|
truncated() {
|
|
383
383
|
return new Numeric(super.truncated());
|
|
384
384
|
}
|
|
385
|
-
|
|
386
|
-
|
|
385
|
+
inspect(depth, options) {
|
|
386
|
+
const value = this.toFixed();
|
|
387
|
+
return isNode ? options.stylize(value, 'bigint') : value;
|
|
387
388
|
}
|
|
388
389
|
}
|
|
389
390
|
export const toNumeric = (value) => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agrozyme/numeric",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.11",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "out/index.js",
|
|
6
6
|
"module": "out/index.mjs",
|
|
@@ -31,7 +31,9 @@
|
|
|
31
31
|
"devDependencies": {
|
|
32
32
|
"@types/bn.js": "^5",
|
|
33
33
|
"@types/jasmine": "^3",
|
|
34
|
-
"
|
|
34
|
+
"@types/node": "^17",
|
|
35
|
+
"jasmine": "^4",
|
|
36
|
+
"prettier": "^2",
|
|
35
37
|
"shx": "^0",
|
|
36
38
|
"ts-node": "^10",
|
|
37
39
|
"tsc-multi": "^0",
|
|
@@ -40,6 +42,7 @@
|
|
|
40
42
|
"dependencies": {
|
|
41
43
|
"@ethersproject/constants": "^5",
|
|
42
44
|
"big-integer": "^1",
|
|
45
|
+
"browser-or-node": "^2",
|
|
43
46
|
"decimal.js": "^10",
|
|
44
47
|
"format-number": "^3",
|
|
45
48
|
"tslib": "^2"
|
package/root/index.ts
CHANGED
|
@@ -3,10 +3,11 @@ import { hexlify, isBytesLike } from '@ethersproject/bytes';
|
|
|
3
3
|
import * as constants from '@ethersproject/constants';
|
|
4
4
|
import bigInt from 'big-integer';
|
|
5
5
|
import BN from 'bn.js';
|
|
6
|
+
import { isNode } from 'browser-or-node';
|
|
6
7
|
import { Decimal } from 'decimal.js';
|
|
7
8
|
import formatter from 'format-number';
|
|
8
|
-
import
|
|
9
|
-
|
|
9
|
+
import { InspectOptionsStylized } from 'util';
|
|
10
|
+
|
|
10
11
|
// const inspect = Symbol.for('nodejs.util.inspect.custom');
|
|
11
12
|
|
|
12
13
|
export type NumericValue = Numeric | Decimal.Value | bigInt.BigNumber | BigNumberish;
|
|
@@ -55,9 +56,9 @@ export class Numeric extends Decimal {
|
|
|
55
56
|
}
|
|
56
57
|
}
|
|
57
58
|
|
|
58
|
-
get [Symbol.toStringTag]() {
|
|
59
|
-
|
|
60
|
-
}
|
|
59
|
+
// get [Symbol.toStringTag]() {
|
|
60
|
+
// return 'Numeric';
|
|
61
|
+
// }
|
|
61
62
|
|
|
62
63
|
static abs(value: NumericValue) {
|
|
63
64
|
return new Numeric(value).abs();
|
|
@@ -523,8 +524,9 @@ export class Numeric extends Decimal {
|
|
|
523
524
|
return new Numeric(super.truncated());
|
|
524
525
|
}
|
|
525
526
|
|
|
526
|
-
|
|
527
|
-
|
|
527
|
+
inspect(depth: number, options: InspectOptionsStylized) {
|
|
528
|
+
const value = this.toFixed();
|
|
529
|
+
return isNode ? options.stylize(value, 'bigint') : value;
|
|
528
530
|
}
|
|
529
531
|
}
|
|
530
532
|
|