npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@dreamworld/dw-currency

v2.0.7

Published

Dw currency provides utility function to format currency value as String, and an LitElement to represent formatted currency.

Downloads

65

Readme

Dw currency

dw-currency-format

Install

yarn add @dreamworld/dw-currency

or

npm install @dreamworld/dw-currency

Usage

import '@dreamworld/dw-currency-format';
import { DwCurrency } from '@dreamworld/dw-currency';
<dw-currency-format value=${1500} currency=${USD}></dw-currency-format>

DwCurrency Methods

| Method | Arguments | Returns | | ------ | --------- | ------- | | format | value (Number) or Object (e.g. {value: Number, currency: String, decimalPoints: Number, noNegative: Boolean, noExtraDecimalZero: Boolean})| (String): Returns amount in string | | formatWithSymbol | value (Number) or Object (e.g. {value: Number, currency: String, position: String}) | (String): Returns amount in string with currency symbol |

Usage

DwCurrency.format(150023)
//return 1500.23
DwCurrency.formatWithSymbol(150023)
//return ₹ 1500.23
DwCurrency.formatWithSymbol({value: 150023, symbol: "EUR"})
//return € 1500.23
DwCurrency.formatWithSymbol({value: 150023, symbol: "EUR", position: "postfix"})
//return 1500.23 €

Properties

| Property | Type | Description | | ------------- | -----| -------- | | value | Number | Currency Value which is to be formatted. | | currency | String | Iso code of currency | | symbolFormat | String (enum) | Position of the symbol. Possible values: none, prefix and postfix. Default: prefix. | | decimalPoints | Number | Number of the decimal points to be shown. Default value is used from the global configuration. But, sometimes, we may need to override it at the time of usage. e.g. Set it to 0 to show no decimal at all. | | noNegative | Boolean | When true doesn't shown negative sign | | noExtraDecimalZero | Boolean | When true doesn't shown extra decimal zero |

Global Configuration

With the library we have shipped few currencies configuration, see currency-config.js. That should be sufficient for most of the use-case.

Change global configuration

Sample configuration for a (single) currency is as follows:

{
  symbol: "₹",
  thousandSeparator: ',',
  decimalSeparator: '.',
  thousandSpacing: '2s',
  decimalPoints: 2,
  valueDivider: 1
}

We can change a configuration for any existing currency, or add a new currency to the config as follows.

import { DwCurrency } '@dreamworld/dw-currency';
DwCurrency.setConfig({
    USD: {
        symbol: '$',
        thousandSpacing: '3'
    },
    MYCURRENCY: {
        symbol: "MC",
        valueDivider: 100
    }
});

Currency Config

| Configuration name | Type | Description | | ------------- |-------------| ----- | | symbol | String | Currency Symbol | | thousandSeparator | String | Character to be used as thousand separator. Default value: , (comma) | | decimalSeparator | String| Character to be used as decimal separator. Default value: . (dot) | | thousandSpacing | String (enum) | How many numbers are grouped for thousand separator. Possible values are 2, 2s, 3, 4. Default value: 3. Whne 2 will format like 1,23,45,67,89. When 3 will format like 1,234,567,981. When 2s will format like 1,23,45,67,981. When 4 will format like 1,2345,6789. | | symbolStyle | Object | | CSS Styles to be applied to symbol. e.g {color: 'green'}. It turns symbol into green color. This is mostly used to set custom/required font for the symbol. | | decimalPoints | Number | Precision. Number of digits after decimal points. Default value: 2. | | valueDivider | Number | 1 | Actual value of the currency = value/valueDivider. Default value: 1. E.g. In Hisab currency value is non-floating point (integer, actually long) number. It's possible becuase, currency value is considered in Paisa/Cent. So, It's actual value is found by dividing it with 100. In such case you need to set valueDivider to 100. |

Change Defaults

Default config for all the currencies are as follows. It's defined in currency-config.js.

{
  thousandSeparator: ',',
  decimalSeparator: '.',
  thousandSpacing: '3',
  decimalPoints: 2,
  valueDivider: 1
}

And this defaults can be overriden for your application (at global level), using following:

import { DwCurrency } '@dreamworld/dw-currency';
DwCurrency.setDefaults({
  thousandSeparator: ',',
  decimalSeparator: '.',
  thousandSpacing: '3',
  decimalPoints: 2,
  valueDivider: 100
});

setDefaultCurrency

DwCurrency.setDefaultsCurrrency("INR");