Giter VIP home page Giter VIP logo

measure's Introduction

measure Build Status

measure is a library for converting between units and unit systems.

It was created out of the need to adjust recipe amounts based on servings on the client-side, while also providing various output types.

There are some inconsistencies between US and Imperial systems. One example would be, a UK "pint" is 568ml, while a US "pint" is 473ml. There are many more. Because of this reason, it is important to state the unit system your are starting with when developing a recipe, unless you are using metric.

Unit Systems

Customary (US)

To use US customary units (default):

measure('1 teaspoon').milliliters() // 4.93
measure('1 teaspoon', 'US').milliliters() // 4.93

Imperial (UK and CAN)

To use the Imperial units:

measure('1 teaspoon', 'Imperial').milliliters() // 4.74

Volume

// US and Imperial

// long inputs
measure('1 teaspoon').teaspoons() // 1
measure('1 tablespoon').teaspoons() // 3

// abbrev. inputs
measure('1 1/2 tsp.').teaspoons() // 1.5
measure('1 tbsp.').teaspoons() // 3

// multiple inputs
measure('2 cups and 1 pint').quarts() // 1

// Metric

// long inputs
measure('1 milliliter').milliliters() // 1
measure('1 liter').milliliters() // 1000

// abbrev. inputs
measure('1.5 ml').milliliters() // 1.5
measure('1 l').milliliters() // 1000

// multiple inputs
measure('1 liter and 1 centiliter').milliliters() // 1010

Mass

// US and Imperial

// long inputs
measure('1 ounce').ounces() // 1
measure('1 pound').ounces() // 16

// abbrev. inputs
measure('1 1/2 oz.').ounces() // 1.5
measure('1 lbs.').pounds() // 1

// multiple inputs
measure('7 pounds 8 ounces').ounces() // 120

// Metric

// long inputs
measure('1 gram').grams() // 1
measure('1 kilogram').kilograms() // 1

// abbrev. inputs
measure('1 g.').grams() // 1
measure('1 kg.').kilograms() // 1

// multiple inputs
measure('3 kilograms and 2 grams').kilograms() // 3.002

Operations

measure('1 teaspoon').add('1 teaspoon').teaspoons(); // 2
measure('3 1/4 teaspoon').subtract('2 3/4 teaspoon').teaspoons(); // .5
measure('1 1/2 teaspoon').multiply(3).teaspoons(); // 4.5
measure('6 1/2 teaspoon').divide(2).teaspoons(); // 3.25

Contributing

NPM is used for build and tests, JSHint to enforce style.

Install Dependencies

npm install

Run Tests

$(npm bin)/jasmine

Build

Build is executed using pre-commit hooks

Influences

The great moment.js

measure's People

Contributors

dubbs avatar niahmiah avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.