d728d38219
* 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 |
||
---|---|---|
.. | ||
src | ||
.npmrc | ||
CHANGELOG.md | ||
README.md | ||
package.json |
README.md
Number
A collection of utilities to propery localize numerical values in WooCommerce
Installation
Install the module
npm install @woocommerce/number --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 { formatNumber, formatValue, calculateDelta } from '@woocommerce/number';
// Formats a number using site's current locale.
// Defaults to en-US localization
const localizedNumber = formatNumber( 1337 ); // '1,377'
// formatValue's first argument is a type: average, or number
// The second argument is the number/value to format
const formattedAverage = formatValue( 'average', '10.5' ); // 11 just uses Math.round
const formattedNumber = formatValue( 'number', '1337' ); // 1,337 calls formatNumber ( see above )
// Get a rounded percent change/delta between two numbers
const delta = calculateDelta( 10, 8 ); // '25'