Skip to content

chore: Refactor price_format function in constant.js#126

Open
asimchoudhary wants to merge 1 commit intodrawrowfly:masterfrom
asimchoudhary:master
Open

chore: Refactor price_format function in constant.js#126
asimchoudhary wants to merge 1 commit intodrawrowfly:masterfrom
asimchoudhary:master

Conversation

@asimchoudhary
Copy link
Copy Markdown

In current implementation of the price_format function within constant.js . I encountered an issue when the input price does not match the expected pattern. Specifically, the price.match(/.*$([0-9.]+)/) expression returns undefined for inputs that do not contain the pattern. This leads to a subsequent error when attempting to access the length property of undefined in the line if (formatedPrice.length > 0).

Copy link
Copy Markdown

@matrayu matrayu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

appears you're solving for the issue at hand. the below is just a little cleaner. I've tested on my forked version and works fine.

price_format: (price) => {
  const formatedPrice = price.match(/.*\$([0-9.]+)/);
  if (formatedPrice && formatedPrice.length > 0) {
    return parseFloat(formatedPrice[1]);
  }
  return 0.0;
},

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants