From 094bd5c70bf7b745239e4eb23dcaa49dec4e70c9 Mon Sep 17 00:00:00 2001 From: Steven Zarrella Date: Mon, 25 Sep 2017 12:24:14 -0400 Subject: [PATCH 1/3] set up initial project & verified lodash & chalk packages work --- .gitignore | 4 +++ index.js | 10 ++++++++ package-lock.json | 62 +++++++++++++++++++++++++++++++++++++++++++++++ package.json | 23 ++++++++++++++++++ 4 files changed, 99 insertions(+) create mode 100644 .gitignore create mode 100644 index.js create mode 100644 package-lock.json create mode 100644 package.json diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3cce633 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ + + + +node_modules/ \ No newline at end of file diff --git a/index.js b/index.js new file mode 100644 index 0000000..e40eade --- /dev/null +++ b/index.js @@ -0,0 +1,10 @@ +const _ = require('./node_modules/lodash'); +const chalk = require('./node_modules/chalk'); + +let testArray = [1, 2, 3, 4, 5]; + +console.log(chalk.blue("Hello world!")); + +_.each(testArray, function(value) { + console.log(value * 2); +}); \ No newline at end of file diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 0000000..d816a4a --- /dev/null +++ b/package-lock.json @@ -0,0 +1,62 @@ +{ + "name": "assignment_node_hello_world", + "version": "1.0.0", + "lockfileVersion": 1, + "requires": true, + "dependencies": { + "ansi-styles": { + "version": "3.2.0", + "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-3.2.0.tgz", + "integrity": "sha512-NnSOmMEYtVR2JVMIGTzynRkkaxtiq1xnFBcdQD/DnNCYPoEPsVJhM98BDyaoNOQIi7p4okdi3E27eN7GQbsUug==", + "requires": { + "color-convert": "1.9.0" + } + }, + "chalk": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-2.1.0.tgz", + "integrity": "sha512-LUHGS/dge4ujbXMJrnihYMcL4AoOweGnw9Tp3kQuqy1Kx5c1qKjqvMJZ6nVJPMWJtKCTN72ZogH3oeSO9g9rXQ==", + "requires": { + "ansi-styles": "3.2.0", + "escape-string-regexp": "1.0.5", + "supports-color": "4.4.0" + } + }, + "color-convert": { + "version": "1.9.0", + "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-1.9.0.tgz", + "integrity": "sha1-Gsz5fdc5uYO/mU1W/sj5WFNkG3o=", + "requires": { + "color-name": "1.1.3" + } + }, + "color-name": { + "version": "1.1.3", + "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.3.tgz", + "integrity": "sha1-p9BVi9icQveV3UIyj3QIMcpTvCU=" + }, + "escape-string-regexp": { + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz", + "integrity": "sha1-G2HAViGQqN/2rjuyzwIAyhMLhtQ=" + }, + "has-flag": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-2.0.0.tgz", + "integrity": "sha1-6CB68cx7MNRGzHC3NLXovhj4jVE=" + }, + "lodash": { + "version": "4.17.4", + "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.4.tgz", + "integrity": "sha1-eCA6TRwyiuHYbcpkYONptX9AVa4=" + }, + "supports-color": { + "version": "4.4.0", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-4.4.0.tgz", + "integrity": "sha512-rKC3+DyXWgK0ZLKwmRsrkyHVZAjNkfzeehuFWdGGcqGDTZFH73+RH6S/RDAAxl9GusSjZSUWYLmT9N5pzXFOXQ==", + "requires": { + "has-flag": "2.0.0" + } + } + } +} diff --git a/package.json b/package.json new file mode 100644 index 0000000..fa71ae6 --- /dev/null +++ b/package.json @@ -0,0 +1,23 @@ +{ + "name": "assignment_node_hello_world", + "version": "1.0.0", + "description": "assignment_node_hello_world ===========================", + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/stevenvz/assignment_node_hello_world.git" + }, + "author": "", + "license": "ISC", + "bugs": { + "url": "https://github.com/stevenvz/assignment_node_hello_world/issues" + }, + "homepage": "https://github.com/stevenvz/assignment_node_hello_world#readme", + "dependencies": { + "chalk": "^2.1.0", + "lodash": "^4.17.4" + } +} From 45918c68b41220f1110955fe8cb81b7130d5fd74 Mon Sep 17 00:00:00 2001 From: Steven Zarrella Date: Mon, 25 Sep 2017 12:25:02 -0400 Subject: [PATCH 2/3] added name to README file --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 468464f..741a2d5 100644 --- a/README.md +++ b/README.md @@ -5,5 +5,5 @@ assignment_node_hello_world Just Node.js saying hello to the world and such. - +Steven Zarrella From e901494a77d4787395742d298324d1d5a177272f Mon Sep 17 00:00:00 2001 From: Steven Zarrella Date: Mon, 25 Sep 2017 12:54:18 -0400 Subject: [PATCH 3/3] project complete --- index.js | 13 +++++++++++++ lib/logger.js | 22 ++++++++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 lib/logger.js diff --git a/index.js b/index.js index e40eade..7149566 100644 --- a/index.js +++ b/index.js @@ -1,5 +1,8 @@ const _ = require('./node_modules/lodash'); const chalk = require('./node_modules/chalk'); +const log = require('./lib/logger'); + +const JSONdata = require('./data/logs.json'); let testArray = [1, 2, 3, 4, 5]; @@ -7,4 +10,14 @@ console.log(chalk.blue("Hello world!")); _.each(testArray, function(value) { console.log(value * 2); +}); + + +log("Hello world!", "info"); +log("Hello world!", "WArning"); +log("Hello world!", "ERROR"); + +//logging from JSON file +_.each(JSONdata, function(data) { + log(data.message, data.level); }); \ No newline at end of file diff --git a/lib/logger.js b/lib/logger.js new file mode 100644 index 0000000..c112d7c --- /dev/null +++ b/lib/logger.js @@ -0,0 +1,22 @@ +const chalk = require('../node_modules/chalk'); + +const log = function(message, level) { + let lowerLevel = level.toLowerCase(); + + switch(lowerLevel) { + case "info": + console.log(chalk.blue(message)); + break; + case "warning": + console.log(chalk.yellow(message)); + break; + case "error": + console.log(chalk.red(message)); + break; + default: + console.log("LOGGER ERROR - Invalid log level"); + break; + } +} + +module.exports = log; \ No newline at end of file