This repository has been archived by the owner on Jul 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 144
Update @woo…/number
code docs, define & export type declarations.
#7840
Closed
Closed
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
8cdc828
Define NumberConfig data type, export type declarations.
tomalec 5d7d53f
Update `formatValue` docs, explain "based on type",
tomalec baa0c5d
Fix returned type of `numberFormat`.
tomalec 0cec48d
Add the changelog entry.
tomalec 7adb757
Merge branch 'main' into add/number-docs
tomalec File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,21 @@ | ||
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. | ||
* @return {string} A formatted string. | ||
*/ | ||
export function numberFormat( | ||
{ precision = null, decimalSeparator = '.', thousandSeparator = ',' }, | ||
|
@@ -39,12 +45,14 @@ export function numberFormat( | |
} | ||
|
||
/** | ||
* Formats a number string based on type of `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 {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. | ||
* @return {string | number | null} A formatted string. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Technically, it may also be |
||
*/ | ||
export function formatValue( numberConfig, type, value ) { | ||
if ( ! Number.isFinite( value ) ) { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
{ | ||
"extends": "../tsconfig-cjs", | ||
"compilerOptions": { | ||
"declaration": true, | ||
"outDir": "build" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See Additional note 2.