diff --git a/lab-ron/.eslintignore b/lab-ron/.eslintignore new file mode 100644 index 0000000..4b63a5d --- /dev/null +++ b/lab-ron/.eslintignore @@ -0,0 +1 @@ +**/*/vendor/ diff --git a/lab-ron/.eslintrc b/lab-ron/.eslintrc new file mode 100644 index 0000000..90447e4 --- /dev/null +++ b/lab-ron/.eslintrc @@ -0,0 +1,35 @@ +{ + "globals" : { + "rawData": true, + "app": true, + "Handlebars": true, + "page": true, + "$": true, + "marked": true, + "hljs": true + }, + "extends": "eslint:recommended", + "parserOptions": { + "ecmaVersion": 6, + "ecmaFeatures": {"impliedStrict": true} + }, + "env": { + "browser": true, + "jquery": true, + "node": true, + "es6": true + }, + "rules": { + "semi": [2, "always"], + "eqeqeq": ["error", "always"], + "no-template-curly-in-string": "error", + "no-console": "off", + "no-undefined": "off", + "indent": ["error", 2], + "quotes": ["warn", "single", {"allowTemplateLiterals": true}], + "no-multi-spaces": ["warn", {"exceptions": { "VariableDeclarator": true }}], + "no-trailing-spaces": "warn", + "new-cap": "warn", + "no-redeclare": ["error", { "builtinGlobals": true }] + } +} diff --git a/lab-ron/.gitignore b/lab-ron/.gitignore new file mode 100644 index 0000000..3583e8a --- /dev/null +++ b/lab-ron/.gitignore @@ -0,0 +1,68 @@ +# Created by https://www.gitignore.io/api/osx,linux,node,vim + +### OSX ### +.DS_Store +.AppleDouble +.LSOverride + +### 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-* + + +### Node ### +# Logs +logs +*.log +npm-debug.log* + +# Runtime data +pids +*.pid +*.seed + +# Directory for instrumented libs generated by jscoverage/JSCover +lib-cov + +# Coverage directory used by tools like istanbul +coverage + +# 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 REPL history +.node_repl_history + +### Vim ### +# swap +[._]*.s[a-w][a-z] +[._]s[a-w][a-z] +# session +Session.vim +# temporary +.netrwhist +*~ + +# auto-generated tag files +tags + +###### Personal +.tern-project diff --git a/lab-ron/README.md b/lab-ron/README.md new file mode 100644 index 0000000..41079ea --- /dev/null +++ b/lab-ron/README.md @@ -0,0 +1,44 @@ +# 01 Node Ecosystem + +Greet and Arithmetic are functions that facilitate adding or subtracting two numbers or greeting someone. + +## how to use + +Please remember to require `greet` and `arithmetic` from the `lib/` directory at the top of your `index.js` + +### greet() +- takes in an argument as a string, and returns `hello + ` +- if argument is not a string or null it will return `null` + +``` +console.log(greet('world')); +console.log(greet(6)); + +>> hello world +>> null +``` + + +### arithmetic.add() +- takes in only two numbers as it's arguments and returns the sum of the numbers +- if any argument is not a number it will return `null` + +``` +console.log(arithmetic.add(2, 3)); +console.log(arithmetic.add('2', '3')); + +>> 5 +>> null +``` + +### arithmetic.sub() +- takes in only two numbers as it's arguments and returns the difference of the numbers +- if any argument is not a number it will return `null` + +``` +console.log(arithmetic.sub(9, 3)); +console.log(arithmetic.sub('9', '3')); + +>> 6 +>> null +``` \ No newline at end of file diff --git a/lab-ron/__test__/arithmetic.test.js b/lab-ron/__test__/arithmetic.test.js new file mode 100644 index 0000000..cca8595 --- /dev/null +++ b/lab-ron/__test__/arithmetic.test.js @@ -0,0 +1,35 @@ +'use strict'; + +const arithmetic = require('../lib/arithmetic.js'); + +// arithmetic.add() +test('arithmetic.add(5, 3) should return 8', () => { + let result = arithmetic.add(5, 3); + expect(result).toEqual(8); +}); + +test('arithmetic.add(5, "3") should return null', () => { + let result = arithmetic.add(5, '3'); + expect(result).toEqual(null); +}); + +test('arithmetic.add("5", 3) should return null', () => { + let result = arithmetic.add('5', 3); + expect(result).toEqual(null); +}); + +// arithmetic.sub() +test('arithmetic.sub(5, 3) should return 2', () => { + let result = arithmetic.sub(5, 3); + expect(result).toEqual(2); +}); + +test('arithmetic.sub(5, "3") should return null', () => { + let result = arithmetic.sub(5, '3'); + expect(result).toEqual(null); +}); + +test('arithmetic.sub("5", 3) should return null', () => { + let result = arithmetic.sub('5', 3); + expect(result).toEqual(null); +}); \ No newline at end of file diff --git a/lab-ron/__test__/greet.test.js b/lab-ron/__test__/greet.test.js new file mode 100644 index 0000000..8a7a5fb --- /dev/null +++ b/lab-ron/__test__/greet.test.js @@ -0,0 +1,19 @@ +'use strict'; + +const greet = require('../lib/greet.js'); + +test('greet() should return null', () => { + let result = greet(); + expect(result).toEqual(null); +}); + +test('greet(6) should return null', () => { + let result = greet(6); + expect(result).toEqual(null); +}); + +test('greet(\'ron\') should return "hello ron"', () => { + let result = greet('ron'); + expect(result).toEqual('hello ron'); +}); + diff --git a/lab-ron/index.js b/lab-ron/index.js new file mode 100644 index 0000000..7a8428d --- /dev/null +++ b/lab-ron/index.js @@ -0,0 +1,15 @@ +'use strict'; + +const greet = require('./lib/greet.js'); +const arithmetic = require('./lib/arithmetic.js'); + +console.log(greet()); +console.log(greet('ron')); + +console.log(arithmetic.add(1,2)); +console.log(arithmetic.sub(1,2)); + +console.log(arithmetic.add(1,'2')); +console.log(arithmetic.sub('1',2)); + + diff --git a/lab-ron/lib/arithmetic.js b/lab-ron/lib/arithmetic.js new file mode 100644 index 0000000..d03f285 --- /dev/null +++ b/lab-ron/lib/arithmetic.js @@ -0,0 +1,20 @@ +'use strict'; + +const arithmetic = {}; + +arithmetic.add = (a, b) => { + if (typeof a === 'number' && typeof b === 'number') + return a + b; + else + return null; +}; + + +arithmetic.sub = (a, b) => { + if (typeof a === 'number' && typeof b === 'number') + return a - b; + else + return null; +}; + +module.exports = arithmetic; \ No newline at end of file diff --git a/lab-ron/lib/greet.js b/lab-ron/lib/greet.js new file mode 100644 index 0000000..1e59aaf --- /dev/null +++ b/lab-ron/lib/greet.js @@ -0,0 +1,8 @@ +'use strict'; + +module.exports = (name) => { + if (typeof name === 'string') + return `hello ${name}`; + else + return null; +}; \ No newline at end of file diff --git a/lab-ron/package.json b/lab-ron/package.json new file mode 100644 index 0000000..6550679 --- /dev/null +++ b/lab-ron/package.json @@ -0,0 +1,23 @@ +{ + "name": "01-node-ecosystem", + "version": "1.0.0", + "description": "First lab of 401", + "main": "index.js", + "dependencies": { + "jest": "^21.0.2" + }, + "devDependencies": {}, + "scripts": { + "test": "jest --runInBand" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/ronbarrantes/01-node-ecosystem.git" + }, + "author": "Ron Barrantes", + "license": "MIT", + "bugs": { + "url": "https://github.com/ronbarrantes/01-node-ecosystem/issues" + }, + "homepage": "https://github.com/ronbarrantes/01-node-ecosystem#readme" +}