week1 gr01-02

This commit is contained in:
lecture 2016-11-03 14:35:56 +01:00
parent 4081c3df16
commit 68c1b99fcd
9 changed files with 281 additions and 0 deletions

26
.gitignore vendored Normal file
View File

@ -0,0 +1,26 @@
*.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

44
week1/person-gr01/.gitignore vendored Normal file
View File

@ -0,0 +1,44 @@
# Logs
logs
*.log
npm-debug.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
# node-waf configuration
.lock-wscript
# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release
# Dependency directories
node_modules
jspm_packages
# Optional npm cache directory
.npm
# Optional eslint cache
.eslintcache
# Optional REPL history
.node_repl_history
# Output of 'npm pack'
*.tgz

9
week1/person-gr01/README Normal file
View File

@ -0,0 +1,9 @@
Usage: person [options]
Options:
-h, --help output usage information
-V, --version output the version number
-n, --name [value] Name of the person to match

View File

@ -0,0 +1,14 @@
{
"name": "person",
"version": "1.0.0",
"description": "find person from database",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "gauthier",
"license": "ISC",
"dependencies": {
"commander": "^2.9.0"
}
}

View File

@ -0,0 +1,61 @@
/*
file: person.js
desc: simple script that matches incoming arguments (--name)
with a simple database
author: gauthier
date: 03/11/16
*/
// import 'commander' (https://www.npmjs.com/package/commander)
var program = require('commander');
// database of persons
var person1_name = "Maurice";
var person1_age = 83;
var person1_lan = "french";
var person2_name = "Lotte";
var person2_age = 32;
var person2_lan = "danish";
var person3_name = "Geert";
var person3_age = 42;
var person3_lan = "dutch";
// initialise program (aka commander)
program
.version('0.0.1')
.option('-n, --name [value]', 'Name of the person to match', 'empty') // add option --name with default value "empty"
.parse(process.argv);
// check what the value of name is regardless of if it matches or not
console.log(program.name); // this line can be commented out
// match value of input's "name" argument
switch(program.name)
{
case person1_name:
// input match person1
console.log(person1_name);
console.log(person1_age);
console.log(person1_lan);
break;
case person2_name:
// input match person2
console.log(person2_name);
console.log(person2_age);
console.log(person2_lan);
break;
case person3_name:
// input match person3
console.log(person3_name);
console.log(person3_age);
console.log(person3_lan);
break;
default:
// default message if no match
console.log('No match...');
break;
}

44
week1/person-gr02/.gitignore vendored Normal file
View File

@ -0,0 +1,44 @@
# Logs
logs
*.log
npm-debug.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
# node-waf configuration
.lock-wscript
# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release
# Dependency directories
node_modules
jspm_packages
# Optional npm cache directory
.npm
# Optional eslint cache
.eslintcache
# Optional REPL history
.node_repl_history
# Output of 'npm pack'
*.tgz

9
week1/person-gr02/README Normal file
View File

@ -0,0 +1,9 @@
Usage: person [options]
Options:
-h, --help output usage information
-V, --version output the version number
-n, --name [string] Name of the person to match

View File

@ -0,0 +1,14 @@
{
"name": "person",
"version": "1.0.0",
"description": "select person from database",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "gauthier",
"license": "ISC",
"dependencies": {
"commander": "^2.9.0"
}
}

View File

@ -0,0 +1,60 @@
/*
file: person.js
desc: simple script that matches incoming arguments (--name)
with a simple database
author: gauthier
date: 03/11/16
*/
// import 'commander' (https://www.npmjs.com/package/commander)
var program = require('commander');
// database of persons
var person1_name = "James";
var person1_age = 25;
var person1_lan = "english";
var person2_name = "Rita";
var person2_age = 7;
var person2_lan = "danish";
var person3_name = "Geert";
var person3_age = 51;
var person3_lan = "dutch";
// initialise program (aka commander)
program
.version('0.1')
.option('-n, --name [string]', 'Name of the person to match', 'empty') // add option --name with default value "empty"
.parse(process.argv);
// check what the value of name is regardless of if it matches or not
console.log(program.name); // this line can be commented out
// match value of input's "name" argument
switch(program.name)
{
case person1_name:
// input match person1
console.log(person1_name); // print name
console.log(person1_age); // print age
console.log(person1_lan); // print language
break;
case person2_name:
// input match person2
console.log(person2_name);
console.log(person2_age);
console.log(person2_lan);
break;
case person3_name:
// input match person3
console.log(person3_name);
console.log(person3_age);
console.log(person3_lan);
break;
default:
// default message if no match
console.log('...');
break;
}