Skip to content

Commit

Permalink
Merge pull request #70 from zackurben/patch/allow-negative-numbers
Browse files Browse the repository at this point in the history
Patch/allow negative numbers
  • Loading branch information
nosir authored Aug 3, 2016
2 parents 09aaaee + aa2b2b2 commit 061432e
Show file tree
Hide file tree
Showing 7 changed files with 127 additions and 28 deletions.
35 changes: 20 additions & 15 deletions dist/cleave-react.js
Original file line number Diff line number Diff line change
Expand Up @@ -372,17 +372,22 @@ return /******/ (function(modules) { // webpackBootstrap

// strip alphabet letters
value = value.replace(/[A-Za-z]/g, '')

// replace the first decimal mark with reserved placeholder
.replace(owner.numeralDecimalMark, 'M')

// strip the non numeric letters except M
.replace(/[^\dM]/g, '')
// replace the first minus sign reserved placeholder
.replace(/^\-/, 'N')

// strip the non numeric letters except the minus sign and decimal placeholder
.replace(/[^\dMN]/g, '')

// replace mark
// replace the minus sign (if present)
.replace('N', '-')

// replace decimal mark
.replace('M', owner.numeralDecimalMark)

// strip leading 0
// strip any leading zeros
.replace(/^(-)?0+(?=\d)/, '$1');

partInteger = value;
Expand Down Expand Up @@ -421,16 +426,16 @@ return /******/ (function(modules) { // webpackBootstrap
/* 3 */
/***/ function(module, exports) {

module.exports = function(module) {
if(!module.webpackPolyfill) {
module.deprecate = function() {};
module.paths = [];
// module.parent = undefined by default
module.children = [];
module.webpackPolyfill = 1;
}
return module;
}
module.exports = function(module) {
if(!module.webpackPolyfill) {
module.deprecate = function() {};
module.paths = [];
// module.parent = undefined by default
module.children = [];
module.webpackPolyfill = 1;
}
return module;
}


/***/ },
Expand Down
2 changes: 1 addition & 1 deletion dist/cleave-react.min.js

Large diffs are not rendered by default.

15 changes: 10 additions & 5 deletions dist/cleave.js
Original file line number Diff line number Diff line change
Expand Up @@ -673,17 +673,22 @@ NumeralFormatter.prototype = {

// strip alphabet letters
value = value.replace(/[A-Za-z]/g, '')

// replace the first decimal mark with reserved placeholder
.replace(owner.numeralDecimalMark, 'M')

// strip the non numeric letters except M
.replace(/[^\dM]/g, '')
// replace the first minus sign reserved placeholder
.replace(/^\-/, 'N')

// strip the non numeric letters except the minus sign and decimal placeholder
.replace(/[^\dMN]/g, '')

// replace the minus sign (if present)
.replace('N', '-')

// replace mark
// replace decimal mark
.replace('M', owner.numeralDecimalMark)

// strip leading 0
// strip any leading zeros
.replace(/^(-)?0+(?=\d)/, '$1');

partInteger = value;
Expand Down
2 changes: 1 addition & 1 deletion dist/cleave.min.js

Large diffs are not rendered by default.

15 changes: 10 additions & 5 deletions src/shortcuts/NumeralFormatter.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,22 @@ NumeralFormatter.prototype = {

// strip alphabet letters
value = value.replace(/[A-Za-z]/g, '')

// replace the first decimal mark with reserved placeholder
.replace(owner.numeralDecimalMark, 'M')

// strip the non numeric letters except M
.replace(/[^\dM]/g, '')
// replace the first minus sign reserved placeholder
.replace(/^\-/, 'N')

// strip the non numeric letters except the minus sign and decimal placeholder
.replace(/[^\dMN]/g, '')

// replace the minus sign (if present)
.replace('N', '-')

// replace mark
// replace decimal mark
.replace('M', owner.numeralDecimalMark)

// strip leading 0
// strip any leading zeros
.replace(/^(-)?0+(?=\d)/, '$1');

partInteger = value;
Expand Down
2 changes: 1 addition & 1 deletion test/NumeralFormatter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ describe('NumeralFormatter', function () {
title.push('Thousands Group Style: ' + numeral.thousandsGroupStyle);
}

if (numeral.numeralDecimalScale) {
if (numeral.numeralDecimalScale !== undefined) {
title.push('Decimal Scale: ' + numeral.numeralDecimalScale);
}

Expand Down
84 changes: 84 additions & 0 deletions test/fixtures/numeral.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
[
"1234567",
"1,234,567"
],
[
"-1234567",
"-1,234,567"
]
]
},
Expand All @@ -14,6 +18,10 @@
[
"01234567",
"1,234,567"
],
[
"-01234567",
"-1,234,567"
]
]
},
Expand All @@ -23,6 +31,10 @@
[
"0.1234",
"0.12"
],
[
"-0.1234",
"-0.12"
]
]
},
Expand All @@ -32,6 +44,10 @@
[
"00.1234",
"0.12"
],
[
"-00.1234",
"-0.12"
]
]
},
Expand All @@ -41,6 +57,10 @@
[
"123456789",
"12,34,56,789"
],
[
"-123456789",
"-12,34,56,789"
]
]
},
Expand All @@ -50,6 +70,10 @@
[
"123456789",
"1,2345,6789"
],
[
"-123456789",
"-1,2345,6789"
]
]
},
Expand All @@ -60,9 +84,33 @@
"12.3456789",
"12"
],
[
"-12.3456789",
"-12"
],
[
"12.3",
"12"
],
[
"-12.3",
"-12"
],
[
"12.3.0",
"12"
],
[
"-12.3.0",
"-12"
],
[
"12.3-0",
"12"
],
[
"-12.3-0",
"-12"
]
]
},
Expand All @@ -73,9 +121,33 @@
"12.3456789",
"12.345"
],
[
"-12.3456789",
"-12.345"
],
[
"12.3",
"12.3"
],
[
"-12.3",
"-12.3"
],
[
"12.3.0",
"12.30"
],
[
"-12.3.0",
"-12.30"
],
[
"12.3-0",
"12.30"
],
[
"-12.3-0",
"-12.30"
]
]
},
Expand All @@ -86,6 +158,10 @@
[
"1234567,89",
"1.234.567,89"
],
[
"-1234567,89",
"-1.234.567,89"
]
]
},
Expand All @@ -96,6 +172,10 @@
[
"1,234,567.89",
"1234567.89"
],
[
"-1,234,567.89",
"-1234567.89"
]
]
},
Expand All @@ -108,6 +188,10 @@
[
"1234567'8901234",
"12|34|567'8901"
],
[
"-1234567'8901234",
"-12|34|567'8901"
]
]
}
Expand Down

0 comments on commit 061432e

Please sign in to comment.