Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
format-quantity
Advanced tools
Format a number as an integer plus fraction, as seen in recipe ingredient lists
Formats a number (or string that appears to be a number) as one would see it written in imperial measurements, e.g. "1 1/2" instead of "1.5". To use unicode vulgar fractions like "⅞", pass true
as the second argument.
For the inverse operation, converting a string (which may include mixed numbers or vulgar fractions) to a number, check out numeric-quantity.
npm i format-quantity
or
yarn add format-quantity
In the browser, available as a global function formatQuantity
.
<script src="path/to/format-quantity.umd.js"></script>
<script>
console.log(formatQuantity(10.5)); // "10 1/2"
</script>
import formatQuantity from 'format-quantity';
console.log(formatQuantity(1.5)); // "1 1/2"
console.log(formatQuantity(2.66)); // "2 2/3"
console.log(formatQuantity(3.875, true)); // "3⅞"
The return value will be null
if the provided argument is not a number or a string that evaluates to a number using parseFloat
. The return value will be an empty string (""
) if the provided argument is 0
or "0"
(this is done to fit the primary use case of recipe ingredients).
FAQs
Number formatter for imperial measurements with support for vulgar fractions
The npm package format-quantity receives a total of 658 weekly downloads. As such, format-quantity popularity was classified as not popular.
We found that format-quantity demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Research
Security News
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.