Showing with 44 additions and 44 deletions.
  1. +4 −4 README.md
  2. +5 −5 doc/api/number/format-number.md
  3. +5 −5 doc/api/number/number-formatter.md
  4. +26 −26 src/number.js
  5. +2 −2 test/functional/number/format-number.js
  6. +2 −2 test/functional/number/number-formatter.js
@@ -275,15 +275,15 @@ to you in different flavors):
<a name="number_module"></a>
### Number module

- **`.numberFormatter( attributes )`**
- **`.numberFormatter( [options] )`**

Return a function that formats a number according to the given attributes.
Return a function that formats a number according to the given options.

[Read more...](doc/api/number/number-formatter.md)

- **`.formatNumber( value [, attributes] )`**
- **`.formatNumber( value [, options] )`**

Format a number according to the given attributes.
Format a number according to the given options.

[Read more...](doc/api/number/format-number.md)

@@ -1,8 +1,8 @@
## .formatNumber( value [, attributes] )
## .formatNumber( value [, options] )

Format a number `value` according to the given `attributes`.
Format a number `value` according to the given `options`.

*Important*: Favor [`.numberFormatter( attributes )`](./number-formatter.md) if
*Important*: Favor [`.numberFormatter( [options] )`](./number-formatter.md) if
repeating the same format over a series of numbers for improved performance.

### Parameters
@@ -11,9 +11,9 @@ repeating the same format over a series of numbers for improved performance.

Number to be formatted, eg. `3.14`.

**attributes** Optional
**options** Optional

See [`.numberFormatter( attributes )`](./number-formatter.md).
See [`.numberFormatter( [options] )`](./number-formatter.md).

### Example

@@ -1,12 +1,12 @@
## .numberFormatter( attributes )
## .numberFormatter( [options] )

Return a function that formats a number according to the given attributes.
Return a function that formats a number according to the given options.

### Parameters

**attributes**
**options** Optional

A JSON object including none or any of the following attributes.
A JSON object including none or any of the following options.

> **style** Optional
>
@@ -53,7 +53,7 @@ var formatter;
Globalize.locale( "en" );
formatter = Globalize.numberFormatter();
formatter( 3.141592 ); // "3.142"
formatter( 3.141592 ); // "3.142"
```

You can use the instance method `.numberFormatter()`, which uses the instance
@@ -18,51 +18,34 @@ define([
numberPattern ) {

/**
* .formatNumber( value [, attributes] )
* .numberFormatter( [options] )
*
* @value [Number] number to be formatted.
*
* @attributes [Object]: see .numberFormatter().
*
* Format a number according to the given attributes and default/instance locale.
*/
Globalize.formatNumber =
Globalize.prototype.formatNumber = function( value, attributes ) {
validateParameterPresence( value, "value" );
validateParameterTypeNumber( value, "value" );

return this.numberFormatter( attributes )( value );
};

/**
* .numberFormatter( [attributes] )
*
* @attributes [Object]:
* @options [Object]:
* - style: [String] "decimal" (default) or "percent".
* - see also number/format options.
*
* Return a function that formats a number according to the given attribute and default/instance
* Return a function that formats a number according to the given options and default/instance
* locale.
*/
Globalize.numberFormatter =
Globalize.prototype.numberFormatter = function( attributes ) {
Globalize.prototype.numberFormatter = function( options ) {
var cldr, maximumFractionDigits, maximumSignificantDigits, minimumFractionDigits,
minimumIntegerDigits, minimumSignificantDigits, pattern, properties;

validateParameterTypePlainObject( attributes, "attributes" );
validateParameterTypePlainObject( options, "options" );

attributes = attributes || {};
options = options || {};
cldr = this.cldr;

validateDefaultLocale( cldr );

cldr.on( "get", validateCldr );

if ( !attributes.pattern ) {
pattern = numberPattern( attributes.style || "decimal", cldr );
if ( !options.pattern ) {
pattern = numberPattern( options.style || "decimal", cldr );
}

properties = numberFormatProperties( pattern, cldr, attributes );
properties = numberFormatProperties( pattern, cldr, options );

cldr.off( "get", validateCldr );

@@ -98,6 +81,23 @@ Globalize.prototype.numberFormatter = function( attributes ) {
};
};

/**
* .formatNumber( value [, options] )
*
* @value [Number] number to be formatted.
*
* @options [Object]: see number/format-properties.
*
* Format a number according to the given options and default/instance locale.
*/
Globalize.formatNumber =
Globalize.prototype.formatNumber = function( value, options ) {
validateParameterPresence( value, "value" );
validateParameterTypeNumber( value, "value" );

return this.numberFormatter( options )( value );
};

/**
* .parseNumber( value )
*
@@ -16,7 +16,7 @@ function extraSetup() {
Globalize.load( esNumbers );
}

QUnit.module( ".formatNumber( value [, attributes] )", {
QUnit.module( ".formatNumber( value [, options] )", {
setup: function() {
Globalize.load( likelySubtags );
Globalize.locale( "en" );
@@ -35,7 +35,7 @@ QUnit.test( "should validate parameters", function( assert ) {
};
});

util.assertPlainObjectParameter( assert, "attributes", function( invalidValue ) {
util.assertPlainObjectParameter( assert, "options", function( invalidValue ) {
return function() {
Globalize.formatNumber( 7, invalidValue );
};
@@ -16,7 +16,7 @@ function extraSetup() {
Globalize.load( esNumbers );
}

QUnit.module( ".numberFormatter( [attributes] )", {
QUnit.module( ".numberFormatter( [options] )", {
setup: function() {
Globalize.load( likelySubtags );
Globalize.locale( "en" );
@@ -25,7 +25,7 @@ QUnit.module( ".numberFormatter( [attributes] )", {
});

QUnit.test( "should validate parameters", function( assert ) {
util.assertPlainObjectParameter( assert, "attributes", function( invalidValue ) {
util.assertPlainObjectParameter( assert, "options", function( invalidValue ) {
return function() {
Globalize.numberFormatter( invalidValue );
};