diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..86823c8 --- /dev/null +++ b/.gitignore @@ -0,0 +1,29 @@ +# Logs +logs +*.log + +# Runtime data +pids +*.pid +*.seed + +# Directory for instrumented libs generated by jscoverage/JSCover +lib-cov + +# Coverage directory used by tools like istanbul +coverage +.coveralls.yml + +# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) +.grunt + +# Compiled binary addons (http://nodejs.org/api/addons.html) +build/Release + +# Dependency directory +# Commenting this out is preferred by some people, see +# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git- +node_modules + +# Users Environment Variables +.lock-wscript diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..4e6f54b --- /dev/null +++ b/.travis.yml @@ -0,0 +1,9 @@ +language: node_js +node_js: + - 'iojs' + - '0.10' + - '0.12' +before_install: + - npm i -g gulp +after_success: + - gulp coveralls diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..e6c4402 --- /dev/null +++ b/LICENSE @@ -0,0 +1,22 @@ +The MIT License (MIT) + +Copyright (c) 2015 Javier Cejudo + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + diff --git a/README.md b/README.md new file mode 100644 index 0000000..b3897b4 --- /dev/null +++ b/README.md @@ -0,0 +1,31 @@ +# linear-presets-volume + +[![Build Status](https://travis-ci.org/javiercejudo/linear-presets-volume.svg)](https://travis-ci.org/javiercejudo/linear-presets-volume) +[![Coverage Status](https://coveralls.io/repos/javiercejudo/linear-presets-volume/badge.svg?branch=master)](https://coveralls.io/r/javiercejudo/linear-presets-volume?branch=master) +[![Code Climate](https://codeclimate.com/github/javiercejudo/linear-presets-volume/badges/gpa.svg)](https://codeclimate.com/github/javiercejudo/linear-presets-volume) + +Linear presets for volume units + +## Install + + npm i linear-presets-volume + +## Presets + +Base: [Cubic metre](https://en.wikipedia.org/wiki/Cubic_metre) + +- [Millilitre](https://en.wikipedia.org/wiki/Millilitre) +- [Litre](https://en.wikipedia.org/wiki/Litre) +- [Cubic inch](https://en.wikipedia.org/wiki/Cubic_inch) +- [Cubic foot](https://en.wikipedia.org/wiki/Cubic_foot) +- [Fluid ounce (imperial and US)](https://en.wikipedia.org/wiki/Fluid_ounce) +- [Gill (imperial and US)](https://en.wikipedia.org/wiki/Gill_(unit)) +- [Pint (imperial and US liquid)](https://en.wikipedia.org/wiki/Pint) +- [Gallon (imperial and US liquid)](https://en.wikipedia.org/wiki/Gallon) +- [Dram](https://en.wikipedia.org/wiki/Dram_(unit)#Unit_of_volume) +- [Cup](https://en.wikipedia.org/wiki/Cup_(unit)) + +## Related projects + +- [linear-presets](https://github.com/javiercejudo/linear-presets): linear presets for common units. +- [linear-converter](https://github.com/javiercejudo/linear-converter): flexible linear converter. diff --git a/data/presets.json b/data/presets.json new file mode 100644 index 0000000..dd594f0 --- /dev/null +++ b/data/presets.json @@ -0,0 +1,18 @@ +{ + "cubicMetreToMillilitre": [[0, 1], [0, 1e6]], + "cubicMetreToLitre": [[0, 1], [0, 1e3]], + "cubicMetreToCubicInch": [[0, 0.000016387064], [0, 1]], + "cubicMetreToCubicFoot": [[0, 0.028316846592000004], [0, 1]], + "cubicMetreToImperialFluidOunce": [[0, 0.0000284130625], [0, 1]], + "cubicMetreToImperialGill": [[0, 0.0001420653125], [0, 1]], + "cubicMetreToImperialPint": [[0, 0.00056826125], [0, 1]], + "cubicMetreToImperialQuart": [[0, 0.0011365225], [0, 1]], + "cubicMetreToImperialGallon": [[0, 0.00454609], [0, 1]], + "cubicMetreToUSDram": [[0, 0.0000036966911953125], [0, 1]], + "cubicMetreToUSFluidOunce": [[0, 0.0000295735295625], [0, 1]], + "cubicMetreToUSGill": [[0, 0.00011829411825], [0, 1]], + "cubicMetreToUSCup": [[0, 0.0002365882365], [0, 1]], + "cubicMetreToUSPint": [[0, 0.000473176473], [0, 1]], + "cubicMetreToUSQuart": [[0, 0.000946352946], [0, 1]], + "cubicMetreToUSGallon": [[0, 0.003785411784], [0, 1]] +} diff --git a/gulpfile.js b/gulpfile.js new file mode 100644 index 0000000..4796c05 --- /dev/null +++ b/gulpfile.js @@ -0,0 +1,28 @@ +var gulp = require('gulp'); +var mocha = require('gulp-mocha'); +var istanbul = require('gulp-istanbul'); +var rimraf = require('rimraf'); +var coveralls = require('gulp-coveralls'); + +gulp.task('clean', function (cb) { + rimraf('./coverage', cb); +}); + +gulp.task('instrument', function () { + return gulp.src(['src/*.js']) + .pipe(istanbul()) + .pipe(istanbul.hookRequire()); +}); + +gulp.task('test', ['clean', 'instrument'], function () { + return gulp.src(['test/*.js']) + .pipe(mocha()) + .pipe(istanbul.writeReports()); +}); + +gulp.task('coveralls', function () { + gulp.src('coverage/lcov.info') + .pipe(coveralls()); +}); + +gulp.task('default', ['test']); diff --git a/package.json b/package.json new file mode 100644 index 0000000..7a6a7e1 --- /dev/null +++ b/package.json @@ -0,0 +1,35 @@ +{ + "name": "linear-presets-volume", + "version": "0.0.0", + "description": "Linear presets for volume units", + "main": "src/linear-presets-volume.js", + "scripts": { + "test": "gulp test" + }, + "repository": { + "type": "git", + "url": "https://github.com/javiercejudo/linear-presets-volume" + }, + "keywords": [ + "linear-presets", + "conversion", + "volume", + "scales" + ], + "author": "Javier Cejudo", + "license": "MIT", + "bugs": { + "url": "https://github.com/javiercejudo/linear-presets-volume/issues" + }, + "homepage": "https://github.com/javiercejudo/linear-presets-volume", + "devDependencies": { + "floating-adapter": "^1.0.0", + "gulp": "^3.8.11", + "gulp-coveralls": "^0.1.3", + "gulp-istanbul": "^0.6.0", + "gulp-mocha": "^2.0.0", + "rescale": "^6.1.0", + "rimraf": "^2.3.2", + "should": "^5.0.0" + } +} diff --git a/src/linear-presets-volume.js b/src/linear-presets-volume.js new file mode 100644 index 0000000..8129077 --- /dev/null +++ b/src/linear-presets-volume.js @@ -0,0 +1,5 @@ +/*jshint node:true */ + +'use strict'; + +module.exports = require('../data/presets.json'); diff --git a/test/presets.js b/test/presets.js new file mode 100644 index 0000000..0df07af --- /dev/null +++ b/test/presets.js @@ -0,0 +1,54 @@ +/*jshint node:true, mocha:true */ + +'use strict'; + +require('should'); + +var rescale = require('rescale')(require('floating-adapter')).rescale; +var volume = require('../src/linear-presets-volume'); + +function convert(x, preset) { + return rescale(x, preset[0], preset[1]); +}; + +function invert(preset) { + return preset.slice(0).reverse(); +}; + +describe('volume presets', function() { + it('should convert correctly', function() { + (Math.PI * 4 / 3).should.be.exactly(convert(1e+6 * Math.PI * 4 / 3, invert(volume.cubicMetreToMillilitre)), 'cubicMetreToMillilitre') + .and.exactly(convert(1e3 * Math.PI * 4 / 3, invert(volume.cubicMetreToLitre)), 'cubicMetreToLitre') + .and.exactly(convert(255615.66152340596, invert(volume.cubicMetreToCubicInch)), 'cubicMetreToCubicInch') + .and.exactly(convert(147.9257300482673, invert(volume.cubicMetreToCubicFoot)), 'cubicMetreToCubicFoot') + .and.exactly(convert(147424.80522071107, invert(volume.cubicMetreToImperialFluidOunce)), 'cubicubicMetreToCubicFootcMetreToImperialFluidOunce') + .and.exactly(convert(29484.96104414222, invert(volume.cubicMetreToImperialGill)), 'cubicMetreToImperialGill') + .and.exactly(convert(7371.240261035554, invert(volume.cubicMetreToImperialPint)), 'cubicMetreToImperialPint') + .and.exactly(convert(3685.6201305177774, invert(volume.cubicMetreToImperialQuart)), 'cubicMetreToImperialQuart') + .and.exactly(convert(921.4050326294443, invert(volume.cubicMetreToImperialGallon)), 'cubicMetreToImperialGallon') + .and.exactly(convert(1133118.7766232367, invert(volume.cubicMetreToUSDram)), 'cubicMetreToUSDram') + .and.exactly(convert(141639.8470779046, invert(volume.cubicMetreToUSFluidOunce)), 'cubicMetreToUSFluidOunce') + .and.exactly(convert(35409.96176947615, invert(volume.cubicMetreToUSGill)), 'cubicMetreToUSGill') + .and.exactly(convert(17704.980884738074, invert(volume.cubicMetreToUSCup)), 'cubicMetreToUSCup') + .and.exactly(convert(8852.490442369037, invert(volume.cubicMetreToUSPint)), 'cubicMetreToUSPint') + .and.exactly(convert(4426.245221184518, invert(volume.cubicMetreToUSQuart)), 'cubicMetreToUSQuart') + .and.exactly(convert(1106.5613052961296, invert(volume.cubicMetreToUSGallon)), 'cubicMetreToUSGallon'); + + (0).should.be.exactly(convert(0, volume.cubicMetreToMillilitre), 'cubicMetreToMillilitre') + .and.exactly(convert(0, volume.cubicMetreToLitre), 'cubicMetreToLitre') + .and.exactly(convert(0, volume.cubicMetreToCubicInch), 'cubicMetreToCubicInch') + .and.exactly(convert(0, volume.cubicMetreToCubicFoot), 'cubicMetreToCubicFoot') + .and.exactly(convert(0, volume.cubicMetreToImperialFluidOunce), 'cubicMetreToImperialFluidOunce') + .and.exactly(convert(0, volume.cubicMetreToImperialGill), 'cubicMetreToImperialGill') + .and.exactly(convert(0, volume.cubicMetreToImperialPint), 'cubicMetreToImperialPint') + .and.exactly(convert(0, volume.cubicMetreToImperialQuart), 'cubicMetreToImperialQuart') + .and.exactly(convert(0, volume.cubicMetreToImperialGallon), 'cubicMetreToImperialGallon') + .and.exactly(convert(0, volume.cubicMetreToUSDram), 'cubicMetreToUSDram') + .and.exactly(convert(0, volume.cubicMetreToUSFluidOunce), 'cubicMetreToUSFluidOunce') + .and.exactly(convert(0, volume.cubicMetreToUSGill), 'cubicMetreToUSGill') + .and.exactly(convert(0, volume.cubicMetreToUSCup), 'cubicMetreToUSCup') + .and.exactly(convert(0, volume.cubicMetreToUSPint), 'cubicMetreToUSPint') + .and.exactly(convert(0, volume.cubicMetreToUSQuart), 'cubicMetreToUSQuart') + .and.exactly(convert(0, volume.cubicMetreToUSGallon), 'cubicMetreToUSGallon'); + }); +});