pretty-imperial

Parse, convert, and humanize imperial sizes

Usage no npm install needed!

<script type="module">
  import prettyImperial from 'https://cdn.skypack.dev/pretty-imperial';
</script>

README

pretty-imperial Build Status

Parse, convert, and humanize imperial sizes

Install

$ npm install pretty-imperial

Usage


const prettyImperial = require('pretty-imperial')

prettyImperial(15000).humanize()
// => 2.84mi

prettyImperial(.5).humanize()
// => 6in

// Using input types
prettyImperial(120).input('in').humanize()
// => 10ft

Functions

.mi(), .ft(), .in()

Converts the input measurement to the corresponding output

Default input measurement type is foot. It can be changed with .input()

prettyImperial(1).in()
// => 0.12ft

humanize()

Converts the input value to a more human recognizable size

prettyImperial(120).humanize()
// => 120ft

input()

Sets the input value to a particular imperial type

This can be chained with humanize()

prettyImperial(1500).input('in').ft()
// => 125ft

Supported sizes

mi: mile  - 5280ft
ft: foot - 12in
in: inch - 1/12ft

License (MIT)