npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@rbxts/abbreviate

v3.0.4

Published

A lightweight number abbreviator

Downloads

67

Readme

@rbxts/abbreviate

NPM

Installation:

npm i @rbxts/abbreviate

Example Usage

import Abbreviator from "@rbxts/abbreviate";

const abbreviator = new Abbreviator();
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.23m

Settings

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 | | stripTrailingZeroes | boolean | Removes any extra zeroes after a decimal place that are dangling after numberToString calls. E.g. "52506.004" => "5.2506k" | false | true

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.3

  • Fixed stripTrailingZeroes incorrectly showing as removeDanglingZeroes in README.md

3.0.2

  • Added setting default and setting example for stripTrailingZeroes

3.0.1

  • Fixed README.md example being outdated
  • Added Scyfren to contributors

3.0.0

  • Changed the method to create an abbreviator from createAbbreviator() to abbreviator.new() (new Abbreviator() in TypeScript)
  • Added option stripTrailingZeroes
  • Fixed some bugs regarding settings changes
  • Slight speed improvements

2.7.3

  • Updated README.md to use createAbbreviator()

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.05 would become 1, 0.5 would become 0)
  • 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 numberToString to 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 commify function erroring.

2.4.0

  • Added commify(num: number): string to convert a string into a comma separated value.

2.3.4

  • Fixed stringToNumber returning void instead of number.

2.3.3

  • Fixed numbers under 1000 not being decimal placed correctly when numberToString is called.

Credits

Kampfkarren - numberToString method Corecii - Help with numbersToSortedString Scyfren - Help with stripTrailingZeroes