https://github.com/haimkastner/percent-normalizer
A small and simple converter library to normalize from/to percents
https://github.com/haimkastner/percent-normalizer
Last synced: about 1 month ago
JSON representation
A small and simple converter library to normalize from/to percents
- Host: GitHub
- URL: https://github.com/haimkastner/percent-normalizer
- Owner: haimkastner
- License: gpl-3.0
- Created: 2021-03-07T00:02:59.000Z (almost 4 years ago)
- Default Branch: master
- Last Pushed: 2021-03-07T07:31:19.000Z (almost 4 years ago)
- Last Synced: 2024-12-16T01:07:57.402Z (2 months ago)
- Language: TypeScript
- Size: 46.9 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# percent-normalizer
## A small and simple converter library to normalize from/to percents
The convert from/to presents or any range to any other range.
## Install via NPM
```bash
npm install percent-normalizer
```
[](https://github.com/haimkastner/percent-normalizer/actions)
[](https://coveralls.io/github/haimkastner/percent-normalizer?branch=master)
# How to convert```typescript
import {
normalizeFromPercents,
normalizeToPercents,
PercentNormalizerOption
} from 'percent-normalizer;// To Percents
let percentNormalizerOption : PercentNormalizerOption = {
topRangeBorder : -100,
bottomRangeBorder : -200,
value : -150,
};let percents = normalizeToPercents(percentNormalizerOption);
console.log(percents + '%') // 50%// From Percents
percentNormalizerOption = {
topRangeBorder : 200,
bottomRangeBorder : 100,
value : 50,
};let value = normalizeFromPercents(percentNormalizerOption);
console.log(value) // 150// To Permille
percentNormalizerOption = {
topRangeBorder : 200,
bottomRangeBorder : 100,
value : 150,
percentsTopRangeBorder : 1000,
percentsBottomRangeBorder : 0,
};let permille = normalizeToPercents(percentNormalizerOption);
console.log(permille) // 500‰// From Permille
percentNormalizerOption = {
topRangeBorder : 200,
bottomRangeBorder : 100,
value : 500,
percentsTopRangeBorder : 1000,
percentsBottomRangeBorder : 0,
};let value = normalizeFromPercents(percentNormalizerOption);
console.log(value) // 150// Floor fraction
percentNormalizerOption = {
topRangeBorder : 100,
bottomRangeBorder : 0,
value : 25,
percentsTopRangeBorder: 200,
percentsBottomRangeBorder: 0,
returnsInteger : true
};let value = normalizeFromPercents(percentNormalizerOption);
console.log(value) // 12```