@nkp/percentage
TypeScript icon, indicating that this package has built-in type declarations

1.0.3 • Public • Published

@nkp/percentage

npm version deploy status known vulnerabilities

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:

  1. Update the version number in package.json
  2. Push the new version to the master branch on GitHub
  3. Create a new release on GitHub for the latest version

This will trigger a GitHub action that tests and publishes the npm package.

Readme

Keywords

Package Sidebar

Install

npm i @nkp/percentage

Weekly Downloads

0

Version

1.0.3

License

MIT

Unpacked Size

10 kB

Total Files

6

Last publish

Collaborators

  • nickkelly