Skip to content

Commit

Permalink
Simplify and standardize named exports
Browse files Browse the repository at this point in the history
  • Loading branch information
Kristofer Selbekk committed Apr 27, 2017
1 parent 1b4c8b5 commit c8cae0d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 14 deletions.
21 changes: 14 additions & 7 deletions src/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,19 @@ This document will document all formatters, how to use them and what to
expect when invoking them. For more detailed documentation, please visit
the relevant tests, as they provide more information on edge case behavior.

### `account-number(accNumber)`
### `formatAccountNumber(accNumber)`

Formats an account number to the correct format separated with non breaking
space characters.

```javascript
import formatAccountNumber from 'ffe-formatters/account-number';
import { formatAccountNumber } from 'ffe-formatters';

formatAccountNumber('90010012345') === '9001 00 12345'
```

### `amount(number [, options])`
### `formatAmount(number [, options])`

Formats an amount with the correct prefix, postfix and decimals, all
separated by non breaking space characters.
Expand All @@ -31,51 +32,55 @@ The function accepts an optional second `options`-object, with two keys:

```javascript
import formatAmount from 'ffe-formatters/amount';
import { formatAmount } from 'ffe-formatters';

formatAmount(1000) === 'kr. 1 000,-'
formatAmount(13.37) === 'kr. 13,37'
formatAmount(1000, { prefix: '', postfix: 'kroner'}) === '1 000,- kroner'
```

### `date(timestamp)`
### `formatDate(timestamp)`

Formats timestamps, `Date`-objects and `moment` instances to the correct
format.

```javascript
import formatDate from 'ffe-formatters/date';
import { formatDate } from 'ffe-formatters';

formatDate(new Date('2000', 0, 1)) === '01.01.2000'
formatDate(moment('20000101')) === '01.01.2000'
formatDate(946681200000) === '01.01.2000'
```

### `km(distance)`
### `formatKm(distance)`

Formats distances in kilometers in the correct format with non breaking
space characters.

```javascript
import formatKm from 'ffe-formatters/km';
import { formatKm } from 'ffe-formatters';

formatKm(160520) === '160 520 km'
```

### `number(num [, decimals = 0])`
### `formatNumber(num [, decimals = 0])`

Formats numbers to the correct format separated with non breaking
space characters. Ignores decimals by default, but accepts the
number for decimals as a second argument.

```javascript
import formatNumber from 'ffe-formatters/number';
import { formatNumber } from 'ffe-formatters/number';

formatNumber(1000000) === '1 000 000'
formatNumber(1234.567) === '1 234'
formatNumber(1234.567, 2) === '1 234,56'
```

### `percentage(num [, maxDecimals = 2])`
### `formatPercentage(num [, maxDecimals = 2])`

Formats percentages to the correct format separated with non breaking
space characters. Returns as few decimals as possible. By default there's
Expand All @@ -84,19 +89,21 @@ optional argument if needed.

```javascript
import formatPercentage from 'ffe-formatters/percentage';
import { formatPercentage } from 'ffe-formatters';

formatPercentage(0.10) === '10 %';
formatPercentage(0.123456) === '12.35 %' // rounds the overflowing decimals
formatPercentage(0.123456, 4) === '12.3456'
```

### `ssn(fødselsnummer)`
### `formatSsn(fødselsnummer)`

Formats a Norwegian SSN (fødselsnummer) to the correct format separated with
non breaking space characters.

```javascript
import formatSsn from 'ffe-formatters/ssn';
import { formatSsn } from 'ffe-formatters';

formatSsn('01010112345') === '010101 12345'
```
14 changes: 7 additions & 7 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export { default as accountNumber } from './account-number';
export { default as amount } from './amount';
export { default as date } from './date';
export { default as km } from './km';
export { default as number } from './number';
export { default as percentage } from './percentage';
export { default as ssn } from './ssn';
export { default as formatAccountNumber } from './account-number';
export { default as formatAmount } from './amount';
export { default as formatDate } from './date';
export { default as formatKm } from './km';
export { default as formatNumber } from './number';
export { default as formatPercentage } from './percentage';
export { default as formatSsn } from './ssn';

0 comments on commit c8cae0d

Please sign in to comment.