Skip to content

Commit

Permalink
Fix issue #474 AutoNumeric.format() and AutoNumeric.unformat() do…
Browse files Browse the repository at this point in the history
… not accept named options

Signed-off-by: Alexandre Bonneau <alexandre.bonneau@linuxfr.eu>
  • Loading branch information
AlexandreBonneau committed Aug 3, 2017
1 parent b49864d commit ff48f13
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 8 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
@@ -1,5 +1,8 @@
## Changelog for autoNumeric

### 4.0.3
+ Fix issue #474 `AutoNumeric.format()` and `AutoNumeric.unformat()` do not accept named options

### 4.0.2
+ Fix issue #473 Static `format()` and `unformat()` functions ignores the `rawValueDivisor` option
+ Fix `AutoNumeric.unformat()` that used the number of decimal places shown on focus instead of the one for the raw value.
Expand Down
2 changes: 1 addition & 1 deletion dist/autoNumeric.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/autoNumeric.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/autoNumeric.min.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "autonumeric",
"version": "4.0.2",
"version": "4.0.3",
"description": "autoNumeric is a standalone Javascript library that provides live *as-you-type* formatting for international numbers and currencies. It supports most international numeric formats and currencies including those used in Europe, Asia, and North and South America.",
"main": "dist/autoNumeric.js",
"readmeFilename": "README.md",
Expand Down
8 changes: 4 additions & 4 deletions src/AutoNumeric.js
@@ -1,7 +1,7 @@
/**
* AutoNumeric.js
*
* @version 4.0.2
* @version 4.0.3
* @date 2017-08-02 UTC 02:50
*
* @authors Bob Knothe, Alexandre Bonneau
Expand Down Expand Up @@ -815,7 +815,7 @@ class AutoNumeric {
* @returns {string}
*/
static version() {
return '4.0.2';
return '4.0.3';
}

/**
Expand Down Expand Up @@ -3580,7 +3580,7 @@ To solve that, you'd need to either set \`decimalPlacesRawValue\` to \`null\`, o
* Analyse the given array `options` and return a single 'merged' option objet.
* `options` can be `null`, or an array of an option objects, or an array containing another array of option objects / strings (pre-defined option names)
*
* @param {null|Array<object|Array<string|object>>} options
* @param {null|Array<object|string|Array<string|object>>} options
* @returns {null|object}
* @private
*/
Expand All @@ -3597,7 +3597,7 @@ To solve that, you'd need to either set \`decimalPlacesRawValue\` to \`null\`, o
});
} else if (options.length >= 1) {
options.forEach(optionObject => {
Object.assign(optionsResult, optionObject);
Object.assign(optionsResult, this._getOptionObject(optionObject));
});
}
}
Expand Down
18 changes: 18 additions & 0 deletions test/unit/autoNumeric.spec.js
Expand Up @@ -5627,6 +5627,15 @@ describe('Static autoNumeric functions', () => {
expect(AutoNumeric.unformat('123,45 €', autoNumericOptionsEuroNumber)).toEqual(123.45);
expect(AutoNumeric.unformat('0,00 €', autoNumericOptionsEuroNumber)).toEqual(0);

expect(AutoNumeric.unformat('1.234,56\u202f€', AutoNumeric.getPredefinedOptions().euro)).toEqual('1234.56');
expect(AutoNumeric.unformat('1.234,56\u202f€', 'euro')).toEqual('1234.56');
expect(AutoNumeric.unformat('1.234,56\u202f€', ['euro'])).toEqual('1234.56');
expect(AutoNumeric.unformat('1.234,56 CFP', ['euro', { currencySymbol: ' CFP' }])).toEqual('1234.56');
expect(AutoNumeric.unformat('1.234,56 CFP', 'euro', { currencySymbol: ' CFP' })).toEqual('1234.56');
expect(AutoNumeric.unformat('72.687,41\u202f€', AutoNumeric.getPredefinedOptions().euro)).toEqual('72687.41');
expect(AutoNumeric.unformat('72.687,41\u202f€', 'euro')).toEqual('72687.41');
expect(AutoNumeric.unformat('72.687,41\u202f€', ['euro'])).toEqual('72687.41');

expect(AutoNumeric.unformat('1.234,56 €', autoNumericOptionsEuro)).toEqual('1234.56');
expect(AutoNumeric.unformat('123,45 €', autoNumericOptionsEuro)).toEqual('123.45');
expect(AutoNumeric.unformat('0,00 €', autoNumericOptionsEuro)).toEqual('0.00');
Expand Down Expand Up @@ -5942,6 +5951,15 @@ describe('Static autoNumeric functions', () => {
expect(AutoNumeric.format('123,45 €', autoNumericOptionsEuro)).toEqual('123,45 €');
expect(AutoNumeric.format(0, autoNumericOptionsEuro)).toEqual('0,00 €');

expect(AutoNumeric.format(1234.56, AutoNumeric.getPredefinedOptions().euro)).toEqual('1.234,56\u202f€');
expect(AutoNumeric.format(1234.56, 'euro')).toEqual('1.234,56\u202f€');
expect(AutoNumeric.format(1234.56, ['euro'])).toEqual('1.234,56\u202f€');
expect(AutoNumeric.format(1234.56, ['euro', { currencySymbol: ' CFP' }])).toEqual('1.234,56 CFP');
expect(AutoNumeric.format(1234.56, 'euro', { currencySymbol: ' CFP' })).toEqual('1.234,56 CFP');
expect(AutoNumeric.format(72687.408552029, AutoNumeric.getPredefinedOptions().euro)).toEqual('72.687,41\u202f€');
expect(AutoNumeric.format(72687.408552029, 'euro')).toEqual('72.687,41\u202f€');
expect(AutoNumeric.format(72687.408552029, ['euro'])).toEqual('72.687,41\u202f€');

expect(AutoNumeric.format(1234.56, autoNumericOptionsDollar)).toEqual('$1,234.56');
expect(AutoNumeric.format(123.45, autoNumericOptionsDollar)).toEqual('$123.45');
expect(AutoNumeric.format('$1,234.56', autoNumericOptionsDollar)).toEqual('$1,234.56');
Expand Down

0 comments on commit ff48f13

Please sign in to comment.