Giter Club home page Giter Club logo

babel-plugin-transform-currency-operators's Introduction

babel-plugin-transform-currency-operators Build Status Coverage Status npm

An experimental babel plugin for transforming currency.js operators.

Example

In

import currency from 'currency.js';

var currency1 = currency(1.23);
var currency2 = currency1 + 4.56;
var currency3 = currency2 - 4.56;
var currency4 = currency3 * 2;
var currency5 = currency4 / 4;
var currency6 = currency1 + currency2;

var MultiDecimal = value => currency(value, { decimals: 3 });
var currency7 = MultiDecimal(1.234) + 5.678;

if(currency1 < currency2) { ... }
if(currency1 > currency2) { ... }
if(currency1 === 1.23) { ... }

Out

import currency from 'currency.js';

var currency1 = currency(1.23);
var currency2 = currency1.add(4.56);
var currency3 = currency2.subtract(4.56);
var currency4 = currency3.multiply(2);
var currency5 = currency4.divide(4);
var currency6 = currency1.add(currency2);

var MultiDecimal = value => currency(value, { decimals: 3 });
var currency7 = MultiDecimal(1.234).add(5.678);

if(currency1.value < currency2.value) { ... }
if(currency1.value > currency2.value) { ... }
if(currency1.value === 1.23) { ... }

Installation

With npm:

npm install --save-dev babel-plugin-transform-currency-operators

With yarn:

yarn install babel-plugin-transform-currency-operators --dev

Usage

Via .babelrc (Recommended)

.babelrc

{
  "plugins": ["transform-currency-operators"]
}

Via CLI

babel --plugins transform-currency-operators

Via Node API

require("babel-core").transform("code", {
  plugins: ["transform-currency-operators"]
});

Advanced Usage

If you have a need to customize and export currency settings as a module, you can include the path to your currency (relative from the root of your project) in your .babelrc plugin configuration to transform those imported module's operator along with any currency.js imports:

File in your project: path/to/custom/currency.js

import currency from 'currency.js';

export default function myCustomCurrencyDefaults(value) {
  return currency(value, { symbol: '€', ...otherOptions });
}

.babelrc

{
  "plugins": ["transform-currency-operators", ['./path/to/custom/currency']]
}

License

MIT

babel-plugin-transform-currency-operators's People

Contributors

greenkeeper[bot] avatar jesobreira avatar scurker avatar

Watchers

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