Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
javiercejudo committed Nov 16, 2015
0 parents commit fda0d4a
Show file tree
Hide file tree
Showing 8 changed files with 209 additions and 0 deletions.
29 changes: 29 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -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
9 changes: 9 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
language: node_js
node_js:
- 'iojs'
- '0.10'
- '0.12'
before_install:
- npm i -g gulp
after_success:
- gulp coveralls
22 changes: 22 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -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.

26 changes: 26 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# linear-preset-by-coefficients

[![Build Status](https://travis-ci.org/javiercejudo/linear-preset-by-coefficients.svg)](https://travis-ci.org/javiercejudo/linear-preset-by-coefficients)
[![Coverage Status](https://coveralls.io/repos/javiercejudo/linear-preset-by-coefficients/badge.svg?branch=master)](https://coveralls.io/r/javiercejudo/linear-preset-by-coefficients?branch=master)
[![Code Climate](https://codeclimate.com/github/javiercejudo/linear-preset-by-coefficients/badges/gpa.svg)](https://codeclimate.com/github/javiercejudo/linear-preset-by-coefficients)

Generate linear presets from coefficients

## Install

npm i linear-preset-by-coefficients

## Usage

```js
var Decimal = require('linear-arbitrary-precision')(require('floating-adapter'));
var preset = require('linear-preset-by-coefficients')(Decimal);

// all numbers are Decimal
preset(temp, 9/5, 32); // => [[0, 1], [32, 33.8]]
```

## 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.
28 changes: 28 additions & 0 deletions gulpfile.js
Original file line number Diff line number Diff line change
@@ -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']);
40 changes: 40 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"name": "linear-preset-by-coefficients",
"version": "0.0.0",
"description": "Generate linear presets from coefficients",
"main": "src/index.js",
"scripts": {
"test": "gulp test"
},
"repository": {
"type": "git",
"url": "https://github.com/javiercejudo/linear-preset-by-coefficients"
},
"keywords": [
"conversion",
"units"
],
"author": "Javier Cejudo",
"license": "MIT",
"bugs": {
"url": "https://github.com/javiercejudo/linear-preset-by-coefficients/issues"
},
"homepage": "https://github.com/javiercejudo/linear-preset-by-coefficients",
"devDependencies": {
"floating-adapter": "^1.2.1",
"gulp": "^3.9.0",
"gulp-coveralls": "^0.1.4",
"gulp-istanbul": "^0.10.2",
"gulp-mocha": "^2.1.3",
"linear-arbitrary-precision": "^3.1.0",
"linear-presets-temperature": "^2.0.3",
"lodash.isfunction": "^3.0.6",
"rimraf": "^2.4.3",
"should": "^7.1.1"
},
"dependencies": {
"linear-converter": "^7.0.2",
"unit-preset": "^1.0.1",
"unit-scale": "^1.0.1"
}
}
27 changes: 27 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*jshint node:true */

'use strict';

var lcFactory = require('linear-converter');
var unitScale = require('unit-scale');
var unitPreset = require('unit-preset');

module.exports = function factory(Decimal) {
var lc = lcFactory(Decimal);

return function coefficients(a, b) {
var decimalA = new Decimal(a.toString());
var decimalB = new Decimal(b.toString());

return lc.composeConversions(
[
unitScale,
[
decimalB,
decimalA.plus(decimalB)
]
],
unitPreset
);
};
};
28 changes: 28 additions & 0 deletions test/spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*jshint node:true, mocha:true */

'use strict';

require('should');

var adapter = require('floating-adapter');
var Decimal = require('linear-arbitrary-precision')(adapter);
var coefficients = require('../src/')(Decimal);
var isFunction = require('lodash.isfunction');

function scaleVals(scale) {
return scale.map(Number);
}

describe('coefficients', function() {
it('creates presets from coefficients', function() {
coefficients(9/5, 32).map(scaleVals).should.eql([[0, 1], [32, 33.8]]);
coefficients(-5, -2).map(scaleVals).should.eql([[0, 1], [-2, -7]]);
coefficients(757, -567).map(scaleVals).should.eql([[0, 1], [-567, 190]]);
});

it('creates presets with Decimals', function() {
coefficients(9/5, 32).every(function(scale) {
return [scale[0].plus, scale[1].plus].every(isFunction);
}).should.be.exactly(true);
});
});

0 comments on commit fda0d4a

Please sign in to comment.