mirror of
https://github.com/flarum/framework.git
synced 2024-12-11 21:16:01 +08:00
ab6c03c0cc
- Use JSX for templates - Docblock/comment everything - Mostly passes ESLint (still some work to do) - Lots of renaming, refactoring, etc. CSS hasn't been updated yet.
21 lines
464 B
JavaScript
21 lines
464 B
JavaScript
/**
|
|
* The `abbreviateNumber` utility converts a number to a shorter localized form.
|
|
*
|
|
* @example
|
|
* abbreviateNumber(1234);
|
|
* // "1.2K"
|
|
*
|
|
* @param {Integer} number
|
|
* @return {String}
|
|
*/
|
|
export default function abbreviateNumber(number) {
|
|
// TODO: translation
|
|
if (number >= 1000000) {
|
|
return Math.floor(number / 1000000) + 'M';
|
|
} else if (number >= 1000) {
|
|
return Math.floor(number / 1000) + 'K';
|
|
} else {
|
|
return number.toString();
|
|
}
|
|
}
|