pimath 0.0.105 → 0.0.106

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/dist/pi.js CHANGED
@@ -4990,7 +4990,7 @@ const fraction_1 = __webpack_require__(506);
4990
4990
  class NumExp {
4991
4991
  constructor(value, uniformize) {
4992
4992
  this._expression = value;
4993
- this._rpn = new shutingyard_1.Shutingyard(shutingyard_1.ShutingyardMode.NUMERIC).parse(value).rpn;
4993
+ this._rpn = new shutingyard_1.Shutingyard(shutingyard_1.ShutingyardMode.NUMERIC).parse(value, uniformize).rpn;
4994
4994
  }
4995
4995
  get rpn() {
4996
4996
  return this._rpn;
@@ -7608,78 +7608,92 @@ class Shutingyard {
7608
7608
  // add the last token
7609
7609
  return normalizedExpr + nextToken;
7610
7610
  }
7611
- /**
7612
- * Sanitize an expression by adding missing common operation (multiplication between parentheseses)
7613
- * @param expr
7614
- * @constructor
7615
- */
7616
- Uniformizer(expr) {
7617
- // TODO: Delete this old version
7618
- // Prefere "normalize", much more robust !
7619
- // Determiner if need to be uniformized
7620
- if (!this._uniformize) {
7621
- return expr;
7622
- }
7623
- // Generate the list of function token.
7624
- let fnToken = [];
7625
- for (let token in this._tokenConfig) {
7626
- if (this._tokenConfig[token].type === ShutingyardType.FUNCTION) {
7627
- fnToken.push(token);
7628
- }
7629
- }
7630
- // sort if from the lengthy to the smallest function
7631
- fnToken.sort((a, b) => b.length - a.length);
7632
- let tokenRegExp = new RegExp(`(${fnToken.join('|')})`, 'g');
7633
- let functionTokenOrder = Array.from(expr.matchAll(tokenRegExp));
7634
- let expr2;
7635
- // Replace all function by @
7636
- expr2 = expr.replace(tokenRegExp, '@');
7637
- // Add * before @ (functionn)
7638
- expr2 = expr2.replace(/([\da-zA-Z])(@)/g, "$1*$2");
7639
- // Replace missing multiplication between two parenthese
7640
- expr2 = expr2.replace(/\)\(/g, ')*(');
7641
- // Replace missing multiplication between number or setLetter and parenthese.
7642
- // 3x(x-4) => 3x*(x-4)
7643
- expr2 = expr2.replace(/([\da-zA-Z])(\()/g, "$1*$2");
7644
- // (x-4)3x => (x-4)*3x
7645
- expr2 = expr2.replace(/(\))([\da-zA-Z])/g, "$1*$2");
7646
- // Add multiplication between number and letters.
7647
- // 3x => 3*x
7648
- expr2 = expr2.replace(/([0-9])([a-zA-Z])/g, "$1*$2");
7649
- expr2 = expr2.replace(/([a-zA-Z])([0-9])/g, "$1*$2");
7650
- // Remove letter between function token and it's parenthese.
7651
- // for (let token of fnToken) {
7652
- // // Remove
7653
- // expr2 = expr2.replace(new RegExp(token + '\\*', 'g'), token);
7654
- // }
7655
- // Add multiplication between letters ?
7656
- expr2 = expr2.replace(/([a-zA-Z])([a-zA-Z])/g, "$1*$2");
7657
- expr2 = expr2.replace(/([a-zA-Z])([a-zA-Z])/g, "$1*$2");
7658
- // Restore operation auto formatting (prevent adding the multiplication star)
7659
- let exprAsArray = expr2.split('@');
7660
- if (exprAsArray.length > 0) {
7661
- expr2 = "";
7662
- for (let idx in exprAsArray) {
7663
- }
7664
- for (let token of fnToken) {
7665
- // Remove
7666
- // expr2 = expr2.replace(new RegExp(token + '\\*', 'g'), token);
7667
- }
7668
- }
7669
- return expr2;
7670
- }
7611
+ // /**
7612
+ // * Sanitize an expression by adding missing common operation (multiplication between parentheseses)
7613
+ // * @param expr
7614
+ // * @constructor
7615
+ // */
7616
+ // Uniformizer(expr: string): string {
7617
+ // // TODO: Delete this old version
7618
+ // // Prefere "normalize", much more robust !
7619
+ // // Determiner if need to be uniformized
7620
+ // if (!this._uniformize) {
7621
+ // return expr
7622
+ // }
7623
+ //
7624
+ // // Generate the list of function token.
7625
+ // let fnToken: string[] = []
7626
+ // for (let token in this._tokenConfig) {
7627
+ // if (this._tokenConfig[token].type === ShutingyardType.FUNCTION) {
7628
+ // fnToken.push(token)
7629
+ // }
7630
+ // }
7631
+ // // sort if from the lengthy to the smallest function
7632
+ // fnToken.sort((a, b) => b.length - a.length)
7633
+ // let tokenRegExp = new RegExp(`(${fnToken.join('|')})`, 'g')
7634
+ // let functionTokenOrder = Array.from(expr.matchAll(tokenRegExp))
7635
+ //
7636
+ //
7637
+ // let expr2;
7638
+ //
7639
+ // // Replace all function by @
7640
+ // expr2 = expr.replace(tokenRegExp, '@')
7641
+ // // Add * before @ (functionn)
7642
+ // expr2 = expr2.replace(/([\da-zA-Z])(@)/g, "$1*$2");
7643
+ //
7644
+ // // Replace missing multiplication between two parenthese
7645
+ // expr2 = expr2.replace(/\)\(/g, ')*(');
7646
+ //
7647
+ // // Replace missing multiplication between number or setLetter and parenthese.
7648
+ //
7649
+ // // 3x(x-4) => 3x*(x-4)
7650
+ // expr2 = expr2.replace(/([\da-zA-Z])(\()/g, "$1*$2");
7651
+ //
7652
+ // // (x-4)3x => (x-4)*3x
7653
+ // expr2 = expr2.replace(/(\))([\da-zA-Z])/g, "$1*$2");
7654
+ //
7655
+ // // Add multiplication between number and letters.
7656
+ // // 3x => 3*x
7657
+ // expr2 = expr2.replace(/([0-9])([a-zA-Z])/g, "$1*$2");
7658
+ // expr2 = expr2.replace(/([a-zA-Z])([0-9])/g, "$1*$2");
7659
+ //
7660
+ // // Remove letter between function token and it's parenthese.
7661
+ // // for (let token of fnToken) {
7662
+ // // // Remove
7663
+ // // expr2 = expr2.replace(new RegExp(token + '\\*', 'g'), token);
7664
+ // // }
7665
+ // // Add multiplication between letters ?
7666
+ // expr2 = expr2.replace(/([a-zA-Z])([a-zA-Z])/g, "$1*$2");
7667
+ // expr2 = expr2.replace(/([a-zA-Z])([a-zA-Z])/g, "$1*$2");
7668
+ //
7669
+ // // Restore operation auto formatting (prevent adding the multiplication star)
7670
+ // let exprAsArray = expr2.split('@')
7671
+ //
7672
+ // if (exprAsArray.length > 0) {
7673
+ // expr2 = ""
7674
+ // for (let idx in exprAsArray) {
7675
+ // }
7676
+ // for (let token of fnToken) {
7677
+ // // Remove
7678
+ //
7679
+ // // expr2 = expr2.replace(new RegExp(token + '\\*', 'g'), token);
7680
+ // }
7681
+ // }
7682
+ //
7683
+ // return expr2;
7684
+ // }
7671
7685
  /**
7672
7686
  * Parse an expression using the shutting yard tree algorithms
7673
7687
  * @param expr (string) Expression to analyse
7674
7688
  * Returns a RPN list of items.
7675
- * @param operators
7689
+ * @param uniformize
7676
7690
  */
7677
- parse(expr, operators) {
7691
+ parse(expr, uniformize) {
7678
7692
  let outQueue = [], // Output queue
7679
7693
  opStack = [], // Operation queue
7680
7694
  token = '', tokenPos = 0, tokenType = '', previousOpStatckLength = 0;
7681
7695
  // Normalize the input if required.
7682
- if (this._uniformize)
7696
+ if (uniformize || this._uniformize)
7683
7697
  expr = this.normalize(expr);
7684
7698
  let securityLoopLvl1 = 50, securityLoopLvl2_default = 50, securityLoopLvl2;
7685
7699
  while (tokenPos < expr.length) {