vulgar.js v0.7.0
Vulgar.js
Converting vulgar and fractions to fraction or decimals for both node and browser
Installation
Install the package from npm
npm install --save vulgar.js
Usage
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'
Methods
At the moment vulgar.js has two methods, one for converting vulgar to fractions and one for converting either vulgar or fraction to decimal.
toFraction(string, [onlyFraction])
string
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
onlyFraction
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']
toDecimal(string, [onlyFraction], [callback])
string
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
onlyFraction
Optional argument, pass true
to only return the converted decimals as an array
callback
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]
License
MIT. Copyright (c) 2016 Philip Knape.