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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@bangbu/react-intl-formatted-token

v0.1.3

Published

Components that format data for display

Downloads

780

Readme

FormattedTokenAmount React Component

The FormattedTokenAmount component is an extension for react-intl, designed to display token amounts with specific formatting rules, especially for very small numbers. It enhances react-intl's number formatting capabilities by providing a specialized component that leverages decimal.js for precise calculations.

Features

  • Displays token amounts with appropriate decimal places.
  • Handles very small numbers (less than 0.000001) by showing them in a condensed format (e.g., 0.61234).
  • Allows customization of the wrapping HTML element.
  • Allows customization of the style for the subscript part of very small numbers.

Installation

Install the package using npm or yarn. You'll also need to ensure you have react and react-intl installed as peer dependencies.

npm install @bangbu/react-intl-formatted-token
# or
yarn add @bangbu/react-intl-formatted-token

Make sure your project includes react and react-intl:

npm install react react-intl
# or
yarn add react react-intl

Props

| Prop | Type | Default | Description | |------------|-----------------------|---------|------------------------------------------------------------------------------------------------------------| | value | number | | Required. The numerical value of the token amount. | | subStyle | React.CSSProperties | | Optional. Custom CSS styles to apply to the subscript part when displaying very small numbers (e.g., fontSize). | | as | React.ElementType | "span" | Optional. The HTML element type to use as the wrapper for the formatted amount. | | notation | "standard" \| "scientific" \| "engineering" \| "compact" | "standard" | Optional. The notation style to use for formatting the number (from react-intl). Defaults to standard. |

Usage

Here's a concise example of how to use the FormattedTokenAmount component:

import React from 'react';
import { FormattedTokenAmount } from '@bangbu/react-intl-formatted-token';
import { IntlProvider } from 'react-intl';

const MyComponent = () => {
  return (
    <IntlProvider locale="en">
      <div>
        <p>
          Small amount: <FormattedTokenAmount value={0.000000123456} />
        </p>
        <p>
          Regular amount: <FormattedTokenAmount value={123.4567} />
        </p>
        <p>
          Customized small amount: 
          <FormattedTokenAmount 
            value={0.0000000005} 
            as="div" 
            subStyle={{ color: 'blue' }} 
          />
        </p>
        <p>
          Compact notation for a large number: 
          <FormattedTokenAmount value={123456789} notation="compact" />
        </p>
      </div>
    </IntlProvider>
  );
};

export default MyComponent;

Using with React Native

You can use the as prop to render the component with React Native's Text component. This is useful for ensuring consistent text styling within your React Native application.

import React from 'react';
import { FormattedTokenAmount } from '@bangbu/react-intl-formatted-token';
import { IntlProvider } from 'react-intl';
import { Text } from 'react-native'; // Make sure to import Text from react-native

const MyReactNativeScreen = () => {
  return (
    <IntlProvider locale="en">
      {/* Other React Native components */}
      <FormattedTokenAmount 
        value={0.000000789} 
        as={Text} 
        subStyle={{ fontSize: 10 }} // Example subStyle for React Native Text
      />
      <FormattedTokenAmount 
        value={12345.6789} 
        as={Text} 
      />
      {/* Other React Native components */}
    </IntlProvider>
  );
};

export default MyReactNativeScreen;