Coder Social home page Coder Social logo

trendingtechnology / vue-currency-directive Goto Github PK

View Code? Open in Web Editor NEW

This project forked from mahmoudzakaria90/vue-currency-directive

0.0 2.0 0.0 236 KB

Vuejs custom directive v-currency

Home Page: https://www.npmjs.com/package/vue-currency-directive

License: MIT License

JavaScript 100.00%

vue-currency-directive's Introduction

Vue-currency-directive

Simple, quick custom directive for handling currency format inside text inputs.

Build Status Version Downloads License

Compatible with Vue 2.x

Installation

npm i vue-currency-directive || yarn add vue-currency-directive

Usage

  • Register in your data() a main state object e.g. amount and inside it 2 main properties value and formatted.
  • You mainly get 2 outputs: one for the unformatted/original value and the other for the formatted value.

In DOM/Single-file-component

<input v-currency:<currency?>[<locale?>]="<bindingExpression>">

For example:

<template>
  <input v-currency="amount.value">
  <input v-currency="foo.value">
  <input v-currency="bar.value">
</template>

<script>
...
export default {
  data(){
    return {
      amount: { // naming is not strict 'amount, foo, bar, ...etc'
        value: '', 
        formatted: ''
      }, 

      foo: {
        value: '',
        formatted: ''
      },

      bar: {
        value: '',
        formatted: ''
      }
    }
  }
}
...
<script>

Global registration

import Vue from 'vue';
import vueCurrencyDirective from 'vue-currency-directive';

Vue.directive('currency', vueCurrencyDirective);

Local registration

<script>
import vueCurrencyDirective from 'vue-currency-directive';
export default {
  ...
  data(){
    amount: {
      value: '', 
      formatted: ''
    }, 
  },
  directives: {
    currency: vueCurrencyDirective
  },
  ...
}
</script>

Examples

Passing no arguments will reflect to "USD" currency by default and for locale it will use the configured browser language.

<input v-currency="amount.value"> // amount.value = 3244
//Output: $3,244.00

Passing currency argument only without locale.

<input v-currency:EUR="amount.value"> // amount.value = 100234
//Output: €100,234.00

Passing with locale argument and different currency.

<input v-currency:EGP[ar-EG]="amount.value"> // amount.value = 554342
//Output: ٥٥٤٬٣٤٢٫٠٠ ج.م.‏ 

vue-currency-directive's People

Contributors

mahmoudzakaria90 avatar

Watchers

 avatar  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.