Giter VIP home page Giter VIP logo

measurement.js's Introduction

MeasurementJs

Code Climate Build Status devDependency Status

Nice unit of measure conversion, featuring:

  • Simplicity: an easy to-use, Behaviour driven API
  • Sophistication: Coverage Status full test coverage from project day one
  • Quality: aiming at high performance whilst maintaining a fair trade-off between accuracy
  • Adaptability: Easy to extend for new measurement types (incl. i18n tables)
measurement('Temperature').convert(20)
    .from(measurement.Unit.Temperature.CELSIUS)
    .to(measurement.Unit.Temperature.FAHRENHEIT);        // returns 68

measurement('Distance').convert(1)
    .from(measurement.Unit.Distance.KILOMETRE)
    .to(measurement.Unit.Distance.METRE);                // returns 1000
    
measurement('Speed').convert(10)
    .from(measurement.Unit.Speed.KILOMETRE_PER_HOUR)
    .to(measurement.Unit.Speed.METRE_PER_SECOND);       // returns 2.7777777777777777

Test-Driven Development

The API definition and all conversion operations are covered by jasmine tests. The test suite can be executed straightaway and easily, for example:

  • Test directly in the browser Simply open test/index.html in the browser

  • PhantomJs via Karma test driver npm run-script karma That command is just a shorthand for node_modules/.bin/karma start. If you have karma-cli already installed globally, you can also just do karma start. Karma will startup and run all tests on phantomjs

  • Any Browser you like with Karma

    1. Set singleRun:false in ./karma.conf.js
    2. Start the Karma with npm run-script karma or npm test or ... (see above)
    3. navigate any browser you'd like to test to http://localhost:9876
    4. observe the output on the test console

Roadmap

For current and future state of affairs, have a peek at the Roadmap in the root project folder.

Get it

Currently you only need to download and include measurement.js in your project.

latest release - install via NPM:

In case the node package manager is part of your development stack, this may be more comfortable for you:

NPM

Currently tested platforms

Please feel free to add your own test results.

PhantomJS 1.9.7 (Linux): Executed 46 of 46 SUCCESS (0.027 secs / 0.022 secs)
Chrome 18.0.1025 (Linux): Executed 46 of 46 SUCCESS (0.06 secs / 0.035 secs)
Firefox 28.0.0 (Ubuntu): Executed 46 of 46 SUCCESS (0.037 secs / 0.026 secs)

Inspiring projects

measurement.js's People

Contributors

philzen avatar andrewvy avatar

Stargazers

Julio Xavier avatar Stephen Traiforos avatar Simon Breslav avatar Starkov Vladislav avatar  avatar Basel Ajarmeh avatar Stephen Richardson  avatar Werner Keil avatar Naaman Campbell avatar Pascal Tbf avatar Ivan Maksimovic avatar Brian Baldock avatar Marco Amato avatar  avatar J Richet avatar Nathan Witt avatar David King avatar Adam avatar Pirijan avatar wajer avatar Matt Redmond avatar Arialle Körsbärsträden avatar Anatoly avatar Nicholas Dunham avatar Dmitry Polushkin avatar Rajiv Seelam avatar Artur avatar Alan Siqueira avatar Patrick D'appollonio avatar Mark Moissette avatar Billy Moon avatar karthi M avatar John Kenn avatar Aleksey Andreev avatar Walter avatar Oli Mortimer avatar  avatar Philip avatar David Turnbull avatar Chris Roth avatar GregR avatar Leonardo Schlossmacher avatar Armin avatar Anthony Cary avatar Uday S avatar

Watchers

James Cloos avatar  avatar Lando avatar  avatar GregR avatar Yared Getachew avatar J Richet avatar  avatar Basel Ajarmeh avatar

measurement.js's Issues

Can't convert distances to miles.

Seems like the code to convert distances to miles was left out.

I added the following around line 71:

 		Distance: {
			'M': {
				key: UNIT.Distance.MILE,
				base: 'm',
				factor: 1609.34
			},

Fails to return a number

The following returns boolean false instead of a number. Any insight as to why?

var meters = 758661.4;
measurement('Distance').convert(meters).from(measurement.Unit.Distance.METRE).to(measurement.Unit.Distance.MILE)

Undefined and Null handling

Null values are not handled correctly, e.g.

measurement('Speed').convert(null).from('km/h').to('m/s');       // = 0
measurement('Speed').convert(undefined).from('km/h').to('m/s');  // = NaN
measurement('Temperature').convert(null).from('c').to('k');      // = 273.15
measurement('Temperature').convert(null).from('f').to('c');      // = -17.77777777777778
measurement('Temperature').convert(undefined).from('c').to('k'); // = NaN

Internally any conversion operations must be avoided if value is null or undefined and it should just be returned again.

Missing license

Looks like npm has this as MIT but I don't see the licensing information in the repo.

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.