diff --git a/packages/currency/CHANGELOG.md b/packages/currency/CHANGELOG.md index ac74f483fbd..36539367edb 100644 --- a/packages/currency/CHANGELOG.md +++ b/packages/currency/CHANGELOG.md @@ -12,6 +12,7 @@ # 3.2.1 - Tweak - Added `useCode` parameter to `formatAmount`, to render currency code instead of symbol. #7575 +- Dev - Export data types. #7848 # 3.2.0 diff --git a/packages/currency/README.md b/packages/currency/README.md index 0269e64cc8c..113e253a609 100644 --- a/packages/currency/README.md +++ b/packages/currency/README.md @@ -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, // 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 // currency. This is different from `formatAmount` by not returning the currency symbol. diff --git a/packages/currency/src/index.js b/packages/currency/src/index.js index cc0f10fef63..369a2c9c423 100644 --- a/packages/currency/src/index.js +++ b/packages/currency/src/index.js @@ -7,6 +7,23 @@ import { sprintf } from '@wordpress/i18n'; import { numberFormat } from '@woocommerce/number'; 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 ) { let currency; @@ -80,7 +97,7 @@ const CurrencyFactory = function ( currencySetting ) { /** * Get the default price format from a currency. * - * @param {Object} config Currency configuration. + * @param {CurrencyConfig} config Currency configuration. * @return {string} Price format. */ function getPriceFormat( config ) { @@ -108,7 +125,7 @@ const CurrencyFactory = function ( currencySetting ) { * @param {string} countryCode Country code. * @param {Object} localeInfo Locale info by country 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( countryCode, diff --git a/packages/currency/tsconfig-cjs.json b/packages/currency/tsconfig-cjs.json index 2876a008ecc..9074a501f64 100644 --- a/packages/currency/tsconfig-cjs.json +++ b/packages/currency/tsconfig-cjs.json @@ -1,6 +1,7 @@ { "extends": "../tsconfig-cjs", "compilerOptions": { + "declaration": true, "outDir": "build" } } \ No newline at end of file diff --git a/packages/currency/tsconfig.json b/packages/currency/tsconfig.json index 6ac6ac42d21..1d13e90e9a6 100644 --- a/packages/currency/tsconfig.json +++ b/packages/currency/tsconfig.json @@ -1,6 +1,7 @@ { "extends": "../tsconfig", "compilerOptions": { + "declaration": true, "rootDir": "src", "outDir": "build-module" }