From 014b4bcaa3aeedaa997c0f23583dfd6039e9a03c Mon Sep 17 00:00:00 2001 From: David Kosmos Date: Mon, 12 Feb 2018 14:42:45 -0800 Subject: [PATCH 1/8] Basic files created --- lab-david/index.js | 0 lab-david/lib/arithmetic.js | 0 lab-david/lib/greet.js | 0 lab-david/test/arithmetic-test.js | 0 lab-david/test/greet-test.js | 0 5 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 lab-david/index.js create mode 100644 lab-david/lib/arithmetic.js create mode 100644 lab-david/lib/greet.js create mode 100644 lab-david/test/arithmetic-test.js create mode 100644 lab-david/test/greet-test.js diff --git a/lab-david/index.js b/lab-david/index.js new file mode 100644 index 0000000..e69de29 diff --git a/lab-david/lib/arithmetic.js b/lab-david/lib/arithmetic.js new file mode 100644 index 0000000..e69de29 diff --git a/lab-david/lib/greet.js b/lab-david/lib/greet.js new file mode 100644 index 0000000..e69de29 diff --git a/lab-david/test/arithmetic-test.js b/lab-david/test/arithmetic-test.js new file mode 100644 index 0000000..e69de29 diff --git a/lab-david/test/greet-test.js b/lab-david/test/greet-test.js new file mode 100644 index 0000000..e69de29 From f721ad7b8f7283c428d4b4b610b933257882b507 Mon Sep 17 00:00:00 2001 From: David Kosmos Date: Mon, 12 Feb 2018 15:49:25 -0800 Subject: [PATCH 2/8] finished greet module --- lab-david/index.js | 6 ++++++ lab-david/lib/greet.js | 10 ++++++++++ 2 files changed, 16 insertions(+) diff --git a/lab-david/index.js b/lab-david/index.js index e69de29..0d46e59 100644 --- a/lab-david/index.js +++ b/lab-david/index.js @@ -0,0 +1,6 @@ +'use strict'; + +const greet = require('./lib/greet.js'); + +greet(2348); +greet('David'); \ No newline at end of file diff --git a/lab-david/lib/greet.js b/lab-david/lib/greet.js index e69de29..8006a22 100644 --- a/lab-david/lib/greet.js +++ b/lab-david/lib/greet.js @@ -0,0 +1,10 @@ +'use strict'; + +module.exports = function(name){ + if(typeof(name) !== 'string') { + console.log(null); + return null; + } + console.log(`Hello ${name}`); + return `Hello ${name}`; +} \ No newline at end of file From 7e0d674a08284afe6a10ac705fa3db0e6a5daf65 Mon Sep 17 00:00:00 2001 From: David Kosmos Date: Mon, 12 Feb 2018 15:57:52 -0800 Subject: [PATCH 3/8] finished arithmetic module --- lab-david/index.js | 7 ++++++- lab-david/lib/arithmetic.js | 21 +++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/lab-david/index.js b/lab-david/index.js index 0d46e59..56e3c22 100644 --- a/lab-david/index.js +++ b/lab-david/index.js @@ -1,6 +1,11 @@ 'use strict'; const greet = require('./lib/greet.js'); +const arithmetic = require('./lib/arithmetic.js'); greet(2348); -greet('David'); \ No newline at end of file +greet('David'); +arithmetic.add(10,10); +arithmetic.add('fool', 10); +arithmetic.sub(10, 9); +arithmetic.sub('fool', 9); \ No newline at end of file diff --git a/lab-david/lib/arithmetic.js b/lab-david/lib/arithmetic.js index e69de29..c757fe9 100644 --- a/lab-david/lib/arithmetic.js +++ b/lab-david/lib/arithmetic.js @@ -0,0 +1,21 @@ +'use strict'; + +module.exports = exports = {}; + +exports.add = function(a,b){ + if(typeof(a) !== 'number' || typeof(b) !== 'number') { + console.log(null); + return null; + } + console.log(a + b); + return a + b; +} + +exports.sub = function(a,b){ + if(typeof(a) !== 'number' || typeof(b) !== 'number'){ + console.log(null); + return null; + } + console.log(a - b); + return a - b; +} \ No newline at end of file From ef138d613fea3bb39b0f4cfc4c613e181c266e54 Mon Sep 17 00:00:00 2001 From: David Kosmos Date: Mon, 12 Feb 2018 16:13:40 -0800 Subject: [PATCH 4/8] finished arithmetic-test --- lab-david/test/arithmetic-test.js | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/lab-david/test/arithmetic-test.js b/lab-david/test/arithmetic-test.js index e69de29..5ed5911 100644 --- a/lab-david/test/arithmetic-test.js +++ b/lab-david/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('#add', function() { + it('Should add 8 to 10 to return 18', function(){ + var result = arithmetic.add(8, 10); + assert.ok(result === 18, 'Not equal to 18'); + }) + it('Should return null', function(){ + assert.throws(function(){ + arithmetic.add('not a number', 'also not a number') + }, 'Error not thrown'); + }); + }); + describe('#sub', function(){ + it('Should subtract 4 from 10 to return 6', function(){ + var result = arithmetic.sub(10,4); + assert.ok(result === 6, 'Not equal to 6'); + }); + it('Should return null', function(){ + assert.throws(function(){ + arithmetic.add('not a number', 'also not a number') + }, 'Error not thrown'); + }); + }); +}); \ No newline at end of file From c6b4a751d27b5a9022a26d85d3c2c3a31ffa887d Mon Sep 17 00:00:00 2001 From: David Kosmos Date: Mon, 12 Feb 2018 16:19:19 -0800 Subject: [PATCH 5/8] changed greet and arithmetic to throw errors rather than return null --- lab-david/lib/arithmetic.js | 10 ++-------- lab-david/lib/greet.js | 5 +---- 2 files changed, 3 insertions(+), 12 deletions(-) diff --git a/lab-david/lib/arithmetic.js b/lab-david/lib/arithmetic.js index c757fe9..fe6c362 100644 --- a/lab-david/lib/arithmetic.js +++ b/lab-david/lib/arithmetic.js @@ -3,19 +3,13 @@ module.exports = exports = {}; exports.add = function(a,b){ - if(typeof(a) !== 'number' || typeof(b) !== 'number') { - console.log(null); - return null; - } + if(typeof(a) !== 'number' || typeof(b) !== 'number') throw new Error('Those aren\'t numbers'); console.log(a + b); return a + b; } exports.sub = function(a,b){ - if(typeof(a) !== 'number' || typeof(b) !== 'number'){ - console.log(null); - return null; - } + if(typeof(a) !== 'number' || typeof(b) !== 'number') throw new Error('Those aren\'t numbers'); console.log(a - b); return a - b; } \ No newline at end of file diff --git a/lab-david/lib/greet.js b/lab-david/lib/greet.js index 8006a22..72f9f26 100644 --- a/lab-david/lib/greet.js +++ b/lab-david/lib/greet.js @@ -1,10 +1,7 @@ 'use strict'; module.exports = function(name){ - if(typeof(name) !== 'string') { - console.log(null); - return null; - } + if(typeof(name) !== 'string') throw new Error ('You didn\'t enter a string'); console.log(`Hello ${name}`); return `Hello ${name}`; } \ No newline at end of file From e0f55037d9ba228f4fc682deb64bb53fd5ab5893 Mon Sep 17 00:00:00 2001 From: David Kosmos Date: Mon, 12 Feb 2018 16:26:02 -0800 Subject: [PATCH 6/8] finished greet-test.js --- lab-david/test/greet-test.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/lab-david/test/greet-test.js b/lab-david/test/greet-test.js index e69de29..cdeaeca 100644 --- a/lab-david/test/greet-test.js +++ b/lab-david/test/greet-test.js @@ -0,0 +1,16 @@ +'use strict'; + +const greet = require('../lib/greet.js') +const assert = require('assert'); + +describe('Greet Module', function(){ + it('Should say Hello David', function(){ + var result = greet('David'); + assert.ok(result === 'Hello David', 'Doesn\'t say Hello David'); + }); + it('Should return null', function(){ + assert.throws(function(){ + greet(); + }, 'Not an error'); + }) +}) \ No newline at end of file From bbb1e9cde9f66a816b267f6236566092a8c5454d Mon Sep 17 00:00:00 2001 From: David Kosmos Date: Mon, 12 Feb 2018 16:37:04 -0800 Subject: [PATCH 7/8] cleaned up index.js and added Readme --- lab-david/README.md | 14 ++++++++++++++ lab-david/index.js | 7 ------- 2 files changed, 14 insertions(+), 7 deletions(-) create mode 100644 lab-david/README.md diff --git a/lab-david/README.md b/lab-david/README.md new file mode 100644 index 0000000..c9b7a3a --- /dev/null +++ b/lab-david/README.md @@ -0,0 +1,14 @@ +### 01-Node-Ecosystem + +Greet Module +* Single function module +* Airty of one +* Expects a string argument, otherwise it will throw an error +* Returns a string concatenating "Hello" with the entered string + +Arithmetic Module +* Two methods within module (add, sub) +* Both methods have an airty of two +* Both methods expect two number arguments, otherwise they will throw errors +* add return the sum of the two arguments +* sub returns the difference between the minuend and subtrahend diff --git a/lab-david/index.js b/lab-david/index.js index 56e3c22..673845c 100644 --- a/lab-david/index.js +++ b/lab-david/index.js @@ -2,10 +2,3 @@ const greet = require('./lib/greet.js'); const arithmetic = require('./lib/arithmetic.js'); - -greet(2348); -greet('David'); -arithmetic.add(10,10); -arithmetic.add('fool', 10); -arithmetic.sub(10, 9); -arithmetic.sub('fool', 9); \ No newline at end of file From cca6a567e497cfef5ee7685db10e77c476efbc4e Mon Sep 17 00:00:00 2001 From: David Kosmos Date: Tue, 13 Feb 2018 09:14:53 -0800 Subject: [PATCH 8/8] added config files --- lab-david/.eslintignore | 5 ++ lab-david/.eslintrc.json | 27 ++++++++ lab-david/.gitignore | 145 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 177 insertions(+) create mode 100644 lab-david/.eslintignore create mode 100644 lab-david/.eslintrc.json create mode 100644 lab-david/.gitignore diff --git a/lab-david/.eslintignore b/lab-david/.eslintignore new file mode 100644 index 0000000..82ff623 --- /dev/null +++ b/lab-david/.eslintignore @@ -0,0 +1,5 @@ +**/node_modules/* +**/vendor/* +**/*.min.js +**/coverage/* +**/build/* \ No newline at end of file diff --git a/lab-david/.eslintrc.json b/lab-david/.eslintrc.json new file mode 100644 index 0000000..3fe56a5 --- /dev/null +++ b/lab-david/.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"] + } + } \ No newline at end of file diff --git a/lab-david/.gitignore b/lab-david/.gitignore new file mode 100644 index 0000000..e24c600 --- /dev/null +++ b/lab-david/.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 \ No newline at end of file