diff --git a/lab-greg/.eslintignore b/lab-greg/.eslintignore new file mode 100644 index 0000000..05b1cf3 --- /dev/null +++ b/lab-greg/.eslintignore @@ -0,0 +1,5 @@ +**/node_modules/* +**/vendor/* +**/*.min.js +**/coverage/* +**/build/* diff --git a/lab-greg/.eslintrc.json b/lab-greg/.eslintrc.json new file mode 100644 index 0000000..886827f --- /dev/null +++ b/lab-greg/.eslintrc.json @@ -0,0 +1,27 @@ +{ + "env": { + "browser": true, + "node": true, + "commonjs": true, + "jest": true, + "es6": true + }, + "globals": { + "err": true, + "req": true, + "res": true, + "next": true + }, + "extends": "eslint:recommended", + "parserOptions": { + "sourceType": "module" + }, + "rules": { + "no-console": "off", + "indent": [ "error", 2 ], + "quotes": ["error", "single", { "allowTemplateLiterals": true }], + "comma-dangle": ["error", "always-multiline"], + "semi": [ "error", "always" ], + "linebreak-style": ["error", "unix"] + } +} diff --git a/lab-greg/.gitignore b/lab-greg/.gitignore new file mode 100644 index 0000000..4745950 --- /dev/null +++ b/lab-greg/.gitignore @@ -0,0 +1,145 @@ +# 401 JS +db +**.env +temp +build + +# Created by https://www.gitignore.io/api/vim,osx,node,linux,windows +### Linux ### +*~ + +# temporary files which can be created if a process still has a handle open of a deleted file +.fuse_hidden* + +# KDE directory preferences +.directory + +# Linux trash folder which might appear on any partition or disk +.Trash-* + +# .nfs files are created when an open file is removed but is still being accessed +.nfs* + +### 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 ### +*.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 + +### 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/vim,osx,node,linux,windows diff --git a/lab-greg/README.md b/lab-greg/README.md new file mode 100644 index 0000000..cfbfdb4 --- /dev/null +++ b/lab-greg/README.md @@ -0,0 +1,7 @@ +## +In your README.md file, describe the exported values of each module defined in your lib directory. Every function description should include it's airty (expected number of parameters), the expected data for each parameter (data-type and limitations), and the expected output behavior (for both valid and invalid use). Feel free to include any additional information that you would like. + +In my greet.js module, the exported value will be one string that reads 'hello (argument passed into the function). For example, if 'world' is passed in, the export will be 'hello world'. + +In my arithmetic.js module, there will be two exported values. One will be from the exports.add function, which will require two integer arguments. The expected return will be a sum of these two numbers. +The other exported value will be the exports.sub function. This will also require two integers as arguments and will return the difference of these two integers. \ No newline at end of file diff --git a/lab-greg/index.js b/lab-greg/index.js new file mode 100644 index 0000000..a9d3dc8 --- /dev/null +++ b/lab-greg/index.js @@ -0,0 +1,8 @@ +'use strict'; + +const greet = require('./lib/greet.js'); +const arithmetic = require('./lib/arithmetic.js'); + +greet.sayHello('world'); +arithmetic.sum(2, 3); +arithmetic.sub(4, 2); \ No newline at end of file diff --git a/lab-greg/lib/arithmetic.js b/lab-greg/lib/arithmetic.js new file mode 100644 index 0000000..ade48dc --- /dev/null +++ b/lab-greg/lib/arithmetic.js @@ -0,0 +1,26 @@ +'use strict'; + +module.exports = exports = {}; + +exports.add = function(numOne, numTwo) { + var sum; + + if(!numOne || !numTwo) throw new Error('Numbers not Provided') + sum = (numOne + numTwo); + if(typeof numOne !== 'number' || typeof numTwo !== 'number') return null; + + console.log(sum); + return sum; + +}; + +exports.sub = function(numOne, numTwo) { + var diff; + if(!numOne || !numTwo) throw new Error('Numbers not Provided') + diff = (numOne - numTwo); + if(typeof numOne !== 'number' || typeof numTwo !== 'number') return null; + + console.log(diff); + return diff; + +}; \ No newline at end of file diff --git a/lab-greg/lib/greet.js b/lab-greg/lib/greet.js new file mode 100644 index 0000000..09fe137 --- /dev/null +++ b/lab-greg/lib/greet.js @@ -0,0 +1,12 @@ +'use strict'; + +module.exports = exports = {}; + +exports.sayHello = function(name) { + if(!name) + throw new Error('name not provided'); + if(typeof name !== 'string') return null; + + return `hello ${name}`; + +}; \ No newline at end of file diff --git a/lab-greg/test/arithmetic-test.js b/lab-greg/test/arithmetic-test.js new file mode 100644 index 0000000..bca6d11 --- /dev/null +++ b/lab-greg/test/arithmetic-test.js @@ -0,0 +1,29 @@ +'use strict'; + +const arithmetic = require('../lib/arithmetic.js'); +const assert = require('assert'); + +describe('arithmetic module', function() { + describe('#sum', function() { + it('should return the sum of two numbers', function() { + var result = arithmetic.add(1, 3); + assert.ok(result === 4, 'not equal to 4'); + }); + it('should throw a missing number error', function() { + assert.throws(function() { + arithmetic.sum(); + }, 'error not thrown'); + }); + }); + describe('#sub', function() { + it('should return the difference of two numbers', function() { + var result = arithmetic.sub(4, 2); + assert.ok(result === 2, 'not equal to 2'); + }); + it('should throw a missing number error', function() { + assert.throws(function() { + arithmetic.sub(); + }, 'error not thrown'); + }); + }); +}); \ No newline at end of file diff --git a/lab-greg/test/greet-test.js b/lab-greg/test/greet-test.js new file mode 100644 index 0000000..4705d59 --- /dev/null +++ b/lab-greg/test/greet-test.js @@ -0,0 +1,21 @@ +'use strict'; + +const greet = require('../lib/greet.js'); +const assert = require('assert'); + +describe('Greet Module', function() { + describe('#sayHello', function() { + it('should return hello world', function() { + var result = greet.sayHello('world'); + assert.ok(result === 'hello world', 'not equal to hello world'); + }); + it('should throw a missing name error', function() { + assert.throws(function() { + greet.sayHello(); + }, 'error not thrown'); + }); + }); +}); + + + \ No newline at end of file