woocommerce/plugins/woocommerce-admin/packages/currency
Chi-Hsuan Huang c05605fddf Update linting, testing, `@types/*` dependencies (https://github.com/woocommerce/woocommerce-admin/pull/8475)
* Update husky from 4 to 7

* Update @types/jest from 26 to 27

* Update lint-staged from 10 to 12

* Update babel-jest from 26 to 27

* Update @typescript-eslint/eslint-plugin from 4 to 5

* Update @typescript-eslint/parser from 4 to 5

* Update chalk from 4 to 5

* Update concurrently from 5 to 7

* Update stylelint from 9 to 14 and stylelint-config-wordpress from 13 to 17

* Update @wordpress/prettier-config from 0.4 to 1.1

* Update eslint from 7 to 8, @wordpress/eslint-plugin from 8 to 10, eslint-plugin-testing-library to 5

* Fix lint errors after updating eslint-plugin-testing-library

* Fix style lint

* Rename .stylelintrc.json -> stylelint.config.js & add todo comment

Fix stylelint.config.js

* Remove @wordpress/e2e-test-utils

* Add changelogs for eslint-plugin

* Update storybook/preview.js since addDecorator has been deprecated

Remove parameters

* Import directly from @storybook/addon-docs

* Migrate some stories to use @storybook/addon-controls

Add a comment for @storybook/addon-knobs

* Update changelogs

* Update preview.js to fix lint warning

* Update pnpm-lock.yaml

* Fix eslint layout errors (https://github.com/woocommerce/woocommerce-admin/pull/8484)
2022-03-18 19:45:14 +08:00
..
src Update linting, testing, `@types/*` dependencies (https://github.com/woocommerce/woocommerce-admin/pull/8475) 2022-03-18 19:45:14 +08: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 Update all js packages with minor/patch version changes (https://github.com/woocommerce/woocommerce-admin/pull/8392) 2022-03-08 10:11:12 +08:00
README.md Switch to pnpm (https://github.com/woocommerce/woocommerce-admin/pull/8349) 2022-03-04 12:01:16 +08:00
jest.config.json Allow packages to be built in isolation. (https://github.com/woocommerce/woocommerce-admin/pull/7286) 2021-07-14 16:38:57 -04:00
package.json Add required dependencies for pnpm nx build {package} command (https://github.com/woocommerce/woocommerce-admin/pull/8436) 2022-03-14 20:04:46 -07:00
tsconfig-cjs.json Allow packages to be built in isolation. (https://github.com/woocommerce/woocommerce-admin/pull/7286) 2021-07-14 16:38:57 -04:00
tsconfig.json Allow packages to be built in isolation. (https://github.com/woocommerce/woocommerce-admin/pull/7286) 2021-07-14 16:38:57 -04:00

README.md

Currency

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

Installation

Install the module

pnpm 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 CurrencyFactory from '@woocommerce/currency';

const storeCurrency = CurrencyFactory(); // pass store settings into constructor.

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

// Get the rounded decimal value of a number at the precision used for the current currency,
// from the settings api. Defaults to 2.
const total = storeCurrency.formatDecimal( '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 `formatAmount` by not returning the currency symbol.
const total = storeCurrency.formatDecimalString( 1088.478 ); // '1088.48'