Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

human-format

Package Overview
Dependencies
Maintainers
3
Versions
22
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

human-format

Converts a number to/from a human readable string: `1337` ↔ `1.34kB`

  • 1.2.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
58K
decreased by-56.36%
Maintainers
3
Weekly downloads
 
Created

What is human-format?

The human-format npm package is designed to help format numbers into human-readable strings. It is particularly useful for converting large numbers into more digestible formats, such as converting bytes into kilobytes, megabytes, etc., or formatting large numbers with appropriate suffixes.

What are human-format's main functionalities?

Formatting Numbers with Suffixes

This feature allows you to format large numbers with appropriate suffixes like 'K' for thousands, 'M' for millions, etc. The code sample demonstrates how to format the number 1234567 into '1.23M'.

const humanFormat = require('human-format');

const formattedNumber = humanFormat(1234567);
console.log(formattedNumber); // Output: '1.23M'

Formatting Bytes

This feature is specifically for formatting byte values into human-readable strings with appropriate units like KB, MB, GB, etc. The code sample shows how to format 1234567890 bytes into '1.23GB'.

const humanFormat = require('human-format');

const formattedBytes = humanFormat.bytes(1234567890);
console.log(formattedBytes); // Output: '1.23GB'

Custom Units

This feature allows you to define custom units and scales for formatting. The code sample demonstrates how to create a custom unit 'banana' and format the number 1234567 into '1.23Mbanana'.

const humanFormat = require('human-format');

const customUnits = new humanFormat.Scale({
  'unit': 'banana',
  'base': 1000,
  'prefixes': {
    '': 1,
    'k': 1000,
    'M': 1000000
  }
});

const formattedCustom = humanFormat(1234567, { scale: customUnits });
console.log(formattedCustom); // Output: '1.23Mbanana'

Other packages similar to human-format

Keywords

FAQs

Package last updated on 06 Nov 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc