Code Monkey home page Code Monkey logo

vue-numeral-filter's Introduction

vue-numeral-filter

npm version tested with jest License: MIT

Vue.js filter for Numeral.js

https://github.com/lloydjatkinson/vue-numeral-filter/

Allows for Numeral.js 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
import vueNumeralFilterInstaller from 'vue-numeral-filter';

Vue.use(vueNumeralFilterInstaller);

CDN - Browser UMD Module

The UMD bundle will automatically install the filters.

<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 documentation. For example:

{{ 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 {{ 10485760 | numeral('0b') }} {{ 10485760 | bytes }} 10 MB
Percentage {{ 0.5567 | numeral('0.[00]%') }} {{ 0.5567 | percentage }} 55.67%
Thousands Separator {{ 561739482 | numeral('0,0') }} {{ 561739482 | separator }} 561,739,482
Ordinal {{ 20 | numeral('Oo') }} {{ 20 | ordinal }} 20th
Abbreviate {{ 1000000 | numeral('0.0a') }} {{ 1000000 | abbreviate }} 1.0m
Exponential {{ 123987.202 | numeral('0.[00]e+0') }} {{ 123987.202 | exponential }} 1.24e+5

vue-numeral-filter's People

Contributors

lloydjatkinson avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.