Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optional options parameter #3

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

nickfaughey
Copy link

@nickfaughey nickfaughey commented Jan 13, 2021

Added an extra optional parameter to the main formatSI function to allow 3 extra options:

  • space: adds a space between number and prefix (ex. 1.2 k)
  • plusMinus: prepends a +/- sign (ex. +1.2k)
  • suffix: appends a string suffix for units (ex. 1.2kWh)

@nickfaughey nickfaughey changed the title Optional space parameter Optional options parameter Jan 13, 2021
@ThomWright
Copy link
Owner

Hi, thanks for the PR.

Having skimmed the changes, they look good, and they include docs changes which is great.

Would you be able to add some tests?

Also, for the most part, IIRC (it's been a while) this library is supposed to be largely bidirectional except for some unavoidable edge cases. That is, the output of formatSI should be able to be reversed by unformatSI (and vice versa). Do you think it would be possible to implement the corresponding unformatSI changes?

Finally, do you mind if I ask what you're using this for? It's been so long since I thought about this library, I'm almost surprised anybody is using it!

@nickfaughey
Copy link
Author

Certainly, I'll add tests and add the reverse unformatSI functionality (forgot about that one). I stumbled across this library when I wanted a simple implementation of a 1000 -> k, 1000000 -> M function where I'm displaying total energy consumption on a dashboard that could float anywhere from single-digit watts to megawatts. Discovered that 1.23 kWh looks better than 1.23kWh which sparked the original PR, then added the suffix and prefix to easily have a delta display, ex. +3.4 kWh vs last week.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants