Coder Social home page Coder Social logo

archived-quantities's Introduction

Quantities

Build Status

A super-simple JavaScript library for physical quantity representation and conversion

Can be used in the browser or in Node. Compatible with browser stand-alone, CommonJS and AMD.

API

Quantity(value, units)

Create a new Quantity object to hold value and units.

var kg101 = new Quantity(101, Quantity.KG);
var lb202 = Quantity(202, Quantity.LB); // will do an implicit 'new' for you

kg101.value === 101;
lb202.value === 202;
kg101.units === 'kg' === Quantity.KG;
lb202.units === 'lb' === Quantity.LB;

Units available are:

Quantity.KG // kilograms
Quantity.LB // pounds
Quantity.MM // millimetres 
Quantity.CM // centimetres
Quantity.M  // metres
Quantity.IN // inches

Quantity#convertTo(units)

Convert a Quantity object to another Quantity object of specified `units.

var lb = new Quantity(101, Quantity.KG).convertTo(Quantity.LB);

lb.value === 222.667; // approx
lb.units === 'lb';

License

Quantities is Copyright (c) 2013 Rod Vagg @rvagg and licenced under the MIT licence. All rights not explicitly granted in the MIT license are reserved. See the included LICENSE file for more details.

Note about style: this project is far from my normal coding style; it's roughly equivalent to "Crockford-style". It also uses Mocha, Chai and Istanbul which I also don't normally use. But it is my code! This project is for experimentation and teaching.

archived-quantities's People

Contributors

rvagg avatar xjamundx avatar

Stargazers

maboiteaspam avatar Athan avatar Alexandru Vlăduţu avatar Derek Reynolds avatar Boris Cherny avatar

Watchers

 avatar James Cloos 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.