vue-numeral-filter
Version:
Vue.js filter for Numeral.js
63 lines (45 loc) • 3.23 kB
Markdown
# vue-numeral-filter
[](https://badge.fury.io/js/vue-numeral-filter)
[](https://madewithvuejs.com/p/vue-js-filter-for-numeral-js/shield-link)
[](https://www.jsdelivr.com/package/npm/vue-numeral-filter)
[](https://github.com/facebook/jest)
[](https://opensource.org/licenses/MIT)
Vue.js filter for Numeral.js
Allows for [Numeral.js](http://numeraljs.com/) to be used inline in the template section of a component. This can be a convenient way of rendering numerically formatted data in situations where you do not wish to create a computed property.
## Demonstration
https://jsfiddle.net/lloydjatkinson/uaq69zjc/
## Installation
### NPM
*This is the recommended approach.*
```
npm install vue-numeral-filter
```
```js
import vueNumeralFilterInstaller from 'vue-numeral-filter';
Vue.use(vueNumeralFilterInstaller, { locale: 'en-gb' });
```
### CDN - Browser UMD Module
The UMD bundle will automatically install the filters.
```html
<script src="https://cdn.jsdelivr.net/npm/vue-numeral-filter/dist/vue-numeral-filter.min.js"></script>
```
### Usage
The `numeral` filter accepts any of the formats specified in the [Numeral.js](http://numeraljs.com/) documentation. For example:
```html
{{ 561739482 | numeral('0,0') }} // => 561,739,482
```
### Predefined Filters
A number of commonly used predefined filters are also provided for ease-of-use and readability.
| Type | Numeral | Alias | Result |
|---------------------|-------------------------------------------|----------------------------------|-------------|
| Bytes | <code>{{ 10485760 | numeral('0b') }}</code> | <code>{{ 10485760 | bytes }}</code> | 10 MB |
| Percentage | <code>{{ 0.5567 | numeral('0.[00]%') }}</code> | <code>{{ 0.5567 | percentage }}</code> | 55.67% |
| Thousands Separator | <code>{{ 561739482 | numeral('0,0') }}</code> | <code>{{ 561739482 | separator }}</code> | 561,739,482 |
| Ordinal | <code>{{ 20 | numeral('Oo') }}</code> | <code>{{ 20 | ordinal }}</code> | 20th |
| Abbreviate | <code>{{ 1000000 | numeral('0.0a') }}</code> | <code>{{ 1000000 | abbreviate }}</code> | 1.0m |
| Exponential | <code>{{ 123987.202 | numeral('0.[00]e+0') }}</code> | <code>{{ 123987.202 | exponential }}</code> | 1.24e+5 |
|Currency| <code>{{ 200.42 | numeral('$0,0.00') }}</code>|<code>{{ 200.42 | currency }}</code>|£200.42|
### Locales
See the list of locales here: https://github.com/adamwdraper/Numeral-js/tree/master/src/locales
### Find this library useful?
[](https://ko-fi.com/K3K71ND3U)