node package manager
It’s your turn. Help us improve JavaScript. Take the 2017 JavaScript Ecosystem Survey »

accounting-helpers

accounting-helpers

Stache helpers for formatting money.

npm version

NPM

Installation

npm install accounting-helpers --save

Usage

Using CanJS's built-in support for StealJS, you can now import the module directly inside your templates. For example, assuming we have a variable amount which holds the value 2333.

<can-import from="accounting-helpers"/>
 
This will return 2,333.00:
{{formatMoney amount}}
 
This will return 23.33:
{{formatCents amount}}

The two examples above will include live binding. To opt out use the Unbound options, like this:

<can-import from="accounting-helpers"/>
 
This will return 2,333.00 without live binding:
{{formatMoneyUnbound amount}}
 
This will return 23.33 without live binding:
{{formatCentsUnbound amount}}

Use individual helpers in can-component

If you need to, you can import the helpers individually.

import Component from 'can-component';
import formatMoney from "accounting-helpers/format-money";
import formatMoneyUnbound from "accounting-helpers/format-money-unbound";
import formatCents from "accounting-helpers/format-cents";
import formatCentsUnbound from "accounting-helpers/format-cents-unbound";
 
Component.extend({
  tag: "hello-world",
  template: stache("{{formatMoney amount}}"),
  viewModel: {
    amount: 300,
  },
  helpers: {
    formatMoney,
    formatMoneyUnbound,
    formatCents,
    formatCentsUnbound
  }
});

Contributing

Pull requests are welcome. Analyze the code. See where it needs improvement, and let me know. Please, help make it better!

Changelog

  • 3.0.0 - CanJS 3.0 compatibility.
  • 1.0.0 - CanJS 2.3 compatibility.

Authors

Built with StealJS