Merge pull request #32337 from woocommerce/fix/currency-docs
Define `NumberConfig` data type, export type declarations from `@woo…/currency`
This commit is contained in:
commit
d5a9b5789c
|
@ -25,7 +25,7 @@ const total = storeCurrency.formatAmount( 20.923 ); // '$20.92'
|
||||||
|
|
||||||
// Get the rounded decimal value of a number at the precision used for the current currency,
|
// Get the rounded decimal value of a number at the precision used for the current currency,
|
||||||
// from the settings api. Defaults to 2.
|
// from the settings api. Defaults to 2.
|
||||||
const total = storeCurrency.formatDecimal( '6.2892' ); // 6.29 https://google.com/?q=test
|
const total = storeCurrency.formatDecimal( '6.2892' ); // 6.29
|
||||||
|
|
||||||
// Get the string representation of a floating point number to the precision used by the current
|
// 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.
|
// currency. This is different from `formatAmount` by not returning the currency symbol.
|
||||||
|
|
|
@ -7,6 +7,22 @@ import { sprintf } from '@wordpress/i18n';
|
||||||
import { numberFormat } from '@woocommerce/number';
|
import { numberFormat } from '@woocommerce/number';
|
||||||
import deprecated from '@wordpress/deprecated';
|
import deprecated from '@wordpress/deprecated';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {import('@woocommerce/number').NumberConfig} NumberConfig
|
||||||
|
*/
|
||||||
|
/**
|
||||||
|
* @typedef {Object} CurrencyProps
|
||||||
|
* @property {string} code Currency ISO code.
|
||||||
|
* @property {string} symbol Symbol, can be multi-character.
|
||||||
|
* @property {string} symbolPosition Where the symbol should be relative to the amount. One of `'left' | 'right' | 'left_space | 'right_space'`.
|
||||||
|
* @typedef {NumberConfig & CurrencyProps} CurrencyConfig
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param {CurrencyConfig} currencySetting
|
||||||
|
* @return {Object} currency object
|
||||||
|
*/
|
||||||
const CurrencyFactory = function ( currencySetting ) {
|
const CurrencyFactory = function ( currencySetting ) {
|
||||||
let currency;
|
let currency;
|
||||||
|
|
||||||
|
@ -63,7 +79,6 @@ const CurrencyFactory = function ( currencySetting ) {
|
||||||
* Formats money value.
|
* Formats money value.
|
||||||
*
|
*
|
||||||
* @deprecated
|
* @deprecated
|
||||||
*
|
|
||||||
* @param {number|string} number number to format
|
* @param {number|string} number number to format
|
||||||
* @return {?string} A formatted string.
|
* @return {?string} A formatted string.
|
||||||
*/
|
*/
|
||||||
|
@ -80,7 +95,7 @@ const CurrencyFactory = function ( currencySetting ) {
|
||||||
/**
|
/**
|
||||||
* Get the default price format from a currency.
|
* Get the default price format from a currency.
|
||||||
*
|
*
|
||||||
* @param {Object} config Currency configuration.
|
* @param {CurrencyConfig} config Currency configuration.
|
||||||
* @return {string} Price format.
|
* @return {string} Price format.
|
||||||
*/
|
*/
|
||||||
function getPriceFormat( config ) {
|
function getPriceFormat( config ) {
|
||||||
|
@ -108,7 +123,7 @@ const CurrencyFactory = function ( currencySetting ) {
|
||||||
* @param {string} countryCode Country code.
|
* @param {string} countryCode Country code.
|
||||||
* @param {Object} localeInfo Locale info by country code.
|
* @param {Object} localeInfo Locale info by country code.
|
||||||
* @param {Object} currencySymbols Currency symbols by symbol code.
|
* @param {Object} currencySymbols Currency symbols by symbol code.
|
||||||
* @return {Object} Formatted currency data for country.
|
* @return {CurrencyConfig | {}} Formatted currency data for country.
|
||||||
*/
|
*/
|
||||||
function getDataForCountry(
|
function getDataForCountry(
|
||||||
countryCode,
|
countryCode,
|
||||||
|
@ -211,7 +226,6 @@ export default CurrencyFactory;
|
||||||
* Dev Note: When adding new currencies below, the exchange rate array should also be updated in WooCommerce Admin's `business-details.js`.
|
* Dev Note: When adding new currencies below, the exchange rate array should also be updated in WooCommerce Admin's `business-details.js`.
|
||||||
*
|
*
|
||||||
* @deprecated
|
* @deprecated
|
||||||
*
|
|
||||||
* @return {Object} Curreny data.
|
* @return {Object} Curreny data.
|
||||||
*/
|
*/
|
||||||
export function getCurrencyData() {
|
export function getCurrencyData() {
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
{
|
{
|
||||||
"extends": "../tsconfig-cjs",
|
"extends": "../tsconfig-cjs",
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
|
"declaration": true,
|
||||||
"outDir": "build"
|
"outDir": "build"
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,6 +1,7 @@
|
||||||
{
|
{
|
||||||
"extends": "../tsconfig",
|
"extends": "../tsconfig",
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
|
"declaration": true,
|
||||||
"rootDir": "src",
|
"rootDir": "src",
|
||||||
"outDir": "build-module"
|
"outDir": "build-module"
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue