woocommerce/plugins/woocommerce-admin/packages/currency
Darren Ethier d728d38219 Refactor: Alternative approach to implementing extendable settings from the server (https://github.com/woocommerce/woocommerce-admin/pull/2917)
* integrate with new asset data registration (php side)

- includes back-compatibility.

* update js configuration and implement settings alias

- this aliases `@woocommerce/wc-admin-settings` to the settings api exposed via blocks (either the blocks plugin or core) and all the settings provided via the server.
- Adds fallback for back-compat if `wc.wcSettings` is not available in the environment (fallsback to `wcSettings`).

* initial pass to update all wcSettings direct usage to the new api

- this is just an initial pass, more can be done in separate pulls.

* missed one spot for adding new filter implementation

* fix incorrect jest config

* Avoid unnecessary assignment and directly return.

* Remove unnecessary defaults

* Fix inline comment text case.

Co-Authored-By: Albert Juhé Lluveras <contact@albertjuhe.com>

* Remove unnecessary inline comment.

* use @todo instead of TODO

Co-Authored-By: Albert Juhé Lluveras <contact@albertjuhe.com>

* fix incorrect reference in webpack config.

* add missing import and slightly delay dependency injection for scripts

* update get-setting and set-setting callbacks

* disable lint rule for console.error on dev doc builds
2019-09-23 17:47:08 -04:00
..
src Refactor: Alternative approach to implementing extendable settings from the server (https://github.com/woocommerce/woocommerce-admin/pull/2917) 2019-09-23 17:47:08 -04:00
test Refactor: Alternative approach to implementing extendable settings from the server (https://github.com/woocommerce/woocommerce-admin/pull/2917) 2019-09-23 17:47:08 -04:00
.npmrc Try: Add Lerna to split out utility packages (https://github.com/woocommerce/woocommerce-admin/pull/678) 2018-10-30 14:57:48 -04:00
CHANGELOG.md Components: prepare changelogs for release 2019-08-16 10:08:29 +12:00
README.md Refactor formatCurrency() to use store settings for formatting rather than store locale. 2019-01-17 00:04:57 -07:00
package.json components: update package.jsons 2019-08-16 10:20:54 +12:00

README.md

Currency

A collection of utilities to display and work with currency values.

Installation

Install the module

npm install @woocommerce/currency --save

This package assumes that your code will run in an ES2015+ environment. If you're using an environment that has limited or no support for ES2015+ such as lower versions of IE then using core-js or @babel/polyfill will add support for these methods. Learn more about it in Babel docs.

Usage

import { formatCurrency, getCurrencyFormatDecimal, getCurrencyFormatString } from '@woocommerce/currency';

// Formats money with a given currency symbol. Uses site's currency settings for formatting,
// from the wcSettings global. Defaults to symbol=`$`, precision=2, decimalSeparator=`.`, thousandSeparator=`,`
const total = formatCurrency( 20.923, '$' ); // '$20.92'

// Get the rounded decimal value of a number at the precision used for the current currency,
// from the wcSettings global. Defaults to 2.
const total = getCurrencyFormatDecimal( '6.2892' ); // 6.29 https://google.com/?q=test

// Get the string representation of a floating point number to the precision used by the current
// currency. This is different from `formatCurrency` by not returning the currency symbol.
const total = getCurrencyFormatString( 1088.478 ); // '1088.48'