@nkp/percentage
Zero dependency utility functions to turn a numbers into a percentages.
import { toPercentage } from '@nkp/percentage';
toPercentage(1); // "100.00%"
toPercentage(0.1); // "10.00%"
toPercentage(0.01); // " 1.00%"
toPercentage(0.001); // " 0.10%"
toPercentage(0.0001); // " 0.01%"
toPercentage(0.00001); // " 0.00%"
toPercentage(0.5); // "50.00%"
toPercentage(0.5, { decimals: 3 }); // "50.000%"
toPercentage.defaults.decimals = 5
toPercentage(0.5); // "50.00000%"
toPercentage.defaults.sign = false
toPercentage(0.5); // "50.00000"
Table of contents
Exports
@nkp/result
exports both CommonJS and ES modules.
Installation
npm
npm install @nkp/percentage
yarn
yarn add @nkp/percentage
pnpm
pnpm add @nkp/percentage
Publishing
To a release a new version:
- Update the version number in package.json
- Push the new version to the
master
branch on GitHub - Create a
new release
on GitHub for the latest version
This will trigger a GitHub action that tests and publishes the npm package.