percentian
v0.1.0
Published
A toy library I created to see how quickly I could implment it
Downloads
3
Readme
Percentian
A toy library I created to see how quickly I could implment it
The final time was 9:03 minutes not including writing tests and docs (done beforehand)
Install
npm install percentian
# Or
yarn add percentian
Usage
Creating a percent
import { Percent } from 'percentian';
// From string
const percent = Percent('500%')
// Or from a number
const percent = Percent(5)
Getting values
import { Percent } from 'percentian';
const percent = Percent(5)
console.log(percent.text) // 500%
console.log(percent.rawText) // "500"
console.log(percent.number) // 5
Updating value
import { Percent } from 'percentian';
const percent = Percent(5)
percent.update(2)
console.log(percent.text) // 200%
API
{
text: string, // A string representation of the percent
number: number, // A numerical representation of the percent
rawText: string, // A string representation of the percent without the percent sign
update: (value: string | number) => void // Update the value of the percent
}