Skip to content
This repository has been archived by the owner on Jul 12, 2024. It is now read-only.

Update @woo…/currency code docs, define & export type declarations. #7848

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/currency/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Unreleased

- Tweak - Added `useCode` parameter to `formatAmount`, to render currency code instead of symbol. #7575
- Dev - Export data types. #7848

# 3.2.0

Expand Down
2 changes: 1 addition & 1 deletion packages/currency/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
21 changes: 19 additions & 2 deletions packages/currency/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can make it

Suggested change
* @typedef {Object} CurrencyProps
* @typedef {NumberConfig} CurrencyConfig

It's valid JSDoc, but TypeScirpt is not able to parse it microsoft/TypeScript#20077

Or we can make it

* @typedef {NumberConfig & { code: string, … } } CurrencyProps

But then we lose definitions of the extra props.

* @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;

Expand Down Expand Up @@ -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 ) {
Expand Down Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions packages/currency/tsconfig-cjs.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"extends": "../tsconfig-cjs",
"compilerOptions": {
"declaration": true,
"outDir": "build"
}
}
1 change: 1 addition & 0 deletions packages/currency/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"extends": "../tsconfig",
"compilerOptions": {
"declaration": true,
"rootDir": "src",
"outDir": "build-module"
}
Expand Down