diff --git a/.eslintignore b/.eslintignore new file mode 100644 index 0000000..05b1cf3 --- /dev/null +++ b/.eslintignore @@ -0,0 +1,5 @@ +**/node_modules/* +**/vendor/* +**/*.min.js +**/coverage/* +**/build/* diff --git a/.eslintrc b/.eslintrc new file mode 100644 index 0000000..8dc6807 --- /dev/null +++ b/.eslintrc @@ -0,0 +1,21 @@ +{ + "rules": { + "no-console": "off", + "indent": [ "error", 2 ], + "quotes": [ "error", "single" ], + "semi": ["error", "always"], + "linebreak-style": [ "error", "unix" ] + }, + "env": { + "es6": true, + "node": true, + "mocha": true, + "jasmine": true + }, + "ecmaFeatures": { + "modules": true, + "experimentalObjectRestSpread": true, + "impliedStrict": true + }, + "extends": "eslint:recommended" +} diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..345130c --- /dev/null +++ b/.gitignore @@ -0,0 +1,136 @@ +# Created by https://www.gitignore.io/api/osx,vim,node,macos,windows + +### macOS ### +*.DS_Store +.AppleDouble +.LSOverride + +# Icon must end with two \r +Icon + +# Thumbnails +._* + +# Files that might appear in the root of a volume +.DocumentRevisions-V100 +.fseventsd +.Spotlight-V100 +.TemporaryItems +.Trashes +.VolumeIcon.icns +.com.apple.timemachine.donotpresent + +# Directories potentially created on remote AFP share +.AppleDB +.AppleDesktop +Network Trash Folder +Temporary Items +.apdisk + +### Node ### +# Logs +logs +*.log +npm-debug.log* +yarn-debug.log* +yarn-error.log* + +# Runtime data +pids +*.pid +*.seed +*.pid.lock + +# Directory for instrumented libs generated by jscoverage/JSCover +lib-cov + +# Coverage directory used by tools like istanbul +coverage + +# nyc test coverage +.nyc_output + +# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) +.grunt + +# Bower dependency directory (https://bower.io/) +bower_components + +# node-waf configuration +.lock-wscript + +# Compiled binary addons (http://nodejs.org/api/addons.html) +build/Release + +# Dependency directories +node_modules/ +jspm_packages/ + +# Typescript v1 declaration files +typings/ + +# Optional npm cache directory +.npm + +# Optional eslint cache +.eslintcache + +# Optional REPL history +.node_repl_history + +# Output of 'npm pack' +*.tgz + +# Yarn Integrity file +.yarn-integrity + +# dotenv environment variables file +.env + + +### OSX ### + +# Icon must end with two \r + +# Thumbnails + +# Files that might appear in the root of a volume + +# Directories potentially created on remote AFP share + +### Vim ### +# swap +[._]*.s[a-v][a-z] +[._]*.sw[a-p] +[._]s[a-v][a-z] +[._]sw[a-p] +# session +Session.vim +# temporary +.netrwhist +*~ +# auto-generated tag files +tags + +### Windows ### +# Windows thumbnail cache files +Thumbs.db +ehthumbs.db +ehthumbs_vista.db + +# Folder config file +Desktop.ini + +# Recycle Bin used on file shares +$RECYCLE.BIN/ + +# Windows Installer files +*.cab +*.msi +*.msm +*.msp + +# Windows shortcuts +*.lnk + +# End of https://www.gitignore.io/api/osx,vim,node,macos,windows diff --git a/README.md b/README.md index a3aca54..297a50f 100644 --- a/README.md +++ b/README.md @@ -57,3 +57,7 @@ * 3pts feature tasks * 3pts tests * 2pts documentation + +## My README.md addition + +##### Today we created two files: one that contains a globally scoped function that takes in a string and adds hello to it, and another that contains two functions one that adds two integers and a second that subtracts the first from the second. All functions have exceptions added to them looking for inputs that are not the same type as what the function is expecting, if triggered they will return an error message, if not triggered the functions should continue as expected. Once the functions are set up we wrote tests to test various conditions like making sure the correct data type was entered or making sure the correct phrase or number is returned. diff --git a/lib/arithmetic.js b/lib/arithmetic.js new file mode 100644 index 0000000..9b89ac2 --- /dev/null +++ b/lib/arithmetic.js @@ -0,0 +1,20 @@ +'use strict'; + +// assigning exports to a empty object and assinging it to the global scope. +module.exports = exports = {}; + +// adding an add function to the exports variable. +exports.add = function(a, b){ + //checking to see if both inputs are numbers, if not stopping the function and throwing an error. + if(typeof(a) !== "number" || typeof(b) !== "number") return 'must be a number/integer'; // NOTE:(just curious if this is the way the function was supposed to fail?) throw new Error('must be a number/integer'); + // if it passes it will return the sum. + return a + b; +}; + +// adding an sub function to the exports variable. +exports.sub = function(a, b){ + //checking to see if both inputs are numbers, if not stopping the function and throwing an error. + if(typeof(a) !== "number" || typeof(b) !== "number") return 'must be a number/integer';// NOTE: throw new Error('must be a number/integer'); + // if it passes it will return the difference. + return a - b; +}; diff --git a/lib/greet.js b/lib/greet.js new file mode 100644 index 0000000..e381651 --- /dev/null +++ b/lib/greet.js @@ -0,0 +1,12 @@ +'use strict'; + +// assigning exports to a empty object and assinging it to the global scope. +module.exports = exports = {}; + +// creating a hello function and attaching it to the globally scoped exports variable. +exports.hello = function(str){ + // checking to see if there is some form of input if not returning null. + if(typeof(str) !== "string") return null; + // returns hello and the str input. + return `hello ${str}`; +}; diff --git a/package.json b/package.json new file mode 100644 index 0000000..f44c9a9 --- /dev/null +++ b/package.json @@ -0,0 +1,22 @@ +{ + "name": "01-node_ecosystem", + "version": "1.0.0", + "description": "first lab", + "main": "index.js", + "directories": { + "test": "test" + }, + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/loganabsher/01-node_ecosystem.git" + }, + "author": "", + "license": "ISC", + "bugs": { + "url": "https://github.com/loganabsher/01-node_ecosystem/issues" + }, + "homepage": "https://github.com/loganabsher/01-node_ecosystem#readme" +} diff --git a/test/arithmetic-test.js b/test/arithmetic-test.js new file mode 100644 index 0000000..b9db9bb --- /dev/null +++ b/test/arithmetic-test.js @@ -0,0 +1,53 @@ +'use strict'; + +// inporting the arithmetic file and the assert library. +const arithmetic = require('../lib/arithmetic.js'); +const assert = require('assert'); + +// creating a test named "Arithmetic Module". +describe('Arithmetic Module', function(){ + + // variables for testing. + let a = 10; + let b = 15; + let c = 'a'; + let d = true; + + // creating a sub catigory looking at the add function. + describe('#add', function(){ + + // creating the results and inputs that will be tested by both tests. + let result = arithmetic.add(a, b); + + // describing the test. + it('should return Number/Integer', function(){ + // checking to see if both values are numbers. + assert.ok(typeof(a) === "number" && typeof(b) === "number", 'must be a number'); + }); + + // describing the test. + it('should return a + b', function(){ + // seeing if the results are correct. + assert.ok(result === a + b, 'did not add correctly'); + }); + }); + + // creating a sub catigory looking at the sub function. + describe('#sub', function(){ + + // creating the results and inputs that will be tested by both tests. + let result = arithmetic.sub(a, b); + + // describing the test. + it('should return Number/Integer', function(){ + // checking to see if both values are numbers. + assert.ok(typeof(a) === "number" && typeof(b) === "number", 'must be a number'); + }); + + // describing the test. + it('should return a - b', function(){ + // seeing if the results are correct. + assert.ok(result === a - b, 'did not sub correctly'); + }); + }); +}); diff --git a/test/greet-test.js b/test/greet-test.js new file mode 100644 index 0000000..163181d --- /dev/null +++ b/test/greet-test.js @@ -0,0 +1,32 @@ +'use strict'; + +// inporting the greet file and the assert library. +const greet = require('../lib/greet.js'); +const assert = require('assert'); + +// creating a test named "Greet Module". +describe('Greet Module', function(){ + + // variables for testing. + let c = 'world!'; + let x = 'this is not world!'; + let n = true; + + // creating a sub catigory looking at the hello function. + describe('#hello', function(){ + + // describing the test. + it('should return hello world!', function(){ + // calling the hello function and passing in a value. + let result = greet.hello(c); + assert.ok(result === 'hello world!', 'not saying \"hello world!\"'); + }); + + // describing the test. + it('should return null if not string', function(){ + // calling the hello function and passing in a value. + let result = greet.hello(n); + assert.ok(result === null, 'not returning null'); + }); + }); +});