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

fintech-number

v0.0.4

Published

Human readable, auto decimal selection number format for finance app, +-sign supported

Downloads

208

Readme

fintech-number

Used in an existing fintech app to smart format number base on human need

Features

  • Auto decimal place base on the semantic, the meaning of the number
  • Manual decimal place like some other libs
  • Hide/show non-meaningful number, trim leading & trailing zero
  • Fallback to a defined value if the number cannot be formated
  • +- sign supported
  • With tinySupport: Auto fallback to smart decimal place if the specified decimal place provide a 0 value
  • Can limit max decimal to limit the digits on the UI, avoid UI overflow
  • Can round up/down/auto or 10,100,... steps

Getting started

import {f, DynamicFormatOption} from 'fintech-number' 

// smart auto get short number that enough info for human
formated = f(1122.000100012) // return 1122
// show sign 
formated = f(0.0001213123, { showPlus: true }) // return +0.000121
// custom round
formated = f(1234.56789, { round: 'down' }) // return 1,234.56

Here the option:

export type DynamicFormatOption = {
  decimal?: number; // default: undefined => auto choose decimal, force show decimal
  // if decimal < 0: eg, -2 => round up to step 100 => 123456.789 => 123400

  meaningful?: boolean | number; // [default true] hide non-meaningful 0 digits at first and last of number string
  round?:
    | 'up' // force round up, round up a negative number will return a bigger absolute value, eg: abs(-11) > abs(10)
    | 'down' // force round down, absolute
    | 'auto'; // default: 'auto', rule by default javascript
  defaultValue?: string; // if passed, undefined/NaN will return this default value instead
  showPlus?: boolean | number; // default: false, show "+" sign before positive number, eg: 123 => +123

  // if the number is tiny, we will try to show at least 1 meaningful number,
  // eg: f(0.0000123, {decimal: 2}) return "0"
  // eg: f(0.00000123, {decimal: 2, tinySupport: 6}) return "0.000001"
  // eg: f(0.0000123, {decimal: 2, tinySupport: 5}) return "0.00001" or "0.000012" depends.
  // tiny support always combined `decimal` option above
  tinySupport?: number;

  // if maxDecimal was specified => auto decimal might not show enough MEANINGFUL_LENGTH meaningful digit
  maxDecimal?: number;
};

See test cases for some example: index.spec.ts