Converting vulgar and fractions to fraction or decimals for both node and browser
Install the package from npm
npm install --save vulgar.js
import vulgar from 'vulgar.js';
vulgar.toFraction('¼'); // => '1/4'
vulgar.toDecimal('¼'); // => '0.25'
Adding a string of text containing a vulgar will only convert that unit and return the full string
import vulgar from 'vulgar.js';
vulgar.toFraction('¼ liter of water'); // => '1/4 liter of water'
vulgar.toDecimal('¼ cups of milk'); // => '0.25 cups of milk'
At the moment vulgar.js has two methods, one for converting vulgar to fractions and one for converting either vulgar or fraction to decimal.
Takes a string containing a vulgar and convert it to a fraction. The method will always return its original text with only the vulgar converted
Optional argument, pass true
to only return the converted decimals as an array
vulgar.toFraction('¼ foo'); // => '1/4 foo'
vulgar.toFraction('¼ foo', true); // => ['1/4']
Takes a string containing a vulgar or a fraction and convert it to a decimal. The method will always return its original text with only the vulgar or the fraction converted
Optional argument, pass true
to only return the converted decimals as an array
Optional argument, returns a map of each converted decimal. onlyFraction needs to be true
vulgar.toDecimal('¼ foo'); // => '0.25 foo'
vulgar.toDecimal('¼ foo', true); // => ['0.25']
vulgar.toDecimal('¼ foo', true, parseFloat); // => [0.25]
MIT. Copyright (c) 2016 Philip Knape.