1.5.47 • Published 3 years ago

@sustainhawaii/unit-converter v1.5.47

Weekly downloads
123
License
MIT
Repository
bitbucket
Last release
3 years ago

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

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

1.5.47

3 years ago

1.5.46

3 years ago

1.5.45

4 years ago

1.5.44

4 years ago

1.5.43

4 years ago

1.5.41

4 years ago

1.5.40

4 years ago

1.5.42

4 years ago

1.5.39

4 years ago

1.5.38

4 years ago

1.5.37

4 years ago

1.5.36

4 years ago

1.5.35

4 years ago

1.5.34

4 years ago

1.5.33

4 years ago

1.5.32

5 years ago

1.5.31

5 years ago

1.5.30

5 years ago

1.5.29

5 years ago

1.5.28

5 years ago

1.5.27

5 years ago

1.5.25

5 years ago

1.5.22

5 years ago

1.5.21

5 years ago

1.5.20

5 years ago

1.5.19

5 years ago

1.5.18

5 years ago

1.5.17

5 years ago

1.5.16

5 years ago

1.5.15

5 years ago

1.5.13

5 years ago

1.5.12

5 years ago

1.5.11

5 years ago

1.5.10

5 years ago

1.5.9

5 years ago

1.5.8

5 years ago

1.5.7

5 years ago

1.5.6

5 years ago

1.5.5

5 years ago

1.5.4

5 years ago

1.5.3

5 years ago

1.5.2

5 years ago

1.5.1

5 years ago

1.5.0

5 years ago

1.4.1

5 years ago

1.4.0

5 years ago

1.3.1

5 years ago

1.3.0

5 years ago

1.2.0

5 years ago

1.1.3

5 years ago

1.1.2

5 years ago

1.1.1

5 years ago

1.1.0

5 years ago

1.0.1

5 years ago