@signpostmarv/intermediary-number 0.2.0 → 0.3.0

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.
@@ -653,6 +653,9 @@ export class TokenScan {
653
653
  return this.parsed.compare(value);
654
654
  }
655
655
  divide(value) {
656
+ if (IntermediaryNumber.reuse_or_create(value).isOne()) {
657
+ return this;
658
+ }
656
659
  return new TokenScan([
657
660
  this,
658
661
  '/',
@@ -684,6 +687,9 @@ export class TokenScan {
684
687
  return this.parsed.max(first, ...remaining);
685
688
  }
686
689
  minus(value) {
690
+ if (IntermediaryNumber.reuse_or_create(value).isZero()) {
691
+ return this;
692
+ }
687
693
  return new TokenScan([
688
694
  this,
689
695
  '-',
@@ -698,6 +704,9 @@ export class TokenScan {
698
704
  ]);
699
705
  }
700
706
  plus(value) {
707
+ if (IntermediaryNumber.reuse_or_create(value).isZero()) {
708
+ return this;
709
+ }
701
710
  return new TokenScan([
702
711
  this,
703
712
  '+',
@@ -709,6 +718,9 @@ export class TokenScan {
709
718
  return IntermediaryCalculation.is(parsed) ? parsed.resolve() : parsed;
710
719
  }
711
720
  times(value) {
721
+ if (IntermediaryNumber.reuse_or_create(value).isOne()) {
722
+ return this;
723
+ }
712
724
  return new TokenScan([
713
725
  this,
714
726
  'x',
@@ -739,9 +751,12 @@ export class TokenScan {
739
751
  toStringCalculation() {
740
752
  if (this.value instanceof Array) {
741
753
  const left_operand = this.value[0];
754
+ const right_operand = IntermediaryNumber.reuse_or_create(this.value[2]);
742
755
  return `${(left_operand.parsed instanceof IntermediaryNumber)
743
756
  ? left_operand.toString()
744
- : `(${left_operand.toStringCalculation()})`} ${this.value[1]} ${IntermediaryNumber.reuse_or_create(this.value[2]).toStringCalculation()}`;
757
+ : `(${left_operand.toStringCalculation()})`} ${this.value[1]} ${(right_operand instanceof IntermediaryNumber)
758
+ ? right_operand.toStringCalculation()
759
+ : `(${right_operand.toStringCalculation()})`}`;
745
760
  }
746
761
  return this.value;
747
762
  }
package/package.json CHANGED
@@ -9,6 +9,7 @@
9
9
  },
10
10
  "funding": "https://github.com/SignpostMarv/Intermediary-Number?sponsor=1",
11
11
  "exports": "./index.js",
12
+ "types": "./index.d.ts",
12
13
  "devDependencies": {
13
14
  "@eslint/js": "^9.4.0",
14
15
  "@stdlib/types": "^0.3.2",
@@ -28,5 +29,5 @@
28
29
  "bignumber.js": "^9.1.2",
29
30
  "fraction.js": "^4.3.7"
30
31
  },
31
- "version": "0.2.0"
32
+ "version": "0.3.0"
32
33
  }