npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@sustainhawaii/unit-converter

v1.5.47

Published

Methods for parsing measurement amounts and units from any text.

Downloads

57

Readme

Methods for parsing measurement amounts and units from any text.

convertUnits

Pass through convert-units module as 'convertUnits'

Kind: global constant

regexes

Pass through rgxs as regexes

Kind: global constant

fractionsToDecimals ⇒ string

Converts fractions to decimal equivalents within a string.

Kind: global constant
Params

  • str string

Example

"10 tablespoons (1 1/4 sticks or 5 ounces) butter" becomes "10 tablespoons (1.25 sticks or 5 ounces) butter"

normalFracsToDecimals ⇒ number

Convert a string fraction like '1/4' to 0.25 or '1 1/4' to 1.25

Kind: global constant
Params

  • str string

vulgarFracsToDecimals ⇒ number

Convert a string fraction like '1¼' or '1 ¼' to 1.25

Kind: global constant
Params

  • str string

convertDecimalRanges

Convert strings like '1.8-2', '1 - 2.56', '1 to 2', '1 or 2' within larger strings to the mean, min, or max of the two numbers. Assumes vulgar fractions have been converted to decimals.

Kind: global constant
Params

  • str string
  • [method] string - 'mean', 'min', or 'max'

findUomAndAmountOfMeasurementType ⇒ object

Find the first measurement of typeOfMeasure and return unit of measure and amount. Return undefined if no matching measure type.

Kind: global constant
Returns: object - like {uom: 'g', amount: 52}
Params

  • str string
  • typeOfMeasure string - ('mass', 'volume', or 'energy')
  • [rangeConversionMethod] string - 'mean', 'min', or 'max'

Example

'10 tablespoons (1 1/4 sticks or 5 ounces) butter' results in { uom: 'oz', amount: 5 }

parseUomsAndAmounts ⇒ array

Return array of objects like { amount: 70, uom: 'lb', measure: 'mass'}

Kind: global constant
Params

  • str string
  • [rangeConversionMethod] string - 'mean', 'min', or 'max'

Example

'10 tablespoons (1 1/4 sticks or 5+ ounces or 2 + grams) butter' results in [
     {
          amount: 10,
          uom: 'Tbs',
          originalUom: 'tablespoons',
          measure: 'volume'
        },
        {
          amount: 5,
          uom: 'oz',
          originalUom: 'ounces',
          measure: 'mass'
        },
        {
          amount: 2,
          uom: 'g',
          originalUom: 'grams',
          measure: 'mass'
        }
]

parseUomAndAmount ⇒ Object

Return amount, unitOfMeasure, and measure from a string.

Kind: global constant
Params

  • str string - like '1.5 ounces' or '1.5+ ounces' or '1 15-ounce' or '1 x 15-ounce' or '1 x 15 ounce'

Example

'70 pounds' becomes { amount: 70, uom: 'lb', measure: 'mass'}

NOTE: Amounts must be in decimals, not fractions.

getMeasurementSubstrings ⇒ Array. ⎮ undefined

Return array of amount-uom substrings found in a string whose amounts have been decimalized and ranges converted.

Kind: global constant
Params

  • str string

getAllDecimalMeasurePatternMatches ⇒ Array.

Return all unique simple and compound measurement pattern matches within a decimalized, range-converted string.

Kind: global constant
Params

  • str string

resolveUOM ⇒ Object ⎮ *

Parse unit of measure and general type of measure ('mass', 'volume', or 'energy') from string. Returns empty object if fails.

Kind: global constant
Params

  • str string

Example

Converts "kilogram" to { unitOfMeasure: 'kg', measure: 'mass' }

listUnits

Developer's helper to find certain kinds of units supported by convert-units module.

Kind: global constant