From 41638aeb7ea8730adfec039a6fd29a1f2a9281b5 Mon Sep 17 00:00:00 2001 From: Javier Cejudo Date: Tue, 10 Nov 2015 23:37:27 +1100 Subject: [PATCH] first commit --- .gitignore | 29 +++++++++++++++++++++++++++++ .travis.yml | 9 +++++++++ LICENSE | 22 ++++++++++++++++++++++ README.md | 27 +++++++++++++++++++++++++++ gulpfile.js | 28 ++++++++++++++++++++++++++++ package.json | 41 +++++++++++++++++++++++++++++++++++++++++ src/index.js | 9 +++++++++ test/spec.js | 16 ++++++++++++++++ 8 files changed, 181 insertions(+) create mode 100644 .gitignore create mode 100644 .travis.yml create mode 100644 LICENSE create mode 100644 README.md create mode 100644 gulpfile.js create mode 100644 package.json create mode 100644 src/index.js create mode 100644 test/spec.js 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..80dd0d6 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,9 @@ +language: node_js +node_js: + - 'stable' + - '0.12' + - '0.10' +before_install: + - npm install -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..ad9916a --- /dev/null +++ b/README.md @@ -0,0 +1,27 @@ +# mod-arbitrary-precision + +[![Build Status](https://travis-ci.org/javiercejudo/mod-arbitrary-precision.svg)](https://travis-ci.org/javiercejudo/mod-arbitrary-precision) +[![Coverage Status](https://coveralls.io/repos/javiercejudo/mod-arbitrary-precision/badge.svg?branch=master)](https://coveralls.io/r/javiercejudo/mod-arbitrary-precision?branch=master) +[![Code Climate](https://codeclimate.com/github/javiercejudo/mod-arbitrary-precision/badges/gpa.svg)](https://codeclimate.com/github/javiercejudo/mod-arbitrary-precision) + +mod abstraction to extend [core-arbitrary-precision](https://github.com/javiercejudo/core-arbitrary-precision/) + +## Install + + npm i mod-arbitrary-precision + +## Adapters + +- [[adapter]](https://github.com/javiercejudo/floating-adapter) [[lib]](https://github.com/javiercejudo/floating) floating + +## Usage + +```js +var adapter = require('floating-adapter'); + +var Decimal = require('mod-arbitrary-precision')(require('linear-arbitrary-precision')(adapter)); + +new Decimal('12').mod(new Decimal('5')).valueOf(); // => 2 +``` + +See [spec](test/spec.js). 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..6a2f56a --- /dev/null +++ b/package.json @@ -0,0 +1,41 @@ +{ + "name": "mod-arbitrary-precision", + "version": "0.0.0", + "description": "mod abstraction to extend core-arbitrary-precision", + "main": "src/index.js", + "scripts": { + "test": "gulp test" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/javiercejudo/mod-arbitrary-precision.git" + }, + "keywords": [ + "feature scaling", + "normalisation", + "normalization", + "scale", + "rescale" + ], + "author": "Javier Cejudo (http://www.javiercejudo.com)", + "license": "MIT", + "bugs": { + "url": "https://github.com/javiercejudo/mod-arbitrary-precision/issues" + }, + "homepage": "https://github.com/javiercejudo/mod-arbitrary-precision#readme", + "devDependencies": { + "core-arbitrary-precision": "^1.0.1", + "floating": "^1.3.1", + "floating-adapter": "^1.3.0", + "gulp": "^3.9.0", + "gulp-coverage": "^0.3.38", + "gulp-coveralls": "^0.1.4", + "gulp-istanbul": "^0.10.2", + "gulp-mocha": "^2.1.3", + "rimraf": "^2.4.3", + "should": "^7.1.1" + }, + "dependencies": { + "binary-op-arbitrary-precision": "^1.1.4" + } +} diff --git a/src/index.js b/src/index.js new file mode 100644 index 0000000..ff04d3b --- /dev/null +++ b/src/index.js @@ -0,0 +1,9 @@ +/*jshint node:true */ + +'use strict'; + +var binaryOpExtender = require('binary-op-arbitrary-precision'); + +module.exports = function factory(Decimal) { + return binaryOpExtender(Decimal, 'mod'); +}; diff --git a/test/spec.js b/test/spec.js new file mode 100644 index 0000000..394380c --- /dev/null +++ b/test/spec.js @@ -0,0 +1,16 @@ +/*jshint node:true, mocha:true */ + +'use strict'; + +require('should'); + +var adapter = require('floating-adapter'); +var Decimal = require('core-arbitrary-precision')(adapter); + +Decimal = require('../src/')(Decimal); + +describe('sqrt', function() { + it('should give the remainder of the division', function() { + new Decimal('12').mod(new Decimal('5')).valueOf().should.be.exactly(2); + }); +});