Giter VIP home page Giter VIP logo

ember-cli-accounting's Introduction

Ember-cli-accounting travis-badge

This is a port of the great accounting.js library to ES6 modules that integrates seamlessly with ember-cli.

Installation

Just add like any other ember-cli addon:

  • ember install ember-cli-accounting

Ember compatiblity

Version 1.0.0 and beyond use Ember.Helper and helper's autoregistration, and are only compatible with Ember 1.13 and Ember 2.0+

Version 0.1.X requires HTMLBars, to works with ember 1.10+, including 1.13, but not with Ember 2.0

If you are in an older than 1.10 use version 0.0.4

Usage

Accounting functions

You no longer need to access the global accounting, you can import only what you need:

import formatMoney from "accounting/format-money"

Although you can import everything as expected:

import accounting from "accounting"

Handlebars helpers

This addon also registers 2 handy helpers in your application: format-number and format-money.

You can set options using bound or unbound options like this:

{{format-money price symbol=selectedCurrency format="%v %s"}} <!-- "123.45 £" -->

Any option not set will have the usual default value:

{{format-number "1234.567" precision=2}} <!-- "1,234.57" -->

Config default options

You can use an initializer to set some default values at initializations and avoid having to repeat over and over the options in the helpers.

Use something like this:

// app/initializers/accounting.js
import { currency, number } from "accounting/settings";

export default {
  name: 'accounting.js',
  initialize: function() {
    currency.symbol = "€";
    number.decimal = ",";
    number.thousand = ".";
  }
};

Differences with accounting.js

Although this is almost a 1:1 port of accountant.js, there is a few differences:

  • Each function of accountant.js lives in its own module, so you can only import those functions you want to use.
  • Removed some polyfills for Array.isArray, Array.prototype.map and Object.prototype.toString. They are not required in modern browsers, and ember.js (unless you opt-out with EXTEND_PROTOTYPES = false) already provides polyfills for those functions.
  • More tests than the original.
  • Enforced jshint. Cleaner code.

Versioning

At the time of writting, this addon bundles the same funcionality than accounting version 0.4.1. This addon's version don't match accounting's version. However, you can check accounting's version easily:

import version from "accounting/version";

console.log(version) // => "0.4.1"

I'll try to keep it always up to date with any bugfix or new feature in the original library.

Documentation

This library does not make any change in the public api of accounting.js, so you can read the official documentation here

ember-cli-accounting's People

Contributors

aaronrenner avatar alexdiliberto avatar bradleypriest avatar cibernox avatar colenso avatar leonardobugoni avatar michaelvdheeren avatar milindalvares avatar pankaj-awake avatar pswai avatar robbiethewagner avatar scottkidder avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

ember-cli-accounting's Issues

Currency convert to symbol

Ok, unless I am misunderstanding, I would think I could pass in USD and it would return me the symbol. But its not

formatMoney(this.get('model.service.price.priceRange.min'), {
      symbol: this.get('model.service.price.currency'),
      precision: 2,
      thousand: "·",
      format: {
        pos: "%s %v",
        zero: "%s  --"
      }
    });```

Thoughts?

Release a new tag version with the updated babel version

The PR #41 upgraded the babel version which is done to resolve the Ember Global usage deprecation warning, which block upgrading to Ember 4. But the last tag as of today (2.0.2) doesn't include this change, so the only option is to point directly to the master branch...

Babel compile error: accounting/utils.js: unknown node of type undefined with constructor "Function"

My project's vitals:

  • Ember 2.11
  • Ember Data 2.11
  • Ember CLI 2.11
  • Node: 6.9.2

If I run "ember install ember-cli-accounting" and then "ember serve", I get this error:

Livereload server on http://localhost:49152
Serving on http://localhost:4200/
File: accounting/utils.js
The Broccoli Plugin: [broccoli-persistent-filter:Babel] failed with:
ReferenceError: accounting/utils.js: unknown node of type undefined with constructor "Function"
    at CodeGenerator.print (.../node_modules/babel-core/lib/generation/index.js:274:13)
    at NodePrinter.plain (.../node_modules/babel-core/lib/generation/node/printer.js:37:27)
    at CodeGenerator.MemberExpression (.../node_modules/babel-core/lib/generation/generators/expressions.js:324:9)
    at CodeGenerator.print (.../node_modules/babel-core/lib/generation/index.js:289:20)
    at NodePrinter.plain (.../node_modules/babel-core/lib/generation/node/printer.js:37:27)
    at CodeGenerator.CallExpression (.../node_modules/babel-core/lib/generation/generators/expressions.js:182:9)
    at CodeGenerator.print (.../node_modules/babel-core/lib/generation/index.js:289:20)
    at NodePrinter.plain (.../node_modules/babel-core/lib/generation/node/printer.js:37:27)
    at CodeGenerator.AssignmentExpression (.../node_modules/babel-core/lib/generation/generators/expressions.js:277:9)
    at CodeGenerator.print (.../node_modules/babel-core/lib/generation/index.js:289:20)

The broccoli plugin was instantiated at: 
    at Babel.Plugin (.../node_modules/broccoli-plugin/index.js:7:31)
    at Babel.Filter [as constructor] (.../node_modules/broccoli-persistent-filter/index.js:62:10)
    at new Babel (.../node_modules/broccoli-babel-transpiler/index.js:35:10)
    at EmberApp._addonTree (.../node_modules/ember-cli/lib/broccoli/ember-app.js:940:29)
    at EmberApp._processedVendorTree (.../node_modules/ember-cli/lib/broccoli/ember-app.js:974:20)
    at EmberApp._processedExternalTree (.../node_modules/ember-cli/lib/broccoli/ember-app.js:1005:21)
    at EmberApp.appAndDependencies (.../node_modules/ember-cli/lib/broccoli/ember-app.js:1114:30)
    at EmberApp.javascript .../node_modules/ember-cli/lib/broccoli/ember-app.js:1244:34)
    at EmberApp.toArray (.../node_modules/ember-cli/lib/broccoli/ember-app.js:1674:10)
    at EmberApp.toTree (.../node_modules/ember-cli/lib/broccoli/ember-app.js:1696:30)

However, when I add it to a newly-created project with the same specs, it works fine. I haven't figured out what's different about my project than a newly-created project. Any ideas on how to investigate this?

It's worth noting that using the standard accounting.js and my own vendor shim works fine.

Define global options

It would be nice to have a way to define global options, so it's possible to use a helper multiple times without passing the same attributes multiple times.

HTMLBars helper registration deprecation

Using Ember.HTMLBars.makeBoundHelper is deprecated. Please refactor to using Ember.Helper or Ember.Helper.helper. [deprecation id: ember-htmlbars.make-bound-helper]

Format Money incorrectly formats negative values

Typically when writing a money value in USD that is negative (I'm not sure about other currencies), one would write "-$100,00.23" however this library does not allow for the detailed formatting necessary for this to work. While one could provide the ordering for "%v" value and "%s" symbol, there is no way to specify where the sign should go.

For now, I have worked around this by using a combination of this library with the ember-math-helpers.

{{if (lt value 0) '-'}}{{format-money (abs value) precision=2}}

$0 rendered as $--

Is there a way to use format-money and have $0 render as $0 ad not $--?

Thanks!

Custom settings for formatNumber don't work.

I do this before usage of accounting.formatNumber():

accounting.settings.number = {
      grouping: 3,
      thousand: ',',
      decimal: '.',
      precision: 4
    },;

but it doesn't affect the result.
I think issue is here:

import { number } from "./settings";
var numberSettings = number;
  var opts = defaults(
      (isObject(precision) ? precision : {
        precision : precision,
        thousand : thousand,
        decimal : decimal
      }),
      numberSettings
    );

Creating additional pointer here breaks the connection.

mention breaking changes in readme file

A lot of people don't use HtmlBars yet and it causes confusion as to why the addon is throwing errors. I think it should clearly be mentioned on the readme file that if you are not on the latest ember you must pull in the '0.0.4' version of the addon. I was about to uninstall the addon but i was lucky to take a look at changelog at the very last minute.

Uncaught TypeError: Cannot read property 'helper' of undefined

I get the above error when I try to use format-money model.unpaid symbol='$' in a template

the relevant code from the browser:

define('accounting/helpers/format-money', ['exports', 'accounting/format-money', 'ember'], function (exports, formatMoney, Ember) {

  'use strict';

  exports['default'] = Ember['default'].Helper.helper(function (params, options) {
    var value = params[0];
    return formatMoney['default'](value, options);
  });

});

I'm new to ember, so I don't know exactly what would cause that.

Format inconsistencies between string and number inputs

Hi Milind - many thanks for this great addon which has been very useful to us in our app!

I discovered an inconsistency in the way that this addon parses string values vs number values. Given the following config:

  // app/initializers/accounting.js
  import { currency, number } from 'accounting/settings'

  export default {
    name: 'accounting.js',
    initialize: function() {
      currency.symbol = '$'
      currency.format = {
        pos: '%v %s',
        neg: '-%v %s',
        zero: '%v %s'
      }
      currency.decimal = ','
      currency.thousand = ' '
      number.decimal = ','
      number.thousand = ' '
      currency.precision = 0
    }
  }

The output of {{format-money "43.7" precision=2}} is: 437.00, while the output of {{format-money 43.7 precision=2}} is 43.70

I've observed the same issue with format-number.

The issue is NOT present with the following config:

      currency.symbol = '$'
      currency.format = {
        pos: '%s%v',
        neg: '-%s%v',
        zero: '%s%v',
      }
      currency.decimal = '.'
      currency.thousand = ','
      number.decimal = '.'
      number.thousand = ','

typed-ember included in 2.0.0 revision of package

This is a weird one...

Repro

  1. Download [email protected] directly from the yarn registry via wget https://registry.yarnpkg.com/ember-cli-accounting/-/ember-cli-accounting-2.0.0.tgz
  2. tar xvf ember-cli-accounting-2.0.0.tgz
  3. cd package

There should be a typings/ember folder
As best as I can tell, the typings included are from https://github.com/wagenet/typed-ember, but they aren't part of the git sourcetree for this addon.

While my instructions above use yarn, the bug also occurs with npm.

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.