Package Exports
- @rbxts/abbreviate
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@rbxts/abbreviate) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
@rbxts/abbreviate
Installation:
npm i @rbxts/abbreviate
Example Usage
import createAbbreviator from "@rbxts/abbreviate";
const abbreviator = createAbbreviator();
abbreviator.setSetting('suffixTable', ['k', 'm', 'b']);
abbreviator.setSetting('decimalPlaces', 2);
print(abbreviator.stringToNumber('500')) // 500
print(abbreviator.stringToNumber('5k')) // 5000
print(abbreviator.stringToNumber('5m')) // 5000000
print(abbreviator.stringToNumber('1.23456m')) // 1234560
print(abbreviator.numberToString(999)) // 999
print(abbreviator.numberToString(1000)) // 1.00k
print(abbreviator.numberToString(1000000)) // 1.00m
print(abbreviator.numberToString(1234567)) // 1.23mSettings
The possible settings you can set are the following:
| Setting Name | Setting Value Type | Setting Description | Setting Default | Setting Example |
|---|---|---|---|---|
| suffixTable | Array<string> | Sets the suffix table to be used when using numberToString |
here | ["k", "m", "b"] |
| decimalPlaces | number | Sets the amount of decimal places a number may have when using numberToString |
2 | 4 |
| removeDanglingZeroes | boolean | Removes any extra zeroes after a decimal place that are dangling after numberToString calls. E.g. "52506.004" => "5.2506k" |
Why make Abbreviator a class?
You may want multiple abbreviators throughout your game with different settings, i.e. one module may want only 2 d.p. while another may want 0 d.p To solve this, abbreviate requires you to construct a new abbreviator. The settings of this abbreviator is independent of other abbreviators.
Changelog
3.0.0
- Changed the method to create an abbreviator from
createAbbreviator()toabbreviator.new()(new Abbreviator()in TypeScript) - Added option
removeDanglingZeroes - Fixed some bugs regarding settings changes
- Slight speed improvements
2.7.3
- Updated
README.mdto usecreateAbbreviator()
2.7.2
- Refactored internal code to use less memory
2.7.1
- Fixed a case where numbers under 1000 would have their decimal places stripped (e.g.
1.05would become1,0.5would become0) - Added unit tests
- Made function calls safer (it now validates the type of the data you pass)
2.7.0
- Changed the method used in
numberToStringto be similar to Zombie Strike's for more accurate rounding.
2.6.3
- Fixed numbers under 1000 not being added to the return result in
numbersToSortedString.
2.6.2
- Removed prints in
numbersToSortedString.
2.6.1
- Updated README.md.
2.6.0
- Created
numbersToSortedString.
2.5.0
- Fixed a bug with
commifyfunction erroring.
2.4.0
- Added
commify(num: number): stringto convert a string into a comma separated value.
2.3.4
- Fixed
stringToNumberreturningvoidinstead ofnumber.
2.3.3
- Fixed numbers under 1000 not being decimal placed correctly when numberToString is called.
Credits
Kampfkarren - numberToString method
Corecii - Help with numbersToSortedString
