• This repository has been archived on 15/May/2023
  • Stars
    star
    247
  • Rank 164,117 (Top 4 %)
  • Language
    TypeScript
  • License
    MIT License
  • Created over 7 years ago
  • Updated about 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

๐Ÿ’ Lightweight vue currency filter based on accounting.js

๐Ÿ’ Vue Currency Filter

Vue Currency Logo

Lightweight vue currency filter based on accounting.js

NPM Version Bundlephobia Size Bundlephobia Size Download All Time Travis Build All Contributors

Bundle Size

Demo

https://mazipan.github.io/vue-currency-filter/

Download

# NPM
npm install vue-currency-filter

# Yarn
yarn add vue-currency-filter

Sample Usage

Step by step to using vue-currency-filter:

Import in main.js

import VueCurrencyFilter from 'vue-currency-filter'

Use Plugins

Vue.use(VueCurrencyFilter)

Add Global Configuration

Vue.use(VueCurrencyFilter,
{
  symbol : '$',
  thousandsSeparator: '.',
  fractionCount: 2,
  fractionSeparator: ',',
  symbolPosition: 'front',
  symbolSpacing: true,
  avoidEmptyDecimals: undefined,
})

Add Multiple Instance

Vue.use(VueCurrencyFilter, [
 { // default name 'currency'
   symbol: '$',
   thousandsSeparator: ',',
   fractionCount: 2,
   fractionSeparator: '.',
   symbolPosition: 'front',
   symbolSpacing: true,
   avoidEmptyDecimals: '',
 },
 { // default name 'currency_2'
   name: 'currency_2',
   symbol: 'usd',
   thousandsSeparator: ' ',
   fractionCount: 2,
   fractionSeparator: '.',
   symbolPosition: 'front',
   symbolSpacing: false,
   avoidEmptyDecimals: '--',
 }
])

Use in View

<span>{{ 20000 | currency}}</span>

Usage in Nuxt.js

Add vue-currency-filter/nuxt to modules section of nuxt.config.js

{
  modules: [
    'vue-currency-filter/nuxt',

    // Or if you have custom options...
    ['vue-currency-filter/nuxt', {
      symbol: '$',
      thousandsSeparator: ',',
      fractionCount: 2,
      fractionSeparator: '.',
      symbolPosition: 'front',
      symbolSpacing: true,
      avoidEmptyDecimals: undefined,
    }],

    // for multiple instance
    ['vue-currency-filter/nuxt', [
      { // default name 'currency'
        symbol: '$',
        thousandsSeparator: ',',
        fractionCount: 2,
        fractionSeparator: '.',
        symbolPosition: 'front',
        symbolSpacing: true,
        avoidEmptyDecimals: '##',
      },
      { // default name 'currency_2'
        name: 'currency_2',
        symbol: 'usd',
        thousandsSeparator: ' ',
        fractionCount: 2,
        fractionSeparator: '.',
        symbolPosition: 'front',
        symbolSpacing: false,
        avoidEmptyDecimals: '',
      }
    ]],
  ]
}

or using external options

{
  modules: [
    'vue-currency-filter/nuxt'
  ]
  currencyFilter: [
    { // default name 'currency'
      symbol: '$',
      thousandsSeparator: ',',
      fractionCount: 2,
      fractionSeparator: '.',
      symbolPosition: 'front',
      symbolSpacing: true,
      avoidEmptyDecimals: '',
    },
    { // default name 'currency_2'
      name: 'currency_2',
      symbol: 'usd',
      thousandsSeparator: ' ',
      fractionCount: 2,
      fractionSeparator: '.',
      symbolPosition: 'front',
      symbolSpacing: false,
      avoidEmptyDecimals: '##',
    }
  ]
  // or for one filter
  currencyFilter: { // default name 'currency'
    symbol: '$',
    thousandsSeparator: ',',
    fractionCount: 2,
    fractionSeparator: '.',
    symbolPosition: 'front',
    symbolSpacing: true,
    avoidEmptyDecimals: undefined,
  }
}

Usage in Nuxt-typescript

you must add declaration for vue and nuxt context if you want autocomplete in methods create file vue-currency-filters.ts in directory with your types

import { CurrencyFilterMethodInstance } from "vue-currency-filter/src/types";

declare module 'vue/types/vue' {
  interface Vue {
    $currency: CurrencyFilterMethodInstance,
    $currency_2: CurrencyFilterMethodInstance
  }
}

declare module '@nuxt/types' {
  interface NuxtAppOptions {
    $currency: CurrencyFilterMethodInstance,
    $currency_2: CurrencyFilterMethodInstance
  }
}

Usage without NPM

Add script dependencies

<!-- Vue Dependency -->
<script src="https://cdn.jsdelivr.net/npm/vue"></script>
<script src="https://unpkg.com/vue-currency-filter"></script>

Use filters in global

if (VueCurrencyFilter) {
  Vue.use(VueCurrencyFilter, {
    symbol: "ยฃ",
    thousandsSeparator: ",",
    fractionCount: 0,
    fractionSeparator: ".",
    symbolPosition: "front",
    symbolSpacing: false,
    avoidEmptyDecimals: '',
  })
}

var app = new Vue({
  el: '#app',
  data: {
    curr: 1000
  }
});

See https://codepen.io/mazipan/pen/YdmNMy for code sample.

Add Configuration In Specific Place

<span>
{{ textInput | currency(configSymbol, configSeparator, configFractionCount,
configFractionSeparator, configSymbolPosition, configSymbolSpacing)}}
</span>

Now configurations is also available as Object, thanks to sunhengzhe in PR #25:

<span>
{{ textInput | currency({
  symbol: '',
  thousandsSeparator: '',
  fractionCount: '',
  fractionSeparator: '',
  symbolPosition: '',
  symbolSpacing: '',
  avoidEmptyDecimals: undefined,
})}}
</span>

Available Options

{
  name: 'string (default: currency)', // using for multiple instance filters
  symbol: 'string (default : empty string)',
  thousandsSeparator: 'string (default : .)',
  fractionCount: 'number (default : 0)',
  fractionSeparator: 'string (default: ",")',
  symbolPosition: 'string (default: front)',
  symbolSpacing: 'boolean (default: true)',
  avoidEmptyDecimals: 'string (default: undefined)',
}

How to test in Unit Test

Using @vue/test-utils we can create test for any Vue Plugins, like:

/* eslint-env jest */
import { shallowMount, createLocalVue } from "@vue/test-utils";
import VueCurrencyFilter from "vue-currency-filter";

import Component from "../pages/myComponent.vue";

describe("test myComponent", () => {
  it("vue-currency-filter should working correctly", () => {
    const localVue = createLocalVue();
    
    localVue.use(VueCurrencyFilter, {
      symbol: "$",
      thousandsSeparator: ",",
      fractionCount: 2,
      fractionSeparator: ".",
      symbolPosition: "front",
      symbolSpacing: true,
      avoidEmptyDecimals: undefined,
    });

    let wrapper = shallowMount(Component, {
      localVue
    });

    const result = wrapper.find(".curr");
    expect(result.text()).toEqual("$ 1,000.00");
    
    localVue.use(VueCurrencyFilter, {
      symbol: "$",
      thousandsSeparator: ",",
      fractionCount: 2,
      fractionSeparator: ".",
      symbolPosition: "front",
      symbolSpacing: true,
      avoidEmptyDecimals: '',
    });

    wrapper = shallowMount(Component, {
      localVue
    });

    const result = wrapper.find(".curr");
    expect(result.text()).toEqual("$ 1,000");
    
    localVue.use(VueCurrencyFilter, {
      symbol: "$",
      thousandsSeparator: ",",
      fractionCount: 2,
      fractionSeparator: ".",
      symbolPosition: "front",
      symbolSpacing: true,
      avoidEmptyDecimals: '##',
    });

    wrapper = shallowMount(Component, {
      localVue
    });

    const result = wrapper.find(".curr");
    expect(result.text()).toEqual("$ 1,000.##");
  });
});

See sample test here: https://codesandbox.io/s/6xk1mv694n

Contributing

If you'd like to contribute, head to the contributing guidelines. Inside you'll find directions for opening issues, coding standards, and notes on development.

Credits

  • Vue for amazing framework
  • Jetbrain for amazing support with free license for WebStorm IDE
  • @iqbalhood as logo creator (see #19)

Support me

Hope this will be useful for you all

Copyright ยฉ 2017 Built with โค๏ธ by Irfan Maulana

Contributors

Thanks goes to these wonderful people (emoji key):


Irfan Maulana

๐Ÿ’ป

iqbalhood

๐ŸŽจ

ๅญ™ๆ’ๅ“ฒ

๐Ÿ’ป

Ricardo Gobbo de Souza

๐Ÿ’ป

Yashodhan Singh Rathore

๐Ÿ’ป

Gijs Rogรฉ

๐Ÿ’ป

Ivan Sysa

๐Ÿ’ป

Nicola Cordioli

๐Ÿ’ป

This project follows the all-contributors specification. Contributions of any kind welcome!

More Repositories

1

hello-open-source

๐Ÿ–๏ธ A repository to learn about open source code contributions flow
JavaScript
586
star
2

bulma-admin-dashboard-template

๐Ÿ Free admin dashboard template with bulma css
EJS
390
star
3

baca-quran.id

๐Ÿ“– Read Qur'an from Your Web Browser. No Ads, No Analytics, It's Totally Free.
TypeScript
385
star
4

auto-commit

๐ŸŒณ Making green your Github stats, powered by Github Actions
301
star
5

vue-google-adsense

๐Ÿ’ฐ Vue.js Google Adsense Component with InFeed and InArticle Ads support
Vue
257
star
6

vue2-simplert

โš ๏ธ Vue 2 Simple Alert Component (SweetAlert Inspired)
JavaScript
214
star
7

ksana.in

โœ‚๏ธ Layanan pemendek tautan yang mudah, gratis & tanpa iklan
TypeScript
201
star
8

graphql-pokeapi

๐Ÿ”ด The Unofficial GraphQL for PokeAPI
JavaScript
175
star
9

login-page-css

๐Ÿ” An Open Source Template for Login Page From Scratch Without Any CSS Framework
HTML
171
star
10

vue-select-image

โœ… Vue 2.x component for selecting image from list
JavaScript
145
star
11

tanyaaja.in

โ“Kumpulkan pertanyaan secara anonim dari siapa saja dengan mudah
TypeScript
132
star
12

nuxt-storage

๐Ÿ›ข Utilities for easy read and write browser's storage in Nuxt.js project
TypeScript
126
star
13

bulma-resume-template

๐Ÿ’ผ Free resume page template with bulma css
EJS
108
star
14

mazipan.space

๐Ÿ‘ฟ Codebase for mazipan.space. Next.js x Tailwind
JavaScript
98
star
15

pramuka-id

๐ŸŒด Kumpulan informasi digital mengenai berbagai materi pramuka, materi kenegaraan dan materi kecakapan umum
TypeScript
98
star
16

vue-ionicons

โ›„๏ธ Vue Icon Set Components from Ionic Team
CSS
96
star
17

awesome-js-dev-id

๐Ÿ˜Ž Daftar para developer/programmer javascript terkece asal Indonesia
93
star
18

vue-tiny-lazyload-img

๐ŸŒ A small size Vue.js directive for lazy loading images using IntersectionObserver API
JavaScript
92
star
19

psi-gh-action

๐Ÿฏ Github Action to generate web performance report for JAMStack using PageSpeedInsight
JavaScript
77
star
20

awesome-sde-id-medium

๐Ÿ˜Ž Daftar akun Medium.com keren dari para pegiat software engineering di Indonesia
JavaScript
76
star
21

bem-kit

๐Ÿ’„ CSS UI kit with BEM convention and SASS
SCSS
68
star
22

explore-github

๐Ÿ™๐Ÿ” VueJS 2 Github Explorer Using API v3
Vue
56
star
23

webperf-ecommerce-id

โšก๏ธ Web Perf Comparison for E-Commerce in Indonesia
TypeScript
40
star
24

cors-hijacker

๐Ÿ’€ A bare-minimum solution to solve CORS problem via proxy API
TypeScript
39
star
25

ebook-belajar-frontend

WIP - ๐Ÿ“š Buku panduan untuk menyelami dunia pengembangan antarmuka website
JavaScript
39
star
26

vue-string-filter

โœ‚๏ธ Vue 2.x lightweight string manipulation filter
TypeScript
38
star
27

modernize-landing-page

How to creating landing page in modern frontend stack
HTML
36
star
28

blog-2.0

๐Ÿ—ฃ A personal blog by Irfan Maulana built with Nuxt.js
Vue
32
star
29

milligram-admin-dashboard-template

๐Ÿ’ฆ Admin dashboard template built with milligram css
HTML
31
star
30

vue2-simplert-plugin

โš ๏ธ Vue 2 Simple Alert Plugin (SweetAlert Inspired)
Vue
30
star
31

nodejs-simple-restfull-with-express

โšก ExpressJS Rest API Sample
JavaScript
30
star
32

vue-doughnut-chart

๐Ÿฉ Doughnut chart component for Vue.js, originally created by Greg Willson
Vue
29
star
33

bulma-dracula

๐Ÿ˜ˆ Bulma css with Dracula dark color themes
HTML
25
star
34

bootstrap4-admin-dashboard-template

๐Ÿ…ฑ๏ธ Bootstrap 4 admin dashboard template
HTML
25
star
35

react-testing-workshop

Code sample for showcasing basic React Testing Library
TypeScript
25
star
36

vue-wwwid

๐Ÿข๏ธ๏ธ๏ธ PWA with Vue + Workbox for WWWID RSS Feed
JavaScript
23
star
37

RumahSakitJakarta

๐Ÿฅ Daftar Rumah Sakit Umum, Khusus dan Puskesmas di Jakarta
Vue
22
star
38

react-simplert

NOT MAINTAINED โš ๏ธ ReactJS Simple Alert Component (SweetAlert Inspired)
JavaScript
22
star
39

talks

๐ŸŽ™๏ธPublic talks by @mazipan
JavaScript
20
star
40

chucknorris

๐Ÿ‹๏ธ Chuck Norris Jokes Generator
Vue
20
star
41

ghibli-fans

๐Ÿฐ Browse film, character, etc from Ghibli Studio
JavaScript
19
star
42

workbox-in-js-framework

๐Ÿณ Code sample for using Workbox in various JS framework
JavaScript
17
star
43

react-workshop

โš›๏ธ A workshop to get started with React
JavaScript
17
star
44

lightweight-admin-template

๐Ÿš€ Lightweight admin template for your web application
HTML
16
star
45

gdk-mws-2018-participants-code

๐ŸŽฅ Dokumentasi kode untuk Google Developer Kejar - Mobile Web Specialist 2018
HTML
16
star
46

eslint-formatter-html-extended

๐ŸŒน Beautiful ESLint HTML formatter extended from ESLint's official HTML formatter by JulianLaval combined with Stylish by Sindre Sorhus
HTML
14
star
47

ghibli-api

๐Ÿ‘ฝ The Unofficial Ghibli Studio API
TypeScript
14
star
48

webperf-psi

๐Ÿš€ Easy to use, PSI API hit using Node.js to collect Web Performance Metrics
JavaScript
13
star
49

nuxt-blog

๐Ÿ“ Personal blog built with Nuxt.js and wordpress rest api
Vue
13
star
50

project-catalog

๐ŸŽ List of all Irfan Maulana's open source project and library
JavaScript
13
star
51

FireJak

๐Ÿš’ Aplikasi Daftar Pos Pemadam Kebakaran di Jakarta
Vue
13
star
52

bumi-langit-scrapper

Scrapper website bumilangit.com
JavaScript
12
star
53

visit-me

๐Ÿ– Visit your web page easier using CLI, powered by Puppeteer and Node-Fetch
JavaScript
12
star
54

ghibli-reasonreact

๐Ÿ‘ป Ghibli studios's film explorer built with ReasonReact
Reason
12
star
55

papercss-admin-dashboard-template

๐Ÿ“œ Free admin dashboard template built with PaperCSS
HTML
12
star
56

vue-complexify

๐Ÿ‘ฎ Vuejs porting library from jquery.complexify.js
HTML
12
star
57

sample-swagger-for-nodejs

๐Ÿ“š Sample of using swagger.io with Nodejs
JavaScript
12
star
58

journey-to-the-frontend-world

๐ŸŒ Introduction Frontend Stack
HTML
11
star
59

gridsome-blog

Blog with gridsome
Vue
11
star
60

cek-halal

๐Ÿ”โ“ Cek produk halal berdasarkan sertifikat dari MUI
JavaScript
11
star
61

vue-offcanvas-menu

๐Ÿ’ƒ Showing off-canvas menu effects stylishly with Vue.js
JavaScript
10
star
62

nodejs-jakarta-api

Node.js wrapper for JakGo API (api.jakarta.go.id)
TypeScript
10
star
63

testing-vuenuxt-playground

๐ŸŒป Playground for setup example and get in action with Unit Test on Nuxt, Vue 2 and Vue 3
JavaScript
9
star
64

ng2-starwars

๐ŸŒŸ Star Wars API Implementation in Angular2
TypeScript
8
star
65

ghibli-svelte

๐Ÿ‘ป Ghibli studios's film explorer built with Svelte
CSS
7
star
66

ng2-simplert

โš ๐Ÿ…ฐ Angular 2 Simple Alert Component (SweetAlert Inspired)
TypeScript
7
star
67

mazipan

๐Ÿง™โ€โ™€๏ธ A magic readme ๐ŸŒŸ
7
star
68

webpack-training

๐Ÿคผโ€โ™‚๏ธ A webpack training repository
JavaScript
7
star
69

akamai-image-converter

๐Ÿž Simple javascript util for Akamai image converter
JavaScript
7
star
70

museum-indonesia

Open source web apps for browse Museum in Indonesia
Vue
7
star
71

angularjs-basic-tutorial

โ„๏ธ Angularjs v.1.x Basic Tutorial
HTML
7
star
72

personal-nextjs-starter

โ‡๏ธ My personal Next.js starter for future projects
TypeScript
6
star
73

vue-webpack-sample

๐Ÿฃ Sample initialize Vue.js project using Vue-CLI webpack template
Vue
6
star
74

awesome-vue-list

๐Ÿ˜Ž A curated list of awesome things related to Vue.js based on awesome-vue repository
JavaScript
6
star
75

gdk-mws-2018-challenge-01-ghibli-studio

๐Ÿ‘พ Google Developer Kejar Mobile Web Specialist 2018 - Challenge 01 - Playing with Ghibli Studio Public API
JavaScript
6
star
76

awesome-bemcss

Renamed to bem-kit
CSS
6
star
77

awesome-sde-id-blogs

Daftar blog keren dari para pegiat software engineering di Indonesia
5
star
78

angular-wwwid

๐Ÿ…ฐ๏ธ Angular PWA WWWID RSS Reader
TypeScript
5
star
79

learn-php-oop-like-java

Sample of Object Oriented Programming in PHP Language that influenced from Java
PHP
5
star
80

node-playground

A personal Node.js playground
JavaScript
5
star
81

phpid-uxd-landingpage-prototype

PHP Indonesia UXD Landing Page Prototype
HTML
5
star
82

vue-cli-sample

Project created with Vue-CLI 3
Vue
5
star
83

preact-script2

Preact component for insert <script> tag, inspired by vue-script2
JavaScript
5
star
84

simple-ampify

โšก A simple plain HTML to AMP converter for personal use
HTML
5
star
85

lighthouse-behind-auth

๐Ÿ™ˆ Codelab for running Lighthouse to test a page behind authentication flow
HTML
5
star
86

wibu

โ›ฉ Anime explorer, using data from AniList
TypeScript
5
star
87

how-to-call-api-in-nodejs

โ“ How to make an API call in Node.js
JavaScript
4
star
88

pengenalan-vuejs-dasar

๐Ÿ“– Repository pengenalan framework Vue.js dasar dalam bahasa Indonesia
4
star
89

medium-stories

๐Ÿ’ผ HTML files of Medium.com stories that I have published
HTML
4
star
90

blog-comments

๐Ÿ’ฌ Blog comment repository for mazipan.space, powered by utteranc.es
4
star
91

pkmn-catcher

๐Ÿ‘พ Just Another Pokรจmon Catcher, based on PokeAPI v2
TypeScript
3
star
92

workshop-delightful-web

Repository for workshop "Create a delightful web with good DX"
JavaScript
3
star
93

discussions

๐Ÿคผ Open discussions with @mazipan
3
star
94

Syamil-AlKhawarizmi

Hello world from Syamil Al-Khawarizmi
JavaScript
3
star
95

mazipan.github.io

๐Ÿ“บ A github page for mazipan.github.io
SCSS
2
star
96

setup-vue-without-vue-cli

How to create skeleton project in Vue.js from basic without Vue-CLI
JavaScript
2
star
97

JavaSwing-SimpleApplicationDesktopTemplate

๐Ÿ’ป Basic Template for Desktop Application Window with Java Swing
Java
2
star
98

Java-SwingCustomComponent

Advance Custom Component for Java Swing
Java
2
star
99

Java-PerpustakaanOnline

๐Ÿ“˜ Sample of JavaEE using servlet
Java
2
star
100

blogs

๐Ÿš Markdown content from mazipanneh.com/blog/
CSS
2
star