Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Format function should support decimal #327

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

wapgear
Copy link

@wapgear wapgear commented Jul 25, 2019

On our project we had a problem with your library - for some reason with typeof props.format === "function" library worked only with integers, with this PR it'll also support decimal values.

@wapgear
Copy link
Author

wapgear commented Aug 5, 2019

@s-yadav hey sorry if I disturb you but what do you think about this?

val = this.removePatternFormatting(val);
} else if (typeof removeFormatting === 'function') { //condition need to be handled if format method is provide,
val = removeFormatting(val);
} else {
val = (val.match(/\d/g) || []).join('')
val = this.removePrefixAndSuffix(val);
Copy link
Owner

Choose a reason for hiding this comment

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

We should not handle other formatting props, when format function is provided.

@s-yadav
Copy link
Owner

s-yadav commented Aug 5, 2019

I don't think we should handle prefix / suffix, and other formatting props if format prop is defined as function. If we do so that will lead to lots of corner case which is not meant to be solved by here.

We can look for some regex instead which allows all the valid character of a number and let the format method handle the cases.

Also, If a user needs to have more control on removing formatting he can pass removeFormat method.
I guess we can work on improving the documentation of format (as function) and removeFormatting method, so people are aware of it while using custom format function. What do you say?

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