Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions lab-david/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
**/node_modules/*
**/vendor/*
**/*.min.js
**/coverage/*
**/build/*
27 changes: 27 additions & 0 deletions lab-david/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -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"]
}
}
145 changes: 145 additions & 0 deletions lab-david/.gitignore
Original file line number Diff line number Diff line change
@@ -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
14 changes: 14 additions & 0 deletions lab-david/README.md
Original file line number Diff line number Diff line change
@@ -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
4 changes: 4 additions & 0 deletions lab-david/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
'use strict';

const greet = require('./lib/greet.js');
const arithmetic = require('./lib/arithmetic.js');
15 changes: 15 additions & 0 deletions lab-david/lib/arithmetic.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
'use strict';

module.exports = exports = {};

exports.add = function(a,b){
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') throw new Error('Those aren\'t numbers');
console.log(a - b);
return a - b;
}
7 changes: 7 additions & 0 deletions lab-david/lib/greet.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
'use strict';

module.exports = function(name){
if(typeof(name) !== 'string') throw new Error ('You didn\'t enter a string');
console.log(`Hello ${name}`);
return `Hello ${name}`;
}
29 changes: 29 additions & 0 deletions lab-david/test/arithmetic-test.js
Original file line number Diff line number Diff line change
@@ -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');
});
});
});
16 changes: 16 additions & 0 deletions lab-david/test/greet-test.js
Original file line number Diff line number Diff line change
@@ -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');
})
})