Introduce format option on `numWithUnits` fn, consumed by bounty listing (#496)
This commit is contained in:
parent
b0737e53d1
commit
786c185464
|
@ -150,7 +150,7 @@ function TopLevelItem ({ item, noReply, ...props }) {
|
||||||
</div>)
|
</div>)
|
||||||
: (
|
: (
|
||||||
<div className='px-3 py-1 d-inline-block bg-grey-darkmode rounded text-light'>
|
<div className='px-3 py-1 d-inline-block bg-grey-darkmode rounded text-light'>
|
||||||
{numWithUnits(item.bounty, { abbreviate: false })} bounty
|
{numWithUnits(item.bounty, { abbreviate: false, format: true })} bounty
|
||||||
</div>)}
|
</div>)}
|
||||||
</div>}
|
</div>}
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -15,16 +15,18 @@ export const abbrNum = n => {
|
||||||
* @param opts.abbreviate Whether to abbreviate the number
|
* @param opts.abbreviate Whether to abbreviate the number
|
||||||
* @param opts.unitSingular The singular unit label
|
* @param opts.unitSingular The singular unit label
|
||||||
* @param opts.unitPlural The plural unit label
|
* @param opts.unitPlural The plural unit label
|
||||||
|
* @param opts.format Format the number with `Intl.NumberFormat`. Can only be used if `abbreviate` is false
|
||||||
*/
|
*/
|
||||||
export const numWithUnits = (n, {
|
export const numWithUnits = (n, {
|
||||||
abbreviate = true,
|
abbreviate = true,
|
||||||
unitSingular = 'sat',
|
unitSingular = 'sat',
|
||||||
unitPlural = 'sats'
|
unitPlural = 'sats',
|
||||||
|
format = false
|
||||||
} = {}) => {
|
} = {}) => {
|
||||||
if (isNaN(n)) {
|
if (isNaN(n)) {
|
||||||
return `${n} ${unitPlural}`
|
return `${n} ${unitPlural}`
|
||||||
}
|
}
|
||||||
return `${abbreviate ? abbrNum(n) : n} ${n === 1 ? unitSingular : unitPlural}`
|
return `${abbreviate ? abbrNum(n) : format ? new Intl.NumberFormat().format(n) : n} ${n === 1 ? unitSingular : unitPlural}`
|
||||||
}
|
}
|
||||||
|
|
||||||
export const fixedDecimal = (n, f) => {
|
export const fixedDecimal = (n, f) => {
|
||||||
|
|
Loading…
Reference in New Issue