From 58ef3861a19b91807213e849f12fa64fa00c0d36 Mon Sep 17 00:00:00 2001 From: Megan Taylor Date: Thu, 7 Jun 2018 19:52:10 -0400 Subject: [PATCH 1/5] npm init and gitignore --- .gitignore | 11 +++++++++++ package.json | 22 ++++++++++++++++++++++ 2 files changed, 33 insertions(+) create mode 100644 .gitignore create mode 100644 package.json diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e786ee5 --- /dev/null +++ b/.gitignore @@ -0,0 +1,11 @@ +node_modules/ + +# OS generated files # +###################### +.DS_Store +.DS_Store? +._* +.Spotlight-V100 +.Trashes +ehthumbs.db +Thumbs.db diff --git a/package.json b/package.json new file mode 100644 index 0000000..d2f2f32 --- /dev/null +++ b/package.json @@ -0,0 +1,22 @@ +{ + "name": "assignment_node_hello_world", + "version": "1.0.0", + "description": "viking code school assignment", + "main": "index.js", + "scripts": { + "test": "console.log(\"test\");" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/megantaylor/assignment_node_hello_world.git" + }, + "keywords": [ + "nodejs" + ], + "author": "megan taylor", + "license": "ISC", + "bugs": { + "url": "https://github.com/megantaylor/assignment_node_hello_world/issues" + }, + "homepage": "https://github.com/megantaylor/assignment_node_hello_world#readme" +} From 2d209819c8a36e662ce590006c17ffd3fe775389 Mon Sep 17 00:00:00 2001 From: Megan Taylor Date: Thu, 7 Jun 2018 19:58:56 -0400 Subject: [PATCH 2/5] install chalk and lodash and confirm use --- index.js | 9 +++++++ package-lock.json | 62 +++++++++++++++++++++++++++++++++++++++++++++++ package.json | 8 ++++-- 3 files changed, 77 insertions(+), 2 deletions(-) create mode 100644 index.js create mode 100644 package-lock.json diff --git a/index.js b/index.js new file mode 100644 index 0000000..8282fcb --- /dev/null +++ b/index.js @@ -0,0 +1,9 @@ +const chalk = require("chalk"); +var _ = require("lodash"); + +console.log("Hello World!"); +console.log(chalk.blue('Hello world!')); + +_.forEach([1, 2], function(value) { + console.log(value); +}); diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 0000000..a712dc1 --- /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.1", + "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-3.2.1.tgz", + "integrity": "sha512-VT0ZI6kZRdTh8YyJw3SMbYm/u+NqfsAxEpWO0Pf9sq8/e94WxxOpPKx9FR1FlyCtOVDNOQ+8ntlqFxiRc+r5qA==", + "requires": { + "color-convert": "^1.9.0" + } + }, + "chalk": { + "version": "2.4.1", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-2.4.1.tgz", + "integrity": "sha512-ObN6h1v2fTJSmUXoS3nMQ92LbDK9be4TV+6G+omQlGJFdcUX5heKi1LZ1YnRMIgwTLEj3E24bT6tYni50rlCfQ==", + "requires": { + "ansi-styles": "^3.2.1", + "escape-string-regexp": "^1.0.5", + "supports-color": "^5.3.0" + } + }, + "color-convert": { + "version": "1.9.1", + "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-1.9.1.tgz", + "integrity": "sha512-mjGanIiwQJskCC18rPR6OmrZ6fm2Lc7PeGFYwCmy5J34wC6F1PzdGL6xeMfmgicfYcNLGuVFA3WzXtIDCQSZxQ==", + "requires": { + "color-name": "^1.1.1" + } + }, + "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": "3.0.0", + "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-3.0.0.tgz", + "integrity": "sha1-tdRU3CGZriJWmfNGfloH87lVuv0=" + }, + "lodash": { + "version": "4.17.10", + "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.10.tgz", + "integrity": "sha512-UejweD1pDoXu+AD825lWwp4ZGtSwgnpZxb3JDViD7StjQz+Nb/6l093lx4OQ0foGWNRoc19mWy7BzL+UAK2iVg==" + }, + "supports-color": { + "version": "5.4.0", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.4.0.tgz", + "integrity": "sha512-zjaXglF5nnWpsq470jSv6P9DwPvgLkuapYmfDm3JWOm0vkNTVF2tI4UrN2r6jH1qM/uc/WtxYY1hYoA2dOKj5w==", + "requires": { + "has-flag": "^3.0.0" + } + } + } +} diff --git a/package.json b/package.json index d2f2f32..c8149b7 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "description": "viking code school assignment", "main": "index.js", "scripts": { - "test": "console.log(\"test\");" + "test": "" }, "repository": { "type": "git", @@ -18,5 +18,9 @@ "bugs": { "url": "https://github.com/megantaylor/assignment_node_hello_world/issues" }, - "homepage": "https://github.com/megantaylor/assignment_node_hello_world#readme" + "homepage": "https://github.com/megantaylor/assignment_node_hello_world#readme", + "dependencies": { + "chalk": "^2.4.1", + "lodash": "^4.17.10" + } } From f4c58e2808bcdf3dfc1cfa31898ec8d9960a735f Mon Sep 17 00:00:00 2001 From: Megan Taylor Date: Thu, 7 Jun 2018 20:08:19 -0400 Subject: [PATCH 3/5] create and test logger --- index.js | 11 ++++------- lib/logger.js | 31 +++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 7 deletions(-) create mode 100644 lib/logger.js diff --git a/index.js b/index.js index 8282fcb..061788c 100644 --- a/index.js +++ b/index.js @@ -1,9 +1,6 @@ -const chalk = require("chalk"); var _ = require("lodash"); +var logger = require("./lib/logger"); -console.log("Hello World!"); -console.log(chalk.blue('Hello world!')); - -_.forEach([1, 2], function(value) { - console.log(value); -}); +logger.log("test", "info"); +logger.log("123", "warning"); +logger.log("abc", "error"); diff --git a/lib/logger.js b/lib/logger.js new file mode 100644 index 0000000..4a3b997 --- /dev/null +++ b/lib/logger.js @@ -0,0 +1,31 @@ +var chalk = require('chalk'); + +var logger = { + log: function(message, level) { + switch (level) { + case "info": + this.info(message); + break; + case "warning": + this.warning(message); + break; + case "error": + this.error(message); + break; + } + }, + + info: function(message) { + console.log(chalk.blue(message)); + }, + + warning: function(message) { + console.log(chalk.yellow(message)); + }, + + error: function(message) { + console.log(chalk.red(message)); + } +}; + +module.exports = logger; From afe1aeb869c140a318a9f5d503a1c8b610124ef3 Mon Sep 17 00:00:00 2001 From: Megan Taylor Date: Thu, 7 Jun 2018 20:10:47 -0400 Subject: [PATCH 4/5] require json and iterate --- index.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index 061788c..7fdbfec 100644 --- a/index.js +++ b/index.js @@ -1,6 +1,7 @@ var _ = require("lodash"); var logger = require("./lib/logger"); +var messages = require('./data/logs'); -logger.log("test", "info"); -logger.log("123", "warning"); -logger.log("abc", "error"); +_.each(messages, function(message){ + logger.log(message.message, message.level) +}) From be91366ae6395368f955dcfc909e347b4f6b06eb Mon Sep 17 00:00:00 2001 From: Megan Taylor Date: Thu, 7 Jun 2018 20:16:32 -0400 Subject: [PATCH 5/5] refactor logger --- lib/logger.js | 60 ++++++++++++++++++++++++++++----------------------- 1 file changed, 33 insertions(+), 27 deletions(-) diff --git a/lib/logger.js b/lib/logger.js index 4a3b997..1105ea1 100644 --- a/lib/logger.js +++ b/lib/logger.js @@ -1,31 +1,37 @@ var chalk = require('chalk'); -var logger = { - log: function(message, level) { - switch (level) { - case "info": - this.info(message); - break; - case "warning": - this.warning(message); - break; - case "error": - this.error(message); - break; - } - }, - - info: function(message) { - console.log(chalk.blue(message)); - }, - - warning: function(message) { - console.log(chalk.yellow(message)); - }, - - error: function(message) { - console.log(chalk.red(message)); - } +var LEVEL_COLOR_MAP = { + info: 'blue', + warning: 'yellow', + error: 'red' }; -module.exports = logger; + +var log = function(message, level) { + var color = LEVEL_COLOR_MAP[level]; + message = chalk[color](message); + console.log(message) +}; + + +var info = function(message) { + log(message, 'info'); +}; + + +var warning = function(message) { + log(message, 'warning'); +}; + + +var error = function(message) { + log(message, 'error'); +}; + + +module.exports = { + log: log, + info: info, + warning: warning, + error: error +};