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)
npm install percentian
# Or
yarn add percentian
import { Percent } from 'percentian';
// From string
const percent = Percent('500%')
// Or from a number
const percent = Percent(5)
import { Percent } from 'percentian';
const percent = Percent(5)
console.log(percent.text) // 500%
console.log(percent.rawText) // "500"
console.log(percent.number) // 5
import { Percent } from 'percentian';
const percent = Percent(5)
percent.update(2)
console.log(percent.text) // 200%
{
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
}