diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..8e74bf3 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,11 @@ +root = true + +[*] +indent_style = tab +end_of_line = lf +charset = utf-8 +trim_trailing_whitespace = true +insert_final_newline = true + +[*.md] +trim_trailing_whitespace = false \ No newline at end of file diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..176a458 --- /dev/null +++ b/.gitattributes @@ -0,0 +1 @@ +* text=auto diff --git a/.jshintignore b/.jshintignore new file mode 100644 index 0000000..3163c22 --- /dev/null +++ b/.jshintignore @@ -0,0 +1,14 @@ + +# Directories # +############### +build/ +reports/ +dist/ + +# Node.js # +########### +/node_modules/ + +# Git # +####### +.git* diff --git a/.jshintrc b/.jshintrc new file mode 100644 index 0000000..d09f1fa --- /dev/null +++ b/.jshintrc @@ -0,0 +1,71 @@ +{ + "bitwise": false, + "camelcase": false, + "curly": true, + "eqeqeq": true, + "es3": false, + "forin": true, + "freeze": true, + "immed": true, + "indent": 4, + "latedef": "nofunc", + "newcap": true, + "noarg": true, + "noempty": false, + "nonbsp": true, + "nonew": true, + "plusplus": false, + "quotmark": "single", + "undef": true, + "unused": true, + "strict": true, + "maxparams": 10, + "maxdepth": 5, + "maxstatements": 100, + "maxcomplexity": false, + "maxlen": 1000, + "asi": false, + "boss": false, + "debug": false, + "eqnull": false, + "esnext": false, + "evil": false, + "expr": false, + "funcscope": false, + "globalstrict": false, + "iterator": false, + "lastsemic": false, + "laxbreak": false, + "laxcomma": false, + "loopfunc": false, + "maxerr": 1000, + "moz": false, + "multistr": false, + "notypeof": false, + "proto": false, + "scripturl": false, + "shadow": false, + "sub": true, + "supernew": false, + "validthis": false, + "noyield": false, + "browser": true, + "browserify": true, + "couch": false, + "devel": true, + "dojo": false, + "jasmine": false, + "jquery": false, + "mocha": true, + "mootools": false, + "node": true, + "nonstandard": false, + "prototypejs": false, + "qunit": false, + "rhino": false, + "shelljs": false, + "worker": false, + "wsh": false, + "yui": false, + "globals": {} +} \ No newline at end of file diff --git a/.npmignore b/.npmignore index 42781b3..9db298d 100644 --- a/.npmignore +++ b/.npmignore @@ -13,6 +13,7 @@ examples/ reports/ support/ test/ +benchmark/ # Node.js # ########### @@ -46,4 +47,6 @@ Desktop.ini # Utilities # ############# .jshintrc -.travis.yml \ No newline at end of file +.jshintignore +.travis.yml +.editorconfig diff --git a/.travis.yml b/.travis.yml index 7c16620..29cff27 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,12 @@ language: node_js node_js: - - "0.10" + - '0.12' + - '0.11' + - '0.10' + - '0.8' + - 'iojs' +before_install: + - npm update -g npm after_script: - - npm run coveralls \ No newline at end of file + - npm run coveralls + diff --git a/LICENSE b/LICENSE index 2fe3939..4a8092e 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ The MIT License (MIT) -Copyright (c) 2014 Athan Reines. +Copyright (c) 2014-2015 The Compute.io Authors. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -18,4 +18,4 @@ 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. \ No newline at end of file +SOFTWARE. diff --git a/Makefile b/Makefile index e3cad30..3234fbb 100644 --- a/Makefile +++ b/Makefile @@ -5,25 +5,29 @@ # Set the node.js environment to test: NODE_ENV ?= test +# Kernel name: +KERNEL ?= $(shell uname -s) + +ifeq ($(KERNEL), Darwin) + OPEN ?= open +else + OPEN ?= xdg-open +endif # NOTES # -NOTES ?= 'TODO|FIXME' +NOTES ?= 'TODO|FIXME|WARNING|HACK|NOTE' # MOCHA # -# Specify the test framework bin locations: MOCHA ?= ./node_modules/.bin/mocha _MOCHA ?= ./node_modules/.bin/_mocha - -# Specify the mocha reporter: MOCHA_REPORTER ?= spec # ISTANBUL # -# Istanbul configuration: ISTANBUL ?= ./node_modules/.bin/istanbul ISTANBUL_OUT ?= ./reports/coverage ISTANBUL_REPORT ?= lcov @@ -31,6 +35,12 @@ ISTANBUL_LCOV_INFO_PATH ?= $(ISTANBUL_OUT)/lcov.info ISTANBUL_HTML_REPORT_PATH ?= $(ISTANBUL_OUT)/lcov-report/index.html +# JSHINT # + +JSHINT ?= ./node_modules/.bin/jshint +JSHINT_REPORTER ?= ./node_modules/jshint-stylish/stylish.js + + # FILES # @@ -81,7 +91,8 @@ test-istanbul-mocha: node_modules NODE_ENV=$(NODE_ENV) \ NODE_PATH=$(NODE_PATH_TEST) \ $(ISTANBUL) cover \ - --dir $(ISTANBUL_OUT) --report $(ISTANBUL_REPORT) \ + --dir $(ISTANBUL_OUT) \ + --report $(ISTANBUL_REPORT) \ $(_MOCHA) -- \ --reporter $(MOCHA_REPORTER) \ $(TESTS) @@ -95,9 +106,20 @@ test-istanbul-mocha: node_modules view-cov: view-istanbul-report view-istanbul-report: - open $(ISTANBUL_HTML_REPORT_PATH) + $(OPEN) $(ISTANBUL_HTML_REPORT_PATH) +# LINT # + +.PHONY: lint lint-jshint + +lint: lint-jshint + +lint-jshint: node_modules + $(JSHINT) \ + --reporter $(JSHINT_REPORTER) \ + ./ + # NODE # @@ -116,7 +138,6 @@ clean-node: # CLEAN # - .PHONY: clean clean: diff --git a/README.md b/README.md index f9cfd63..9e0be6c 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,6 @@ For use in the browser, use [browserify](https://github.com/substack/node-browse ## Usage -To use the module, ``` javascript var hypot = require( 'compute-hypot' ); @@ -26,6 +25,8 @@ var hypot = require( 'compute-hypot' ); ## Examples ``` javascript +var hypot = require( 'compute-hypot' ); + var a = 10, b = 12; @@ -58,7 +59,7 @@ An alternative [approach](http://www.johndcook.com/blog/2010/06/02/whats-so-hard ### Unit -Unit tests use the [Mocha](http://visionmedia.github.io/mocha) test framework with [Chai](http://chaijs.com) assertions. To run the tests, execute the following command in the top-level application directory: +Unit tests use the [Mocha](http://mochajs.org) test framework with [Chai](http://chaijs.com) assertions. To run the tests, execute the following command in the top-level application directory: ``` bash $ make test @@ -78,19 +79,19 @@ $ make test-cov Istanbul creates a `./reports/coverage` directory. To access an HTML version of the report, ``` bash -$ open reports/coverage/lcov-report/index.html +$ make view-cov ``` +--- ## License -[MIT license](http://opensource.org/licenses/MIT). +[MIT license](http://opensource.org/licenses/MIT). ---- ## Copyright -Copyright © 2014. Athan Reines. +Copyright © 2014-2015. The Compute.io Authors. [npm-image]: http://img.shields.io/npm/v/compute-hypot.svg @@ -109,4 +110,4 @@ Copyright © 2014. Athan Reines. [dev-dependencies-url]: https://david-dm.org/dev/compute-io/hypot [github-issues-image]: http://img.shields.io/github/issues/compute-io/hypot.svg -[github-issues-url]: https://github.com/compute-io/hypot/issues \ No newline at end of file +[github-issues-url]: https://github.com/compute-io/hypot/issues diff --git a/examples/index.js b/examples/index.js index f9a9aa4..a7c2cc1 100644 --- a/examples/index.js +++ b/examples/index.js @@ -1,6 +1,8 @@ +'use strict'; + var hypot = require( './../lib' ); var a = 10, b = 12; -console.log( hypot( a, b ) ); \ No newline at end of file +console.log( hypot( a, b ) ); diff --git a/lib/index.js b/lib/index.js index 84d1ccf..b8dfff2 100644 --- a/lib/index.js +++ b/lib/index.js @@ -1,70 +1,39 @@ -/** -* -* COMPUTE: hypot -* -* -* DESCRIPTION: -* - Computes the hypotenuse of a right triangle. -* -* -* NOTES: -* [1] Based on http://www.johndcook.com/blog/2010/06/02/whats-so-hard-about-finding-a-hypotenuse/ . -* -* -* TODO: -* [1] -* -* -* LICENSE: -* MIT -* -* Copyright (c) 2014. Athan Reines. -* -* -* AUTHOR: -* Athan Reines. kgryte@gmail.com. 2014. -* -*/ - -(function() { - 'use strict'; - - // MODULES // - - var isNumeric = require( 'validate.io-number' ); +'use strict'; +// MODULES // - // HYPOT // +var isNumeric = require( 'validate.io-number' ); - /** - * FUNCTION: hypot( a, b ) - * Computes the hypotenuse of a right triangle. - * - * @param {Number} a - length of one side of triangle - * @param {Number} b - length of other side of a triangle - * @returns {Number} hypotenuse - */ - function hypot( a, b ) { - if ( !isNumeric( a ) || !isNumeric( b ) ) { - throw new TypeError( 'hypot()::invalid input argument. Input arguments must be numeric.' ); - } - var min, max, r; - a = Math.abs( a ); - b = Math.abs( b ); - if ( a > b ) { - min = b; - max = a; - } else { - min = a; - max = b; - } - r = min / max; - return max * Math.sqrt( 1 + r*r ); - } // end FUNCTION hypot() +// HYPOT // - // EXPORTS // - - module.exports = hypot; - -})(); \ No newline at end of file +/** +* FUNCTION: hypot( a, b ) +* Computes the hypotenuse of a right triangle. +* +* @param {Number} a - length of one side of triangle +* @param {Number} b - length of other side of a triangle +* @returns {Number} hypotenuse +*/ +function hypot( a, b ) { + if ( !isNumeric( a ) || !isNumeric( b ) ) { + throw new TypeError( 'hypot()::invalid input argument. Input arguments must be numeric.' ); + } + var min, max, r; + a = Math.abs( a ); + b = Math.abs( b ); + if ( a > b ) { + min = b; + max = a; + } else { + min = a; + max = b; + } + r = min / max; + return max * Math.sqrt( 1 + r*r ); +} // end FUNCTION hypot() + + +// EXPORTS // + +module.exports = hypot; diff --git a/package.json b/package.json index d4600a7..c48af41 100644 --- a/package.json +++ b/package.json @@ -10,6 +10,10 @@ { "name": "Athan Reines", "email": "kgryte@gmail.com" + }, + { + "name": "Philipp Burckhardt", + "email": "pburckhardt@outlook.com" } ], "scripts": { @@ -36,15 +40,10 @@ "validate.io-number": "^1.0.0" }, "devDependencies": { - "chai": "1.x.x", - "mocha": "1.x.x", + "chai": "2.x.x", + "mocha": "2.x.x", "coveralls": "^2.11.1", "istanbul": "^0.3.0" }, - "licenses": [ - { - "type": "MIT", - "url": "http://www.opensource.org/licenses/MIT" - } - ] + "license": "MIT" } diff --git a/test/test.js b/test/test.js index f61eb49..d74be86 100644 --- a/test/test.js +++ b/test/test.js @@ -1,3 +1,5 @@ +/* global require, describe, it */ +'use strict'; // MODULES // @@ -17,7 +19,6 @@ var expect = chai.expect, // TESTS // describe( 'compute-hypot', function tests() { - 'use strict'; it( 'should export a function', function test() { expect( hypot ).to.be.a( 'function' ); @@ -56,4 +57,4 @@ describe( 'compute-hypot', function tests() { assert.strictEqual( hypot( 8, 6 ), 10 ); }); -}); \ No newline at end of file +});