Skip to content

Commit

Permalink
Negative signs should come before the prefix.
Browse files Browse the repository at this point in the history
  • Loading branch information
jsillitoe committed Dec 9, 2016
1 parent de157e4 commit 36de2ba
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 6 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,14 @@ Optionally set a currency symbol as a prefix or suffix
```
Negative signs come before the prefix
```javascript
// -$20.00
<CurrencyInput prefix="$" value="-20.00" />
```
All other attributes are applied to the input element. For example, you can integrate bootstrap styling:
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-currency-input",
"version": "1.0.9",
"version": "1.0.10",
"description": "React component for inputing currency amounts",
"main": "lib/index.js",
"scripts": {
Expand Down
9 changes: 4 additions & 5 deletions src/mask.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,15 @@ export default function mask(value, precision, decimalSeparator, thousandSeparat
digits.splice(x, 0, thousandSeparator);
}

// if we have a prefix or suffix, add them in.
if (prefix.length > 0){digits.unshift(prefix);}
if (suffix.length > 0){digits.push(suffix);}

// if the number is negative, insert a "-" to
// the front of the array
if (allowNegative && numberIsNegative) {
digits.unshift('-');
}

// if we have a prefix or suffix, add them in.
if (prefix.length > 0){digits.unshift(prefix);}
if (suffix.length > 0){digits.push(suffix);}


return digits.join('').trim();
}
5 changes: 5 additions & 0 deletions test/mask.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,11 @@ describe('mask', function(){
expect(mask("0","2",".",",",true,""," kr ")).to.equal("0.00 kr");
});


it('"-" should come before the prefix', function(){
expect(mask("-20.00","2",".",",",true,"$","")).to.equal("-$20.00");
});

});


Expand Down

0 comments on commit 36de2ba

Please sign in to comment.