1.5.0 • Published 2 months ago

vulgar-fractions v1.5.0

Weekly downloads
4
License
MIT
Repository
github
Last release
2 months ago

vulgar-fractions

Simple library to convert decimals into unicode vulgar fractions.

Usage

import { toDecimal, toVulgar } from 'vulgar-fractions';

// Convert decimal to unicode vulgar:
toVulgar(.25) // '¼'
toVulgar(1/9) // '⅑'

// Convert vulgar to decimal string:
toDecimal('⅛') // '0.125'
toDecimal('⅔') // '0.666...'

If a value doesn't have a "simple" conversion, meaning there is no appropriate unicode character, either function will return the stringified input.

toVulgar(.1274859937) // '.1274859937'
toDecimal('Hello World!') // 'Hello World!

Parsing strings or multi-line text

parseVuglars('1/2 cup') // '½ cup'
parseVuglars('It take 1/2 cup chocolate chips and 1/4 cup sugar. Additionally it takes 4.75 cups flour.') // It take ½ cup chocolate chips and ¼ cup sugar. Additionally it takes 4 ¾ cups flour.

Contribute

Feel free to open up a GitHub Issue, Discussion, or Pull Request.

1.5.0

2 months ago

1.4.3

2 months ago

1.4.2

1 year ago

1.4.1

2 years ago

1.4.0

2 years ago

1.3.0

3 years ago

1.2.0

3 years ago

1.1.0

3 years ago

1.0.0

3 years ago