I'm submitting a pull request designed to fix all of the failing jasmine tests for unformatSpect.js.
I noticed a pattern in the 3 unformatSpec failures where the regular expression literal (within the replace method) was not considering the case when parentheses are simply passed as a special character. In this case (ie. accounting.unformat('&*()$ 123,456')), the expected value is a positive number but unformat returns a negative value.
I propose updating the regular expression literal to match only if an open parentheses is followed by a numeric character, then strip out both parentheses and add the negative symbol.
IE.
accounting.unformat('&*()$ 123,456') // returns 123456 accounting.unformat('&*()$ (123,456)') // returns -123456
The 3 failing tests, now pass. I've also added an extra test below to confirm the regExp works as designed:
@wjcrowcroft Hope all's well!
I'm submitting a pull request designed to fix all of the failing jasmine tests for unformatSpect.js.
I noticed a pattern in the 3 unformatSpec failures where the regular expression literal (within the replace method) was not considering the case when parentheses are simply passed as a special character. In this case (ie. accounting.unformat('&*()$ 123,456')), the expected value is a positive number but unformat returns a negative value.
I propose updating the regular expression literal to match only if an open parentheses is followed by a numeric character, then strip out both parentheses and add the negative symbol.
IE.
accounting.unformat('&*()$ 123,456') // returns 123456
accounting.unformat('&*()$ (123,456)') // returns -123456
The 3 failing tests, now pass. I've also added an extra test below to confirm the regExp works as designed:
expect( accounting.unformat('&*()$(123,456)A$@P') ).toBe( -123456 );
Please reach out if there's anything that I can help further clarify in my PR. Thanks!