diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000..5008ddf Binary files /dev/null and b/.DS_Store differ diff --git a/README.md b/README.md deleted file mode 100644 index 61783ab..0000000 --- a/README.md +++ /dev/null @@ -1,53 +0,0 @@ -![CF](https://camo.githubusercontent.com/70edab54bba80edb7493cad3135e9606781cbb6b/687474703a2f2f692e696d6775722e636f6d2f377635415363382e706e67) 01: Node Ecosystem -=== - -## Submission Instructions -* Work in a fork of this repository. -* Work in a branch on your fork. -* Write all of your code in a directory named `lab-` + `` **e.g.** `lab-susan`. -* Open a pull request to this repository. -* Submit on canvas a question and observation, how long you spent, and a link to your pull request. -* Features without unit tests behind them will not be graded. - -## Resources -* [Jest Getting Started](https://facebook.github.io/jest/docs/en/getting-started.html) -* [Jest Globals](https://facebook.github.io/jest/docs/en/api.html#content) -* [Jest Expect](https://facebook.github.io/jest/docs/en/expect.html#content) - -## Configuration -Configure the root of your repository with the following files and directories. Thoughfully name and organize any aditional configuration or module files. -* **README.md** - contains documentation -* **.gitignore** - contains a [robust](http://gitignore.io) `.gitignore` file -* **.eslintrc** - contains the course linter configuratoin -* **.eslintignore** - contains the course linter ignore configuration -* **lib/** - contains module definitions -* **__test__/** - contains unit tests - -## Feature Tasks -#### Greet Module -Create a NodeJS module in the lib/ directory named `greet.js` that exports a single function. -* The `greet` function should have a single parameter (arity of one) that should expect a string as it's input -* The `greet` function should return the input name, concatenated with "hello ": eg. ("hello susan") -* The `greet` function should return `null` if the input is not a string - -#### Arithmetic Module -Create a NodeJS module in the lib/ directory named `arithmetic.js` that exports an object. This module should have `add` and `sub` methods that implament addition and subtraction. -* The `add` method should have an arity of two (define two paramiters) - * If either parameter is a non-number the function should return null - * Else return the sum of the 2 numbers -* The `sub` method should have an arity of two (define two paramiters) - * If either parameter is a non-number the function should return null - * Else return the second paramiter subtracted from the first paramiter - -## Testing -#### Greet Module Tests -* Write a test that expects the greet module to return `null` when you supply non string values -* Write a test the expects the greet module to return `'hello world'` - * This should happen when invoked with `'world'` as the first argument - -#### Arithmetic Module Tests -* Test each method for proper use (invoded with number arguments) -* Test each method for inproper use (invoded with one or more non-numner arguments) - -## Documentation -In your README.md describe the exported values of each module defined in your lib/ directory. Every function description should include it's airty (expected number of paramiters), the expected data for each paramiter (data-type and limitations), and it's behavior (for both valid and invalued use). Feel free to write any additional information in your README.md. diff --git a/lab-pedja/.eslintignore b/lab-pedja/.eslintignore new file mode 100644 index 0000000..05b1cf3 --- /dev/null +++ b/lab-pedja/.eslintignore @@ -0,0 +1,5 @@ +**/node_modules/* +**/vendor/* +**/*.min.js +**/coverage/* +**/build/* diff --git a/lab-pedja/.eslintrc.json b/lab-pedja/.eslintrc.json new file mode 100644 index 0000000..840d336 --- /dev/null +++ b/lab-pedja/.eslintrc.json @@ -0,0 +1,26 @@ +{ + "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" ] + } +} diff --git a/lab-pedja/.gitignore b/lab-pedja/.gitignore new file mode 100644 index 0000000..8fe2634 --- /dev/null +++ b/lab-pedja/.gitignore @@ -0,0 +1,148 @@ +# Created by https://www.gitignore.io/api/osx,vim,node,linux,windows,visualstudiocode + +### 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 + +### VisualStudioCode ### +.vscode/* +!.vscode/settings.json +!.vscode/tasks.json +!.vscode/launch.json +!.vscode/extensions.json +.history + +### 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,linux,windows,visualstudiocode diff --git a/lab-pedja/README.md b/lab-pedja/README.md new file mode 100644 index 0000000..91080d5 --- /dev/null +++ b/lab-pedja/README.md @@ -0,0 +1,22 @@ +![CF](https://camo.githubusercontent.com/70edab54bba80edb7493cad3135e9606781cbb6b/687474703a2f2f692e696d6775722e636f6d2f377635415363382e706e67) Lab class 01: Node Ecosystem +=== + +#### greet Module +NodeJS module `greet` located in the lib/ directory(`lib/greet.js`) and it exports a single function - `greet.hi`. +* The `greet.hi` function has a single parameter (arity of one) that should expect a string as it's input +* The `greet.hi` function returns the input name, concatenated with "hello ": eg. ("hello world") +* The `greet.hi` function returns `null` if the input is not a string. + +#### arithmetic Module +NodeJS module `arithmetic` located in the lib/ directory (`lib/arithmetic.js`) and it exports an object. This module has `add` and `sub` methods that implement addition and subtraction. +* The `add` method takes two parameters; + * If either parameter is a non-number the function returns `null` + * Else return the sum of the 2 numbers +* The `sub` method also takes two parameters; + * If either parameter is a non-number the function returns `null` + * Else it return the second parameter subtracted from the first parameter. + +## Used Resources +* [Jest Getting Started](https://facebook.github.io/jest/docs/en/getting-started.html) +* [Jest Globals](https://facebook.github.io/jest/docs/en/api.html#content) +* [Jest Expect](https://facebook.github.io/jest/docs/en/expect.html#content) diff --git a/lab-pedja/__test__/arithmetic.test.js b/lab-pedja/__test__/arithmetic.test.js new file mode 100644 index 0000000..e9c0a45 --- /dev/null +++ b/lab-pedja/__test__/arithmetic.test.js @@ -0,0 +1,33 @@ +'use strict'; + +const arithmetic = require('../lib/arithmetic'); + +describe('arithmetic.test.js', () => { + + test('arithmetic.add has 2 number params and returns their sum', () => { + expect(arithmetic.add(1,2)).toBe(3); + }); + + test('arithmetic.add return null is one param is not a number', () => { + expect(arithmetic.add(12, '')).toBeNull(); + expect(arithmetic.add('', 12)).toBeNull(); + expect(arithmetic.add('hello', 12)).toBeNull(); + expect(arithmetic.add(12, 'hello')).toBeNull(); + expect(arithmetic.add('', '')).toBeNull(); + expect(arithmetic.add('hello', 'world')).toBeNull(); + }); + + test('arithmetic.sub has 2 number params and returns second param subtracted from the first one', () => { + expect(arithmetic.sub(2,1)).toBe(1); + }); + + test('arithmetic.sub return null is one param is not a number', () => { + expect(arithmetic.sub(12, '')).toBeNull(); + expect(arithmetic.sub('', 12)).toBeNull(); + expect(arithmetic.sub('Pedja', 12)).toBeNull(); + expect(arithmetic.sub(12, 'Pedja')).toBeNull(); + expect(arithmetic.sub('', '')).toBeNull(); + expect(arithmetic.sub('hello', 'world')).toBeNull(); + }); + +}); diff --git a/lab-pedja/__test__/greet.test.js b/lab-pedja/__test__/greet.test.js new file mode 100644 index 0000000..a51d852 --- /dev/null +++ b/lab-pedja/__test__/greet.test.js @@ -0,0 +1,17 @@ +'use strict'; + +const greet = require('../lib/greet'); + +describe('greet.test.js', () => { + + test('greet.hi has single string param and returns "hello ', () => { + expect(greet.hi('world')).toEqual('hello world'); + }); + + test('greet.hi returns null if input is not a string', () => { + expect(greet.hi('')).toBeNull(); + expect(greet.hi(1234)).toBeNull(); + expect(greet.hi(true)).toBeNull(); + }); + +}); diff --git a/lab-pedja/lib/arithmetic.js b/lab-pedja/lib/arithmetic.js new file mode 100644 index 0000000..2bd4856 --- /dev/null +++ b/lab-pedja/lib/arithmetic.js @@ -0,0 +1,15 @@ +'use strict'; + +const arithmetic = module.exports = {}; + +arithmetic.add = (param1, param2) => { + if(typeof param1 !== 'number' || typeof param2 !== 'number') + return null; + return param1 + param2; +}; + +arithmetic.sub = (param1, param2) => { + if(typeof param1 !== 'number' || typeof param2 !== 'number') + return null; + return param1 - param2; +}; diff --git a/lab-pedja/lib/greet.js b/lab-pedja/lib/greet.js new file mode 100644 index 0000000..bfc7d31 --- /dev/null +++ b/lab-pedja/lib/greet.js @@ -0,0 +1,9 @@ +'use strict'; + +const greet = module.exports = {}; + +greet.hi = (name) => { + if(name === '' || typeof name !== 'string') + return null; + return `hello ${name}`; +}; diff --git a/lab-pedja/package.json b/lab-pedja/package.json new file mode 100644 index 0000000..bf5e631 --- /dev/null +++ b/lab-pedja/package.json @@ -0,0 +1,22 @@ +{ + "name": "01-node-ecosystem", + "version": "1.0.0", + "description": "Class01_ecosystem", + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/pjosifovic/01-node-ecosystem.git" + }, + "author": "Pedja", + "license": "ISC", + "bugs": { + "url": "https://github.com/pjosifovic/01-node-ecosystem/issues" + }, + "homepage": "https://github.com/pjosifovic/01-node-ecosystem#readme", + "devDependencies": { + "jest": "^21.2.1" + } +}