@agrozyme/numeric 1.0.9 → 1.0.10

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 CHANGED
@@ -1,11 +1,7 @@
1
1
  {
2
2
  "spec_dir": "test",
3
- "spec_files": [
4
- "**/*.test.ts"
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.js CHANGED
@@ -4,11 +4,12 @@ exports.MinInt256 = exports.MaxInt256 = exports.MaxUint256 = exports.WeiPerEther
4
4
  const tslib_1 = require("tslib");
5
5
  const bignumber_1 = require("@ethersproject/bignumber");
6
6
  const bytes_1 = require("@ethersproject/bytes");
7
- const constants = tslib_1.__importStar(require("@ethersproject/constants"));
8
- const big_integer_1 = tslib_1.__importDefault(require("big-integer"));
9
- const bn_js_1 = tslib_1.__importDefault(require("bn.js"));
7
+ const constants = (0, tslib_1.__importStar)(require("@ethersproject/constants"));
8
+ const big_integer_1 = (0, tslib_1.__importDefault)(require("big-integer"));
9
+ const bn_js_1 = (0, 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
- const format_number_1 = tslib_1.__importDefault(require("format-number"));
12
+ const format_number_1 = (0, tslib_1.__importDefault)(require("format-number"));
12
13
  //noinspection FunctionNamingConventionJS
13
14
  class Numeric extends decimal_js_1.Decimal {
14
15
  constructor(value) {
@@ -28,8 +29,8 @@ class Numeric extends decimal_js_1.Decimal {
28
29
  if (big_integer_1.default.isInstance(value) || bignumber_1.BigNumber.isBigNumber(value) || bn_js_1.default.isBN(value)) {
29
30
  super(value.toString());
30
31
  }
31
- else if (bytes_1.isBytesLike(value)) {
32
- super(bytes_1.hexlify(value));
32
+ else if ((0, bytes_1.isBytesLike)(value)) {
33
+ super((0, bytes_1.hexlify)(value));
33
34
  }
34
35
  else {
35
36
  super(value);
@@ -90,7 +91,7 @@ class Numeric extends decimal_js_1.Decimal {
90
91
  return new Numeric(value).floor();
91
92
  }
92
93
  static hypot(...values) {
93
- return new Numeric(decimal_js_1.Decimal.hypot(...exports.toNumerics(values)));
94
+ return new Numeric(decimal_js_1.Decimal.hypot(...(0, exports.toNumerics)(values)));
94
95
  }
95
96
  static ln(value) {
96
97
  return new Numeric(value).ln();
@@ -105,10 +106,10 @@ class Numeric extends decimal_js_1.Decimal {
105
106
  return new Numeric(value).log(2);
106
107
  }
107
108
  static max(...values) {
108
- return new Numeric(decimal_js_1.Decimal.max(...exports.toNumerics(values)));
109
+ return new Numeric(decimal_js_1.Decimal.max(...(0, exports.toNumerics)(values)));
109
110
  }
110
111
  static min(...values) {
111
- return new Numeric(decimal_js_1.Decimal.min(...exports.toNumerics(values)));
112
+ return new Numeric(decimal_js_1.Decimal.min(...(0, exports.toNumerics)(values)));
112
113
  }
113
114
  static mod(x, y) {
114
115
  return new Numeric(x).mod(y);
@@ -361,7 +362,7 @@ class Numeric extends decimal_js_1.Decimal {
361
362
  : super.toDecimalPlaces(decimalPlaces));
362
363
  }
363
364
  toFraction(maxDenominator) {
364
- return exports.toNumerics(super.toFraction(undefined === maxDenominator ? undefined : new Numeric(maxDenominator)));
365
+ return (0, exports.toNumerics)(super.toFraction(undefined === maxDenominator ? undefined : new Numeric(maxDenominator)));
365
366
  }
366
367
  toNearest(value, rounding) {
367
368
  return new Numeric(super.toNearest(new Numeric(value), rounding));
@@ -386,7 +387,8 @@ class Numeric extends decimal_js_1.Decimal {
386
387
  return new Numeric(super.truncated());
387
388
  }
388
389
  inspect(depth, options) {
389
- return options.stylize(this.toFixed(), 'bigint');
390
+ const value = this.toFixed();
391
+ return browser_or_node_1.isNode ? options.stylize(value, 'bigint') : value;
390
392
  }
391
393
  }
392
394
  exports.Numeric = Numeric;
@@ -399,23 +401,23 @@ const toNumerics = (values) => {
399
401
  };
400
402
  exports.toNumerics = toNumerics;
401
403
  const toIntegerString = (value) => {
402
- return exports.toNumeric(value).toFixed(0);
404
+ return (0, exports.toNumeric)(value).toFixed(0);
403
405
  };
404
406
  exports.toIntegerString = toIntegerString;
405
407
  const toBigInt = (value) => {
406
- return BigInt(exports.toIntegerString(value));
408
+ return BigInt((0, exports.toIntegerString)(value));
407
409
  };
408
410
  exports.toBigInt = toBigInt;
409
411
  const toBN = (value) => {
410
- return new bn_js_1.default(exports.toIntegerString(value));
412
+ return new bn_js_1.default((0, exports.toIntegerString)(value));
411
413
  };
412
414
  exports.toBN = toBN;
413
415
  const toBigInteger = (value) => {
414
- return big_integer_1.default(exports.toIntegerString(value));
416
+ return (0, big_integer_1.default)((0, exports.toIntegerString)(value));
415
417
  };
416
418
  exports.toBigInteger = toBigInteger;
417
419
  const toBigNumber = (value) => {
418
- return bignumber_1.BigNumber.from(exports.toIntegerString(value));
420
+ return bignumber_1.BigNumber.from((0, exports.toIntegerString)(value));
419
421
  };
420
422
  exports.toBigNumber = toBigNumber;
421
423
  const createArrayCompareFunction = (ascending = true) => {
@@ -426,7 +428,7 @@ const createArrayCompareFunction = (ascending = true) => {
426
428
  };
427
429
  exports.createArrayCompareFunction = createArrayCompareFunction;
428
430
  const formatValue = (value, options) => {
429
- const format = format_number_1.default(options);
431
+ const format = (0, format_number_1.default)(options);
430
432
  const text = new Numeric(value).toFixed();
431
433
  return format(text);
432
434
  };
package/out/index.mjs CHANGED
@@ -3,6 +3,7 @@ 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
9
  //noinspection FunctionNamingConventionJS
@@ -382,7 +383,8 @@ export class Numeric extends Decimal {
382
383
  return new Numeric(super.truncated());
383
384
  }
384
385
  inspect(depth, options) {
385
- return options.stylize(this.toFixed(), 'bigint');
386
+ const value = this.toFixed();
387
+ return isNode ? options.stylize(value, 'bigint') : value;
386
388
  }
387
389
  }
388
390
  export const toNumeric = (value) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agrozyme/numeric",
3
- "version": "1.0.9",
3
+ "version": "1.0.10",
4
4
  "description": "",
5
5
  "main": "out/index.js",
6
6
  "module": "out/index.mjs",
@@ -11,12 +11,6 @@
11
11
  "require": "./out/index.js"
12
12
  }
13
13
  },
14
- "scripts": {
15
- "clean": "shx rm -f *.tsbuildinfo && shx rm -rf out",
16
- "build": "npm run clean && tsc-multi --force",
17
- "prepublishOnly": "npm run build",
18
- "test": "jasmine --config=jasmine.json"
19
- },
20
14
  "repository": {
21
15
  "type": "git",
22
16
  "url": "git+ssh://git@gitlab.com/agrozyme-package/JavaScript/numeric.git"
@@ -31,18 +25,28 @@
31
25
  "devDependencies": {
32
26
  "@types/bn.js": "^5",
33
27
  "@types/jasmine": "^3",
34
- "@types/node": "^15",
35
- "jasmine": "^3",
28
+ "@types/node": "^17",
29
+ "jasmine": "^4",
36
30
  "shx": "^0",
37
31
  "ts-node": "^10",
38
32
  "tsc-multi": "^0",
39
33
  "typescript": "^4"
40
34
  },
41
35
  "dependencies": {
36
+ "@ethersproject/bignumber": "^5",
37
+ "@ethersproject/bytes": "^5",
42
38
  "@ethersproject/constants": "^5",
43
39
  "big-integer": "^1",
40
+ "bn.js": "^5",
41
+ "browser-or-node": "^2",
44
42
  "decimal.js": "^10",
45
43
  "format-number": "^3",
46
44
  "tslib": "^2"
47
- }
48
- }
45
+ },
46
+ "scripts": {
47
+ "clean": "shx rm -f *.tsbuildinfo && shx rm -rf out",
48
+ "build": "npm run clean && tsc-multi --force",
49
+ "test": "jasmine --config=jasmine.json"
50
+ },
51
+ "readme": "# Numeric\n\nA wrapper of Decimal.js\n\n## Usage\n\nSee the source code for more details.\n\nAll functions are same as Decimal.js and can convert from:\n\n- String\n- Number\n- BigInt\n- Array of Number\n- [bn.js](https://www.npmjs.com/package/bn.js)\n- [BigInteger.js](https://www.npmjs.com/package/big-integer)\n- [Big Numbers](https://www.npmjs.com/package/@ethersproject/bignumber)\n- [Decimal.js](https://www.npmjs.com/package/decimal.js)\n\nExamples:\n\n```ts\nimport { Numeric } from '@agrozyme/numeric';\nconst test1 = new Numeric('1');\nconst test2 = new Numeric(2);\nconst test3 = new Numeric(3n);\nconst test4 = new Numeric([4]);\nconst test5 = new Numeric(new BN(5));\nconst test6 = new Numeric(bigInt('6'));\nconst test7 = new Numeric(BigNumber.from(7));\nconst test8 = new Numeric(new Decimal(8));\n```\n\n## Constants\n\nSame as [Etehreum Constants](https://www.npmjs.com/package/@ethersproject/constants) bignumber constants but export to Numeric type\n\n- NegativeOne\n- Zero\n- One\n- Two\n- WeiPerEther\n- MaxUint256\n- MaxInt256\n- MinInt256\n\n## Helper Functions\n\n- createArrayCompareFunction: create a simple array compare function\n\n```ts\nconst ascending = createArrayCompareFunction(true);\nconst descending = createArrayCompareFunction(false);\n```\n\n- formatValue: use [format-number](https://www.npmjs.com/package/format-number) to format a Numeric-Like value\n\n```ts\nconst text = formatValue(1000, { prefix: '$' });\n```\n\n## Convert Functions\n\nAll convert functions are accept one Numeric-Like argument, except `toNumerics`\n\n- toNumerics: convert a Numeric-Like array to a Numeric array\n\n```ts\nimport { toNumerics } from '@agrozyme/numeric';\nconst test = toNumerics(['1', 2, 3n]);\n```\n\n- toNumeric: convert a Numeric-Like value to a Numeric value\n- toIntegerString: convert a Numeric-Like value to a interger string\n- toBigInt: convert a Numeric-Like value to a `native` bigint value\n- toBN: convert a Numeric-Like value to a BN value\n- toBigInteger: convert a Numeric-Like value to a BigInteger value\n- toBigNumber: convert a Numeric-Like value to a BigNumber value\n\n## Config Functions\n\n- getNumericConfig: get NumericConfig that same as [Decimal.Config](https://mikemcl.github.io/decimal.js/#constructor-properties)\n- setupNumericConfig: setup NumericConfig\n"
52
+ }
package/root/index.ts CHANGED
@@ -3,9 +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
9
  import { InspectOptionsStylized } from 'util';
10
+
9
11
  // const inspect = Symbol.for('nodejs.util.inspect.custom');
10
12
 
11
13
  export type NumericValue = Numeric | Decimal.Value | bigInt.BigNumber | BigNumberish;
@@ -523,7 +525,8 @@ export class Numeric extends Decimal {
523
525
  }
524
526
 
525
527
  inspect(depth: number, options: InspectOptionsStylized) {
526
- return options.stylize(this.toFixed(), 'bigint');
528
+ const value = this.toFixed();
529
+ return isNode ? options.stylize(value, 'bigint'): value;
527
530
  }
528
531
  }
529
532