Skip to content

Conversation

@asimchoudhary
Copy link

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

@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