Skip to content

Commit

Permalink
Plans: rename lib from currency-formatter to format-currency
Browse files Browse the repository at this point in the history
  • Loading branch information
gwwar committed Jun 17, 2016
1 parent 9bdcc45 commit 96155c8
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 20 deletions.
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
Currency Formatter
Format Currency
==========
Given a currency code, this library will take in a number and display it as money correctly.

Usage
==========
```javascript
import currencyFormatter from 'lib/currency-formatter';
import formatCurrency from 'lib/format-currency';

const USD = currencyFormatter( 9800900.32, 'USD' ); // '$9,800,900.32'
const EUR = currencyFormatter( 9800900.32, 'EUR' ); // '€9.800.900,32'
const JPY = currencyFormatter( 9800900.32, 'JPY' ); // '¥9,800,900'
const USD = formatCurrency( 9800900.32, 'USD' ); // '$9,800,900.32'
const EUR = formatCurrency( 9800900.32, 'EUR' ); // '€9.800.900,32'
const JPY = formatCurrency( 9800900.32, 'JPY' ); // '¥9,800,900'
```

Or

```javascript
import { getCurrencyObject } from 'lib/currency-formatter';
import { getCurrencyObject } from 'lib/format-currency';
const USD = getCurrencyObject( 9800900.32, 'USD' ); // { symbol: '$', integer: '9,800,900', fraction: '.32', sign: '' }

```
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -6,53 +6,53 @@ import { expect } from 'chai';
/**
* Internal dependencies
*/
import currencyFormatter, { getCurrencyDefaults, getCurrencyObject } from 'lib/currency-formatter';
import formatCurrency, { getCurrencyDefaults, getCurrencyObject } from 'lib/format-currency';

describe( 'currencyFormatter', () => {
describe( 'formatCurrency', () => {
it( 'formats a number to localized currency', () => {
const money = currencyFormatter( 99.32, 'USD' );
const money = formatCurrency( 99.32, 'USD' );
expect( money ).to.equal( '$99.32' );
} );
it( 'adds a localized thousands separator', () => {
const money = currencyFormatter( 9800900.32, 'USD' );
const money = formatCurrency( 9800900.32, 'USD' );
expect( money ).to.equal( '$9,800,900.32' );
} );
it( 'handles zero', () => {
const money = currencyFormatter( 0, 'USD' );
const money = formatCurrency( 0, 'USD' );
expect( money ).to.equal( '$0.00' );
} );
it( 'handles negative values', () => {
const money = currencyFormatter( -1234.56789, 'USD' );
const money = formatCurrency( -1234.56789, 'USD' );
expect( money ).to.equal( '-$1,234.57' );
} );
it( 'unknown currency codes return null', () => {
const money = currencyFormatter( 9800900.32, {} );
const money = formatCurrency( 9800900.32, {} );
expect( money ).to.equal( null );
} );

describe( 'supported currencies', () => {
it( 'USD', () => {
const money = currencyFormatter( 9800900.32, 'USD' );
const money = formatCurrency( 9800900.32, 'USD' );
expect( money ).to.equal( '$9,800,900.32' );
} );
it( 'AUD', () => {
const money = currencyFormatter( 9800900.32, 'AUD' );
const money = formatCurrency( 9800900.32, 'AUD' );
expect( money ).to.equal( 'A$9,800,900.32' );
} );
it( 'CAD', () => {
const money = currencyFormatter( 9800900.32, 'CAD' );
const money = formatCurrency( 9800900.32, 'CAD' );
expect( money ).to.equal( 'C$9,800,900.32' );
} );
it( 'EUR', () => {
const money = currencyFormatter( 9800900.32, 'EUR' );
const money = formatCurrency( 9800900.32, 'EUR' );
expect( money ).to.equal( '€9.800.900,32' );
} );
it( 'GBP', () => {
const money = currencyFormatter( 9800900.32, 'GBP' );
const money = formatCurrency( 9800900.32, 'GBP' );
expect( money ).to.equal( '£9,800,900.32' );
} );
it( 'JPY', () => {
const money = currencyFormatter( 9800900.32, 'JPY' );
const money = formatCurrency( 9800900.32, 'JPY' );
expect( money ).to.equal( '¥9,800,900' );
} );
} );
Expand Down
2 changes: 1 addition & 1 deletion client/my-sites/plan-features/price.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import React, { Component, PropTypes } from 'react';
/**
* Internal Dependencies
**/
import { getCurrencyObject } from 'lib/currency-formatter';
import { getCurrencyObject } from 'lib/format-currency';

export default class PlanFeaturesPrice extends Component {

Expand Down

0 comments on commit 96155c8

Please sign in to comment.