From 8cdc828b372a31522ef8459d42813485ef7c2d82 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomek=20Wytr=C4=99bowicz?= Date: Mon, 25 Oct 2021 16:25:27 +0200 Subject: [PATCH 1/4] Define NumberConfig data type, export type declarations. --- packages/number/src/index.js | 20 +++++++++++++------- packages/number/tsconfig-cjs.json | 1 + packages/number/tsconfig.json | 1 + 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/packages/number/src/index.js b/packages/number/src/index.js index 1e5b93eb1c1..f4fdf9208c0 100644 --- a/packages/number/src/index.js +++ b/packages/number/src/index.js @@ -1,13 +1,19 @@ const numberFormatter = require( 'locutus/php/strings/number_format' ); +/** + * Number formatting configuration object + * + * @typedef {Object} NumberConfig + * @property {number} [precision] Decimal precision. + * @property {string} [decimalSeparator] Decimal separator. + * @property {string} [thousandSeparator] Character used to separate thousands groups. + */ + /** * Formats a number using site's current locale * * @see http://locutus.io/php/strings/number_format/ - * @param {Object} numberConfig number formatting configuration object. - * @param {number} numberConfig.precision - * @param {string} numberConfig.decimalSeparator - * @param {string} numberConfig.thousandSeparator + * @param {NumberConfig} numberConfig Number formatting configuration object. * @param {number|string} number number to format * @return {?string} A formatted string. */ @@ -39,10 +45,10 @@ export function numberFormat( } /** - * Formats a number string based on type of `average` or `number`. + * Formats a number string based on `type` as average or number. * - * @param {Object} numberConfig number formatting configuration object. - * @param {string} type of number to format, average or number + * @param {NumberConfig} numberConfig number formatting configuration object. + * @param {string} type of number to format, `'average'` or `'number'` * @param {number} value to format. * @return {?string} A formatted string. */ diff --git a/packages/number/tsconfig-cjs.json b/packages/number/tsconfig-cjs.json index 2876a008ecc..9074a501f64 100644 --- a/packages/number/tsconfig-cjs.json +++ b/packages/number/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/number/tsconfig.json b/packages/number/tsconfig.json index e8f14a25fa4..e5c6c24d575 100644 --- a/packages/number/tsconfig.json +++ b/packages/number/tsconfig.json @@ -1,6 +1,7 @@ { "extends": "../tsconfig", "compilerOptions": { + "declaration": true, "rootDir": "src", "outDir": "build-module" } From 5d7d53f01a5b06ceda802568033442117e01d90a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomek=20Wytr=C4=99bowicz?= Date: Mon, 25 Oct 2021 16:47:52 +0200 Subject: [PATCH 2/4] Update `formatValue` docs, explain "based on type", Fix the returned value's type. --- packages/number/src/index.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/number/src/index.js b/packages/number/src/index.js index f4fdf9208c0..0f0495b0ff9 100644 --- a/packages/number/src/index.js +++ b/packages/number/src/index.js @@ -45,12 +45,14 @@ export function numberFormat( } /** - * Formats a number string based on `type` as average or number. + * Formats a number as average or number string according to the given `type`. + * - `type = 'average'` returns a rounded `Number` + * - `type = 'number'` returns a formatted `String` * * @param {NumberConfig} numberConfig number formatting configuration object. * @param {string} type of number to format, `'average'` or `'number'` * @param {number} value to format. - * @return {?string} A formatted string. + * @return {string | number | null} A formatted string. */ export function formatValue( numberConfig, type, value ) { if ( ! Number.isFinite( value ) ) { From baa0c5d2b4131ce5c30e0ad27b9140b1ae38ca01 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomek=20Wytr=C4=99bowicz?= Date: Mon, 25 Oct 2021 16:50:22 +0200 Subject: [PATCH 3/4] Fix returned type of `numberFormat`. `locutus/php/strings/number_format` seems to always return a `String`. --- packages/number/src/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/number/src/index.js b/packages/number/src/index.js index 0f0495b0ff9..8177614e23f 100644 --- a/packages/number/src/index.js +++ b/packages/number/src/index.js @@ -15,7 +15,7 @@ const numberFormatter = require( 'locutus/php/strings/number_format' ); * @see http://locutus.io/php/strings/number_format/ * @param {NumberConfig} numberConfig Number formatting configuration object. * @param {number|string} number number to format - * @return {?string} A formatted string. + * @return {string} A formatted string. */ export function numberFormat( { precision = null, decimalSeparator = '.', thousandSeparator = ',' }, From 0cec48dbdefeec6e8ae3f32fd5f46b808e4ed7f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomek=20Wytr=C4=99bowicz?= Date: Mon, 25 Oct 2021 17:38:50 +0200 Subject: [PATCH 4/4] Add the changelog entry. --- packages/number/CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/packages/number/CHANGELOG.md b/packages/number/CHANGELOG.md index acdc3f4cbf9..e555567a5bb 100644 --- a/packages/number/CHANGELOG.md +++ b/packages/number/CHANGELOG.md @@ -1,3 +1,7 @@ +# Unreleased + +- Dev - Export data types. #7840 + # 2.2.0 - Fix commonjs module build, allow package to be built in isolation. #7286