From a7a2978ab1c1fbbb5095190c315d4621b860ca84 Mon Sep 17 00:00:00 2001 From: Austin1780 Date: Tue, 14 Nov 2017 09:49:02 -0700 Subject: [PATCH 01/17] warmup complete --- index.js | 0 lib/userInput.js | 66 ++++++++++++++++++++++++++++++++++++++++++++++++ warmup/index.js | 66 ++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 132 insertions(+) create mode 100644 index.js create mode 100644 lib/userInput.js create mode 100644 warmup/index.js diff --git a/index.js b/index.js new file mode 100644 index 0000000..e69de29 diff --git a/lib/userInput.js b/lib/userInput.js new file mode 100644 index 0000000..c7e2d5f --- /dev/null +++ b/lib/userInput.js @@ -0,0 +1,66 @@ +// Start listening to STDIN +process.stdin.resume(); +process.stdin.setEncoding('utf8'); + +let state = "State one"; + +function one(state) { + + // Start listening to STDIN + process.stdin.resume(); + process.stdin.setEncoding('utf8'); + + // Inline function to handle + // message output + var showMessage = (state, err) => { + console.log("Welcome to the Node Dictionary Reader!"); + console.log('Type "next" to continue'); + if (err) { + console.error(err); + } + }; + + // Display message + showMessage(state); + + + // Handler for STDIN data + // event + var onData = (data) => { + data = data.trim(); + + // If user input "next" + // let's go to the next + // state + if (data === 'next') { + process.stdin.pause(); + process.stdin.removeListener('data', onData); + + if (state === "State one") { + two(state); + } else if (state === "State two") { + three(state); + } + + } else { + + // All other input is invalid + showMessage(`Invalid: ${ data }`); + } + }; + + // Set the listener + process.stdin.on('data', onData); +} + +function two() { + state = "State two"; + one(state); +} + +function three() { + console.log("Goodbye"); +} + +// Start the app +one(state); diff --git a/warmup/index.js b/warmup/index.js new file mode 100644 index 0000000..1a09a16 --- /dev/null +++ b/warmup/index.js @@ -0,0 +1,66 @@ +// Start listening to STDIN +process.stdin.resume(); +process.stdin.setEncoding('utf8'); + +let state = "State one"; + +function one(state) { + + // Start listening to STDIN + process.stdin.resume(); + process.stdin.setEncoding('utf8'); + + // Inline function to handle + // message output + var showMessage = (state, err) => { + console.log(state); + console.log('Type "next" to continue'); + if (err) { + console.error(err); + } + }; + + // Display message + showMessage(state); + + + // Handler for STDIN data + // event + var onData = (data) => { + data = data.trim(); + + // If user input "next" + // let's go to the next + // state + if (data === 'next') { + process.stdin.pause(); + process.stdin.removeListener('data', onData); + + if (state === "State one") { + two(state); + } else if (state === "State two") { + three(state); + } + + } else { + + // All other input is invalid + showMessage(`Invalid: ${ data }`); + } + }; + + // Set the listener + process.stdin.on('data', onData); +} + +function two() { + state = "State two"; + one(state); +} + +function three() { + console.log("Goodbye"); +} + +// Start the app +one(state); From 48dbbc399ef70b0d1191ccbbf0c7641bfd36fb8e Mon Sep 17 00:00:00 2001 From: SamuelLangenfeld Date: Tue, 14 Nov 2017 12:15:24 -0500 Subject: [PATCH 02/17] working on it --- lib/loader.js | 16 +++++++++++++ lib/userInput.js | 59 +++++++++++++++++++++++++----------------------- 2 files changed, 47 insertions(+), 28 deletions(-) create mode 100644 lib/loader.js diff --git a/lib/loader.js b/lib/loader.js new file mode 100644 index 0000000..2b248cc --- /dev/null +++ b/lib/loader.js @@ -0,0 +1,16 @@ +fs = require("fs"); + +function loader() { + fs.readdir("../data/", (err, data) => { + if (err) { + throw err; + } + console.log("Select a dictionary to load:"); + for (let i = 0; i < data.length; i++) { + console.log(i + 1 + ". " + data[i]); + } + return data; + }); +} + +module.exports = loader; diff --git a/lib/userInput.js b/lib/userInput.js index c7e2d5f..7367921 100644 --- a/lib/userInput.js +++ b/lib/userInput.js @@ -1,66 +1,69 @@ +var loader = require("./loader.js"); + // Start listening to STDIN process.stdin.resume(); -process.stdin.setEncoding('utf8'); - -let state = "State one"; - -function one(state) { +process.stdin.setEncoding("utf8"); +function start() { // Start listening to STDIN process.stdin.resume(); - process.stdin.setEncoding('utf8'); + process.stdin.setEncoding("utf8"); // Inline function to handle // message output - var showMessage = (state, err) => { + var dicArray; + var showMessage = err => { console.log("Welcome to the Node Dictionary Reader!"); - console.log('Type "next" to continue'); + console.log("======================================"); + console.log("Enter q to quit"); + dicArray = loader(); if (err) { console.error(err); } }; // Display message - showMessage(state); - + showMessage(); // Handler for STDIN data // event - var onData = (data) => { + var onData = data => { data = data.trim(); // If user input "next" // let's go to the next // state - if (data === 'next') { + if (data === "q") { + process.exit(); + } + if (!isNaN(data)) { + console.log(dicArray); + if (dicArray[Number(data) - 1]) { + } else { + console.log("Invalid choice"); + } + } else { + /* + + if (data === "next") { process.stdin.pause(); - process.stdin.removeListener('data', onData); + process.stdin.removeListener("data", onData); if (state === "State one") { two(state); } else if (state === "State two") { three(state); } - - } else { - + } + */ // All other input is invalid - showMessage(`Invalid: ${ data }`); + showMessage(`Invalid: ${data}`); } }; // Set the listener - process.stdin.on('data', onData); -} - -function two() { - state = "State two"; - one(state); -} - -function three() { - console.log("Goodbye"); + process.stdin.on("data", onData); } // Start the app -one(state); +start(); From 21f2104cbc7636791d8d85d35be3c1bbf554bd3e Mon Sep 17 00:00:00 2001 From: Austin1780 Date: Tue, 14 Nov 2017 10:21:51 -0700 Subject: [PATCH 03/17] minor changes --- lib/loader.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/loader.js b/lib/loader.js index 2b248cc..2fe8b73 100644 --- a/lib/loader.js +++ b/lib/loader.js @@ -1,7 +1,7 @@ fs = require("fs"); function loader() { - fs.readdir("../data/", (err, data) => { + let data = fs.readdir("../data/", (err, data) => { if (err) { throw err; } @@ -11,6 +11,7 @@ function loader() { } return data; }); + return data; } module.exports = loader; From fcfe56b76e99e624b2e2b1e4efb42215f6b11ecb Mon Sep 17 00:00:00 2001 From: Austin1780 Date: Tue, 14 Nov 2017 10:41:45 -0700 Subject: [PATCH 04/17] finished loader module --- lib/dictionary.js | 1 + lib/loader.js | 15 +++++++++++---- lib/userInput.js | 12 ++++++++---- 3 files changed, 20 insertions(+), 8 deletions(-) create mode 100644 lib/dictionary.js diff --git a/lib/dictionary.js b/lib/dictionary.js new file mode 100644 index 0000000..88edba1 --- /dev/null +++ b/lib/dictionary.js @@ -0,0 +1 @@ +fs = require("fs"); diff --git a/lib/loader.js b/lib/loader.js index 2fe8b73..77f36e7 100644 --- a/lib/loader.js +++ b/lib/loader.js @@ -1,7 +1,14 @@ fs = require("fs"); -function loader() { - let data = fs.readdir("../data/", (err, data) => { +let dictionaries = { + arrayDictionaries: fs.readdirSync("../data/", (err, data) => { + if (err) { + throw err; + } + return data; + }), + loaderFunction: function loader() { + fs.readdir("../data/", (err, data) => { if (err) { throw err; } @@ -11,7 +18,7 @@ function loader() { } return data; }); - return data; + } } -module.exports = loader; +module.exports = dictionaries; diff --git a/lib/userInput.js b/lib/userInput.js index 7367921..dd9c61a 100644 --- a/lib/userInput.js +++ b/lib/userInput.js @@ -1,4 +1,5 @@ -var loader = require("./loader.js"); +var dictionaries = require("./loader.js"); +var dictionary = require("./dictionary.js"); // Start listening to STDIN process.stdin.resume(); @@ -11,12 +12,14 @@ function start() { // Inline function to handle // message output - var dicArray; + var dicArray = [""]; var showMessage = err => { console.log("Welcome to the Node Dictionary Reader!"); console.log("======================================"); console.log("Enter q to quit"); - dicArray = loader(); + dicArray = dictionaries.arrayDictionaries; + dictionaries.loaderFunction(); + console.log(dicArray); if (err) { console.error(err); } @@ -39,6 +42,7 @@ function start() { if (!isNaN(data)) { console.log(dicArray); if (dicArray[Number(data) - 1]) { + } else { console.log("Invalid choice"); } @@ -54,7 +58,7 @@ function start() { } else if (state === "State two") { three(state); } - } + } */ // All other input is invalid showMessage(`Invalid: ${data}`); From fd641fb13bdaac873f686417556377421ff5898c Mon Sep 17 00:00:00 2001 From: SamuelLangenfeld Date: Tue, 14 Nov 2017 13:10:30 -0500 Subject: [PATCH 05/17] dictionary.js in progress --- lib/dictionary.js | 22 ++++++++++++++++++++++ lib/userInput.js | 2 +- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/lib/dictionary.js b/lib/dictionary.js index 88edba1..51e4d18 100644 --- a/lib/dictionary.js +++ b/lib/dictionary.js @@ -1 +1,23 @@ fs = require("fs"); + +function loadDictionary(path) { + fs.readFile("../data/" + path, "utf8", (err, data) => { + if (err) { + throw err; + } + console.log(`Successfully loaded ${path}!`); + data = JSON.parse(data); + console.log("number of keys " + Object.keys(data).length); + console.log("Word frequency by starting letter: "); + var alphabet = "abcdefghijklmnopqrstuvwxyz".split(""); + var letterCount = new Array(26); + var keys = Object.keys(data); + + for (let i = 0; i < alphabet.length; i++) { + let letter = alphabet[i]; + var regex = `/\A${letter}/g`; + } + }); +} + +module.exports = loadDictionary; diff --git a/lib/userInput.js b/lib/userInput.js index dd9c61a..ba82e3e 100644 --- a/lib/userInput.js +++ b/lib/userInput.js @@ -42,7 +42,7 @@ function start() { if (!isNaN(data)) { console.log(dicArray); if (dicArray[Number(data) - 1]) { - + dictionary(dicArray[Number(data) - 1]); } else { console.log("Invalid choice"); } From 1b6bf82ecf9255e47effad821fcb9ec64c852432 Mon Sep 17 00:00:00 2001 From: Austin1780 Date: Tue, 14 Nov 2017 11:35:18 -0700 Subject: [PATCH 06/17] working on letter counts --- lib/dictionary.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/lib/dictionary.js b/lib/dictionary.js index 51e4d18..0fcf94c 100644 --- a/lib/dictionary.js +++ b/lib/dictionary.js @@ -10,12 +10,17 @@ function loadDictionary(path) { console.log("number of keys " + Object.keys(data).length); console.log("Word frequency by starting letter: "); var alphabet = "abcdefghijklmnopqrstuvwxyz".split(""); - var letterCount = new Array(26); + var letterCount = new Array(26).fill(0); var keys = Object.keys(data); - for (let i = 0; i < alphabet.length; i++) { let letter = alphabet[i]; - var regex = `/\A${letter}/g`; + let regex = new RegExp("\\A" + letter, "g"); + for (let n = 0; n < keys.length; n++) { + if (regex.test(keys[n])) { + letterCount[i] += 1; + } + } + console.log(alphabet[i] + ": " + letterCount[i]); } }); } From f324d6504b003f1d05f99a96ced8ab966de30c25 Mon Sep 17 00:00:00 2001 From: SamuelLangenfeld Date: Tue, 14 Nov 2017 14:01:46 -0500 Subject: [PATCH 07/17] loader dictionary in progress --- lib/dictionary.js | 5 +++-- lib/loader.js | 8 +++++++- lib/search.js | 12 ++++++++++++ lib/userInput.js | 30 +++--------------------------- 4 files changed, 25 insertions(+), 30 deletions(-) create mode 100644 lib/search.js diff --git a/lib/dictionary.js b/lib/dictionary.js index 0fcf94c..204d148 100644 --- a/lib/dictionary.js +++ b/lib/dictionary.js @@ -1,4 +1,4 @@ -fs = require("fs"); +var fs = require("fs"); function loadDictionary(path) { fs.readFile("../data/" + path, "utf8", (err, data) => { @@ -14,7 +14,8 @@ function loadDictionary(path) { var keys = Object.keys(data); for (let i = 0; i < alphabet.length; i++) { let letter = alphabet[i]; - let regex = new RegExp("\\A" + letter, "g"); + let regex = "^" + letter + "+"; + regex = new RegExp(regex, "gi"); for (let n = 0; n < keys.length; n++) { if (regex.test(keys[n])) { letterCount[i] += 1; diff --git a/lib/loader.js b/lib/loader.js index 77f36e7..f7d2827 100644 --- a/lib/loader.js +++ b/lib/loader.js @@ -18,7 +18,13 @@ let dictionaries = { } return data; }); - } + }, + loadDictionary: (path)=>fs.readFile(path, 'utf8', (err, data){ + if (err){ + throw err; + } + + }) } module.exports = dictionaries; diff --git a/lib/search.js b/lib/search.js new file mode 100644 index 0000000..65f7d7c --- /dev/null +++ b/lib/search.js @@ -0,0 +1,12 @@ + +function search(dictionary){ + var keys = Object.keys(dictionary); + var searchType = { + "exact":(keys, searchTerm)=>{ + + }, + "partial":, + "begins":, + "ends": + } +} \ No newline at end of file diff --git a/lib/userInput.js b/lib/userInput.js index ba82e3e..1ec43f6 100644 --- a/lib/userInput.js +++ b/lib/userInput.js @@ -19,7 +19,6 @@ function start() { console.log("Enter q to quit"); dicArray = dictionaries.arrayDictionaries; dictionaries.loaderFunction(); - console.log(dicArray); if (err) { console.error(err); } @@ -33,35 +32,12 @@ function start() { var onData = data => { data = data.trim(); - // If user input "next" - // let's go to the next - // state if (data === "q") { process.exit(); - } - if (!isNaN(data)) { - console.log(dicArray); - if (dicArray[Number(data) - 1]) { - dictionary(dicArray[Number(data) - 1]); - } else { - console.log("Invalid choice"); - } + } else if (!isNaN(data) && dicArray[Number(data) - 1]) { + dictionary(dicArray[Number(data) - 1]); } else { - /* - - if (data === "next") { - process.stdin.pause(); - process.stdin.removeListener("data", onData); - - if (state === "State one") { - two(state); - } else if (state === "State two") { - three(state); - } - } - */ - // All other input is invalid - showMessage(`Invalid: ${data}`); + console.log("Invalid choice"); } }; From 45548aa102703250478b5c565f4056a97fa30b41 Mon Sep 17 00:00:00 2001 From: SamuelLangenfeld Date: Tue, 14 Nov 2017 15:52:05 -0500 Subject: [PATCH 08/17] in progress --- lib/loader.js | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/lib/loader.js b/lib/loader.js index f7d2827..1bddc1e 100644 --- a/lib/loader.js +++ b/lib/loader.js @@ -8,23 +8,23 @@ let dictionaries = { return data; }), loaderFunction: function loader() { - fs.readdir("../data/", (err, data) => { - if (err) { - throw err; - } - console.log("Select a dictionary to load:"); - for (let i = 0; i < data.length; i++) { - console.log(i + 1 + ". " + data[i]); - } - return data; - }); + fs.readdir("../data/", (err, data) => { + if (err) { + throw err; + } + console.log("Select a dictionary to load:"); + for (let i = 0; i < data.length; i++) { + console.log(i + 1 + ". " + data[i]); + } + return data; + }); }, - loadDictionary: (path)=>fs.readFile(path, 'utf8', (err, data){ - if (err){ - throw err; - } - - }) -} + loadDictionary: path => + fs.readFile(path, "utf8", (err, data) => { + if (err) { + throw err; + } + }) +}; module.exports = dictionaries; From fc843eeabd06b78bfb55057fd7adfe3fc3985faa Mon Sep 17 00:00:00 2001 From: Austin1780 Date: Tue, 14 Nov 2017 14:20:25 -0700 Subject: [PATCH 09/17] working on search --- lib/loader.js | 15 ++++++++++----- lib/search.js | 11 ++++++++--- lib/userInput.js | 32 +++++++++++++++++++++++++++++--- 3 files changed, 47 insertions(+), 11 deletions(-) diff --git a/lib/loader.js b/lib/loader.js index 1bddc1e..740d19e 100644 --- a/lib/loader.js +++ b/lib/loader.js @@ -19,12 +19,17 @@ let dictionaries = { return data; }); }, - loadDictionary: path => - fs.readFile(path, "utf8", (err, data) => { - if (err) { - throw err; - } + loadDictionary: path => { + let dictContents = new Promise(function(resolve, reject) { + fs.readFile(path, "utf8", (err, data) => { + if (err) { + throw err; + } + resolve(data); + }) }) + return dictContents; + } }; module.exports = dictionaries; diff --git a/lib/search.js b/lib/search.js index 65f7d7c..5e31c79 100644 --- a/lib/search.js +++ b/lib/search.js @@ -1,12 +1,17 @@ -function search(dictionary){ + +function search(dictionary, userChoice){ var keys = Object.keys(dictionary); var searchType = { "exact":(keys, searchTerm)=>{ - + for (let i =0; i < keys.length; i++) { + if () + } }, "partial":, "begins":, "ends": } -} \ No newline at end of file +} + +module.exports = search; diff --git a/lib/userInput.js b/lib/userInput.js index 1ec43f6..59527b9 100644 --- a/lib/userInput.js +++ b/lib/userInput.js @@ -1,5 +1,6 @@ var dictionaries = require("./loader.js"); var dictionary = require("./dictionary.js"); +var search = require("./search.js"); // Start listening to STDIN process.stdin.resume(); @@ -12,8 +13,8 @@ function start() { // Inline function to handle // message output - var dicArray = [""]; - var showMessage = err => { + let dicArray = [""]; + let showMessage = err => { console.log("Welcome to the Node Dictionary Reader!"); console.log("======================================"); console.log("Enter q to quit"); @@ -29,18 +30,43 @@ function start() { // Handler for STDIN data // event - var onData = data => { + let onData = data => { data = data.trim(); if (data === "q") { process.exit(); } else if (!isNaN(data) && dicArray[Number(data) - 1]) { dictionary(dicArray[Number(data) - 1]); + console.log("What kind of search would you like to perform?"); + console.log("1. Exact"); + console.log("2. Partial"); + console.log("3. Begins With"); + console.log("4. Ends With"); + process.stdin.removeAllListeners("data"); + process.stdin.on("data", onSearch); } else { console.log("Invalid choice"); } }; + let onSearch = data => { + data = data.trim(); + let searchTerm = getSearchTerm(); + if (data) { + case "1": search(dictionaries.loadDictionary, "exact", searchTerm); + case "2": search(dictionaries.loadDictionary, "partial", searchTerm); + case "3": search(dictionaries.loadDictionary, "begins", searchTerm); + case "4": search(dictionaries.loadDictionary, "ends", searchTerm); + default: console.log("Invalid choice"); + } + } + + let getSearchTerm = data => { + data = data.trim(); + + return data; + } + // Set the listener process.stdin.on("data", onData); } From f459b3901ec205913fcc7795cccded9b5cbb37d2 Mon Sep 17 00:00:00 2001 From: SamuelLangenfeld Date: Tue, 14 Nov 2017 16:49:25 -0500 Subject: [PATCH 10/17] in progress --- lib/dictionary.js | 3 ++- lib/search.js | 21 +++++++++--------- lib/userInput.js | 55 ++++++++++++++++++++++++++++++----------------- 3 files changed, 48 insertions(+), 31 deletions(-) diff --git a/lib/dictionary.js b/lib/dictionary.js index 204d148..308d8fc 100644 --- a/lib/dictionary.js +++ b/lib/dictionary.js @@ -1,6 +1,6 @@ var fs = require("fs"); -function loadDictionary(path) { +function loadDictionary(path, callback) { fs.readFile("../data/" + path, "utf8", (err, data) => { if (err) { throw err; @@ -23,6 +23,7 @@ function loadDictionary(path) { } console.log(alphabet[i] + ": " + letterCount[i]); } + callback(); }); } diff --git a/lib/search.js b/lib/search.js index 5e31c79..ec788a2 100644 --- a/lib/search.js +++ b/lib/search.js @@ -1,17 +1,18 @@ - - -function search(dictionary, userChoice){ +function search(dictionary, userChoice, searchTerm) { var keys = Object.keys(dictionary); var searchType = { - "exact":(keys, searchTerm)=>{ - for (let i =0; i < keys.length; i++) { - if () + exact: (keys, searchTerm) => { + for (let i = 0; i < keys.length; i++) { + if (keys[i] === searchTerm) { + console.log("Found a match"); + console.log(searchTerm); + } } }, - "partial":, - "begins":, - "ends": - } + partial: 0, + begins: 0, + ends: 0 + }; } module.exports = search; diff --git a/lib/userInput.js b/lib/userInput.js index 59527b9..1c3ab92 100644 --- a/lib/userInput.js +++ b/lib/userInput.js @@ -36,36 +36,51 @@ function start() { if (data === "q") { process.exit(); } else if (!isNaN(data) && dicArray[Number(data) - 1]) { - dictionary(dicArray[Number(data) - 1]); - console.log("What kind of search would you like to perform?"); - console.log("1. Exact"); - console.log("2. Partial"); - console.log("3. Begins With"); - console.log("4. Ends With"); - process.stdin.removeAllListeners("data"); - process.stdin.on("data", onSearch); + dictionary(dicArray[Number(data) - 1], () => { + console.log("What kind of search would you like to perform?"); + console.log("1. Exact"); + console.log("2. Partial"); + console.log("3. Begins With"); + console.log("4. Ends With"); + process.stdin.removeAllListeners("data"); + process.stdin.on("data", onSearch); + }); } else { console.log("Invalid choice"); } }; - let onSearch = data => { - data = data.trim(); - let searchTerm = getSearchTerm(); - if (data) { - case "1": search(dictionaries.loadDictionary, "exact", searchTerm); - case "2": search(dictionaries.loadDictionary, "partial", searchTerm); - case "3": search(dictionaries.loadDictionary, "begins", searchTerm); - case "4": search(dictionaries.loadDictionary, "ends", searchTerm); - default: console.log("Invalid choice"); - } - } + let onSearch = data => { + let searchType = data.trim(); + process.stdin.removeAllListeners("data"); + process.stdin.on("data", data => { + let searchTerm = getSearchTerm(data); + console.log("searchTerm is " + searchTerm); + console.log("searchType is " + searchType); + switch (searchType) { + case "1": + search(dictionaries.loadDictionary, "exact", searchTerm); + break; + case "2": + search(dictionaries.loadDictionary, "partial", searchTerm); + break; + case "3": + search(dictionaries.loadDictionary, "begins", searchTerm); + break; + case "4": + search(dictionaries.loadDictionary, "ends", searchTerm); + break; + default: + console.log("Invalid choice"); + } + }); + }; let getSearchTerm = data => { data = data.trim(); return data; - } + }; // Set the listener process.stdin.on("data", onData); From a2703631d6e01c9ab09af15c511f9ebd027debf1 Mon Sep 17 00:00:00 2001 From: Austin1780 Date: Tue, 14 Nov 2017 15:34:56 -0700 Subject: [PATCH 11/17] changes to search features --- lib/loader.js | 1 + lib/search.js | 4 +++- lib/userInput.js | 21 ++++++++++++--------- 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/lib/loader.js b/lib/loader.js index 740d19e..481d8e4 100644 --- a/lib/loader.js +++ b/lib/loader.js @@ -25,6 +25,7 @@ let dictionaries = { if (err) { throw err; } + data = JSON.parse(data); resolve(data); }) }) diff --git a/lib/search.js b/lib/search.js index ec788a2..dcd0c84 100644 --- a/lib/search.js +++ b/lib/search.js @@ -2,6 +2,7 @@ function search(dictionary, userChoice, searchTerm) { var keys = Object.keys(dictionary); var searchType = { exact: (keys, searchTerm) => { + console.log("I am executing"); for (let i = 0; i < keys.length; i++) { if (keys[i] === searchTerm) { console.log("Found a match"); @@ -9,10 +10,11 @@ function search(dictionary, userChoice, searchTerm) { } } }, - partial: 0, + partial: , begins: 0, ends: 0 }; + searchType[userChoice](keys, searchTerm); } module.exports = search; diff --git a/lib/userInput.js b/lib/userInput.js index 1c3ab92..16e8908 100644 --- a/lib/userInput.js +++ b/lib/userInput.js @@ -6,6 +6,9 @@ var search = require("./search.js"); process.stdin.resume(); process.stdin.setEncoding("utf8"); +let dicArray = [""]; +let dictPath = ""; + function start() { // Start listening to STDIN process.stdin.resume(); @@ -13,7 +16,6 @@ function start() { // Inline function to handle // message output - let dicArray = [""]; let showMessage = err => { console.log("Welcome to the Node Dictionary Reader!"); console.log("======================================"); @@ -36,6 +38,7 @@ function start() { if (data === "q") { process.exit(); } else if (!isNaN(data) && dicArray[Number(data) - 1]) { + dictPath = "../data/" + dicArray[Number(data) -1]; dictionary(dicArray[Number(data) - 1], () => { console.log("What kind of search would you like to perform?"); console.log("1. Exact"); @@ -52,27 +55,27 @@ function start() { let onSearch = data => { let searchType = data.trim(); + console.log("Please enter your search term:"); process.stdin.removeAllListeners("data"); process.stdin.on("data", data => { let searchTerm = getSearchTerm(data); - console.log("searchTerm is " + searchTerm); - console.log("searchType is " + searchType); - switch (searchType) { + dictionaries.loadDictionary(dictPath).then(loadedDictionary => + {switch (searchType) { case "1": - search(dictionaries.loadDictionary, "exact", searchTerm); + search(loadedDictionary, "exact", searchTerm); break; case "2": - search(dictionaries.loadDictionary, "partial", searchTerm); + search(loadedDictionary, "partial", searchTerm); break; case "3": - search(dictionaries.loadDictionary, "begins", searchTerm); + search(loadedDictionary, "begins", searchTerm); break; case "4": - search(dictionaries.loadDictionary, "ends", searchTerm); + search(loadedDictionary, "ends", searchTerm); break; default: console.log("Invalid choice"); - } + }}); }); }; From 9c5c5004da0b491833ff1b54ef9990c8a6f868c1 Mon Sep 17 00:00:00 2001 From: SamuelLangenfeld Date: Tue, 14 Nov 2017 18:02:43 -0500 Subject: [PATCH 12/17] working on file saving --- lib/search.js | 36 +++++++++++++++++++++++++++---- lib/userInput.js | 55 ++++++++++++++++++++++++++++++++---------------- 2 files changed, 69 insertions(+), 22 deletions(-) diff --git a/lib/search.js b/lib/search.js index dcd0c84..cecacab 100644 --- a/lib/search.js +++ b/lib/search.js @@ -1,8 +1,22 @@ function search(dictionary, userChoice, searchTerm) { var keys = Object.keys(dictionary); + let found = []; + const findMatches = (keys, regex) => { + for (let i = 0; i < keys.length; i++) { + if (regex.test(keys[i])) { + found.push(keys[i]); + } + } + return found; + }; + const printMatches = found => { + console.log("Found " + found.length + " Matches:"); + for (let i = 0; i < found.length; i++) { + console.log(found[i]); + } + }; var searchType = { exact: (keys, searchTerm) => { - console.log("I am executing"); for (let i = 0; i < keys.length; i++) { if (keys[i] === searchTerm) { console.log("Found a match"); @@ -10,9 +24,23 @@ function search(dictionary, userChoice, searchTerm) { } } }, - partial: , - begins: 0, - ends: 0 + partial: (keys, searchTerm) => { + let regex = new RegExp(searchTerm); + let found = findMatches(keys, regex); + printMatches(found); + }, + begins: (keys, searchTerm) => { + searchTerm = "^" + searchTerm; + let regex = new RegExp(searchTerm); + let found = findMatches(keys, regex); + printMatches(found); + }, + ends: (keys, searchTerm) => { + searchTerm = searchTerm + "$"; + let regex = new RegExp(searchTerm); + let found = findMatches(keys, regex); + printMatches(found); + } }; searchType[userChoice](keys, searchTerm); } diff --git a/lib/userInput.js b/lib/userInput.js index 16e8908..3dcc22d 100644 --- a/lib/userInput.js +++ b/lib/userInput.js @@ -38,7 +38,7 @@ function start() { if (data === "q") { process.exit(); } else if (!isNaN(data) && dicArray[Number(data) - 1]) { - dictPath = "../data/" + dicArray[Number(data) -1]; + dictPath = "../data/" + dicArray[Number(data) - 1]; dictionary(dicArray[Number(data) - 1], () => { console.log("What kind of search would you like to perform?"); console.log("1. Exact"); @@ -59,26 +59,45 @@ function start() { process.stdin.removeAllListeners("data"); process.stdin.on("data", data => { let searchTerm = getSearchTerm(data); - dictionaries.loadDictionary(dictPath).then(loadedDictionary => - {switch (searchType) { - case "1": - search(loadedDictionary, "exact", searchTerm); - break; - case "2": - search(loadedDictionary, "partial", searchTerm); - break; - case "3": - search(loadedDictionary, "begins", searchTerm); - break; - case "4": - search(loadedDictionary, "ends", searchTerm); - break; - default: - console.log("Invalid choice"); - }}); + dictionaries.loadDictionary(dictPath).then(loadedDictionary => { + switch (searchType) { + case "1": + search(loadedDictionary, "exact", searchTerm); + break; + case "2": + search(loadedDictionary, "partial", searchTerm); + break; + case "3": + search(loadedDictionary, "begins", searchTerm); + break; + case "4": + search(loadedDictionary, "ends", searchTerm); + break; + default: + console.log("Invalid choice"); + } + process.stdin.removeAllListeners("data"); + console.log("Do you want to save the results to a file? y/n?"); + process.stdin.on("data", onSaveChoice); + }); }); }; + let onSaveChoice = data => { + if (data == "y") { + console.log("What filepath should we write results to?"); + process.stdin.removeAllListeners("data"); + process.stdin.on("data", onSave); + } else if (data == "n") { + process.stdin.removeAllListeners("data"); + process.stdin.on("data", showMessage); + } else if (data == "q") { + process.exit(); + } + }; + + let onSave = data => {}; + let getSearchTerm = data => { data = data.trim(); From 81fec6606754c6db8b1633e64c1701d326c1cab8 Mon Sep 17 00:00:00 2001 From: Austin1780 Date: Tue, 14 Nov 2017 16:31:55 -0700 Subject: [PATCH 13/17] updates to saving files --- fileSaves/dummyFile.txt | 0 lib/search.js | 4 ++++ lib/userInput.js | 53 ++++++++++++++++++++++++++++++++--------- 3 files changed, 46 insertions(+), 11 deletions(-) create mode 100644 fileSaves/dummyFile.txt diff --git a/fileSaves/dummyFile.txt b/fileSaves/dummyFile.txt new file mode 100644 index 0000000..e69de29 diff --git a/lib/search.js b/lib/search.js index cecacab..29ae0ae 100644 --- a/lib/search.js +++ b/lib/search.js @@ -21,6 +21,7 @@ function search(dictionary, userChoice, searchTerm) { if (keys[i] === searchTerm) { console.log("Found a match"); console.log(searchTerm); + return searchTerm; } } }, @@ -28,18 +29,21 @@ function search(dictionary, userChoice, searchTerm) { let regex = new RegExp(searchTerm); let found = findMatches(keys, regex); printMatches(found); + return found; }, begins: (keys, searchTerm) => { searchTerm = "^" + searchTerm; let regex = new RegExp(searchTerm); let found = findMatches(keys, regex); printMatches(found); + return found; }, ends: (keys, searchTerm) => { searchTerm = searchTerm + "$"; let regex = new RegExp(searchTerm); let found = findMatches(keys, regex); printMatches(found); + return found; } }; searchType[userChoice](keys, searchTerm); diff --git a/lib/userInput.js b/lib/userInput.js index 3dcc22d..9d7f10e 100644 --- a/lib/userInput.js +++ b/lib/userInput.js @@ -54,6 +54,7 @@ function start() { }; let onSearch = data => { + let found = []; let searchType = data.trim(); console.log("Please enter your search term:"); process.stdin.removeAllListeners("data"); @@ -62,41 +63,71 @@ function start() { dictionaries.loadDictionary(dictPath).then(loadedDictionary => { switch (searchType) { case "1": - search(loadedDictionary, "exact", searchTerm); + found = search(loadedDictionary, "exact", searchTerm); break; case "2": - search(loadedDictionary, "partial", searchTerm); + found = search(loadedDictionary, "partial", searchTerm); break; case "3": - search(loadedDictionary, "begins", searchTerm); + found = search(loadedDictionary, "begins", searchTerm); break; case "4": - search(loadedDictionary, "ends", searchTerm); + found = search(loadedDictionary, "ends", searchTerm); break; default: console.log("Invalid choice"); } process.stdin.removeAllListeners("data"); console.log("Do you want to save the results to a file? y/n?"); - process.stdin.on("data", onSaveChoice); + process.stdin.on("data", onSaveChoice(found)); }); }); }; - let onSaveChoice = data => { - if (data == "y") { + const onSaveChoice = (data, found) => { + data = data.trim(); + if (data === "y") { console.log("What filepath should we write results to?"); process.stdin.removeAllListeners("data"); process.stdin.on("data", onSave); - } else if (data == "n") { + } else if (data === "n") { process.stdin.removeAllListeners("data"); - process.stdin.on("data", showMessage); - } else if (data == "q") { + showMessage(); + } else if (data === "q") { process.exit(); } }; - let onSave = data => {}; + let onSave = data => { + let savePath = "../fileSaves/" + data; + if (fs.existsSync(savePath)) { + console.log("That file exists, overwrite? y/n?") + process.stdin.removeAllListeners("data"); + process.stdin.on("data", saveOptions(savePath)); + } else { + saveFile(savePath); + } + }; + + let saveOptions = (data, savePath) => { + if (data == "y") { + saveFile(savePath); + } else if (data = "n") { + process.stdin.removeAllListeners("data"); + showMessage(); + } else if (data == "q") { + process.exit(); + } + } + + let saveFile = savePath => { + fs.writeFile(savePath, "utf8", (err) => { + if (err) { + throw err; + } + console.log("File saved.") + }); + } let getSearchTerm = data => { data = data.trim(); From 452fb6ee3af2e00c629c7ed3b62532dafbcb53e9 Mon Sep 17 00:00:00 2001 From: SamuelLangenfeld Date: Tue, 14 Nov 2017 19:01:29 -0500 Subject: [PATCH 14/17] final --- lib/search.js | 4 ++-- lib/userInput.js | 53 +++++++++++++++++++++++++++++------------------- 2 files changed, 34 insertions(+), 23 deletions(-) diff --git a/lib/search.js b/lib/search.js index 29ae0ae..b3b63b1 100644 --- a/lib/search.js +++ b/lib/search.js @@ -21,7 +21,7 @@ function search(dictionary, userChoice, searchTerm) { if (keys[i] === searchTerm) { console.log("Found a match"); console.log(searchTerm); - return searchTerm; + return [searchTerm]; } } }, @@ -46,7 +46,7 @@ function search(dictionary, userChoice, searchTerm) { return found; } }; - searchType[userChoice](keys, searchTerm); + return searchType[userChoice](keys, searchTerm); } module.exports = search; diff --git a/lib/userInput.js b/lib/userInput.js index 9d7f10e..524583f 100644 --- a/lib/userInput.js +++ b/lib/userInput.js @@ -2,6 +2,7 @@ var dictionaries = require("./loader.js"); var dictionary = require("./dictionary.js"); var search = require("./search.js"); +var found = []; // Start listening to STDIN process.stdin.resume(); process.stdin.setEncoding("utf8"); @@ -14,6 +15,8 @@ function start() { process.stdin.resume(); process.stdin.setEncoding("utf8"); + // Set the listener + // Inline function to handle // message output let showMessage = err => { @@ -30,8 +33,7 @@ function start() { // Display message showMessage(); - // Handler for STDIN data - // event + // Handler for starting input let onData = data => { data = data.trim(); @@ -53,13 +55,14 @@ function start() { } }; + //Enter search term + let onSearch = data => { - let found = []; let searchType = data.trim(); console.log("Please enter your search term:"); process.stdin.removeAllListeners("data"); process.stdin.on("data", data => { - let searchTerm = getSearchTerm(data); + let searchTerm = data.trim(); dictionaries.loadDictionary(dictPath).then(loadedDictionary => { switch (searchType) { case "1": @@ -79,12 +82,14 @@ function start() { } process.stdin.removeAllListeners("data"); console.log("Do you want to save the results to a file? y/n?"); - process.stdin.on("data", onSaveChoice(found)); + process.stdin.on("data", onSaveChoice); }); }); }; - const onSaveChoice = (data, found) => { + //do they want to save + + const onSaveChoice = data => { data = data.trim(); if (data === "y") { console.log("What filepath should we write results to?"); @@ -92,50 +97,56 @@ function start() { process.stdin.on("data", onSave); } else if (data === "n") { process.stdin.removeAllListeners("data"); - showMessage(); + start(); } else if (data === "q") { process.exit(); } }; + //determines if existing file + let onSave = data => { let savePath = "../fileSaves/" + data; if (fs.existsSync(savePath)) { - console.log("That file exists, overwrite? y/n?") + console.log("That file exists, overwrite? y/n?"); process.stdin.removeAllListeners("data"); - process.stdin.on("data", saveOptions(savePath)); + process.stdin.on("data", data => { + data = data.trim(); + saveOptions(data, savePath); + }); } else { saveFile(savePath); } }; + //determine if you want to overwrite + let saveOptions = (data, savePath) => { + console.log("In saveOptions"); if (data == "y") { saveFile(savePath); - } else if (data = "n") { + } else if (data == "n") { process.stdin.removeAllListeners("data"); - showMessage(); + start(); } else if (data == "q") { process.exit(); } - } + }; + + //saves file let saveFile = savePath => { - fs.writeFile(savePath, "utf8", (err) => { + console.log(found); + fs.writeFile(savePath, found.join("\n"), "utf8", err => { if (err) { throw err; } - console.log("File saved.") + console.log("File saved."); }); - } - - let getSearchTerm = data => { - data = data.trim(); - - return data; + process.stdin.removeAllListeners("data"); + start(); }; - // Set the listener process.stdin.on("data", onData); } From a7322b5594ba30bd29eeb48890cb2d75e21aaec0 Mon Sep 17 00:00:00 2001 From: Austin1780 Date: Tue, 14 Nov 2017 21:17:29 -0700 Subject: [PATCH 15/17] moved userInput from lib fold to main index --- fileSaves/dummyFile.txt | 1 + index.js | 154 ++++++++++++++++++++++++++++++++++++++++ lib/dictionary.js | 2 +- lib/loader.js | 4 +- lib/userInput.js | 154 ---------------------------------------- 5 files changed, 158 insertions(+), 157 deletions(-) delete mode 100644 lib/userInput.js diff --git a/fileSaves/dummyFile.txt b/fileSaves/dummyFile.txt index e69de29..46f29e8 100644 --- a/fileSaves/dummyFile.txt +++ b/fileSaves/dummyFile.txt @@ -0,0 +1 @@ +red \ No newline at end of file diff --git a/index.js b/index.js index e69de29..186fc30 100644 --- a/index.js +++ b/index.js @@ -0,0 +1,154 @@ +var dictionaries = require("./lib/loader.js"); +var dictionary = require("./lib/dictionary.js"); +var search = require("./lib/search.js"); + +var found = []; +// Start listening to STDIN +process.stdin.resume(); +process.stdin.setEncoding("utf8"); + +let dicArray = [""]; +let dictPath = ""; + +function start() { + // Start listening to STDIN + process.stdin.resume(); + process.stdin.setEncoding("utf8"); + + // Set the listener + + // Inline function to handle + // message output + let showMessage = err => { + console.log("Welcome to the Node Dictionary Reader!"); + console.log("======================================"); + console.log("Enter q to quit"); + dicArray = dictionaries.arrayDictionaries; + dictionaries.loaderFunction(); + if (err) { + console.error(err); + } + }; + + // Display message + showMessage(); + + // Handler for starting input + let onData = data => { + data = data.trim(); + + if (data === "q") { + process.exit(); + } else if (!isNaN(data) && dicArray[Number(data) - 1]) { + dictPath = "./data/" + dicArray[Number(data) - 1]; + dictionary(dicArray[Number(data) - 1], () => { + console.log("What kind of search would you like to perform?"); + console.log("1. Exact"); + console.log("2. Partial"); + console.log("3. Begins With"); + console.log("4. Ends With"); + process.stdin.removeAllListeners("data"); + process.stdin.on("data", onSearch); + }); + } else { + console.log("Invalid choice"); + } + }; + + //Enter search term + + let onSearch = data => { + let searchType = data.trim(); + console.log("Please enter your search term:"); + process.stdin.removeAllListeners("data"); + process.stdin.on("data", data => { + let searchTerm = data.trim(); + dictionaries.loadDictionary(dictPath).then(loadedDictionary => { + switch (searchType) { + case "1": + found = search(loadedDictionary, "exact", searchTerm); + break; + case "2": + found = search(loadedDictionary, "partial", searchTerm); + break; + case "3": + found = search(loadedDictionary, "begins", searchTerm); + break; + case "4": + found = search(loadedDictionary, "ends", searchTerm); + break; + default: + console.log("Invalid choice"); + } + process.stdin.removeAllListeners("data"); + console.log("Do you want to save the results to a file? y/n?"); + process.stdin.on("data", onSaveChoice); + }); + }); + }; + + //do they want to save + + const onSaveChoice = data => { + data = data.trim(); + if (data === "y") { + console.log("What filepath should we write results to?"); + process.stdin.removeAllListeners("data"); + process.stdin.on("data", onSave); + } else if (data === "n") { + process.stdin.removeAllListeners("data"); + start(); + } else if (data === "q") { + process.exit(); + } + }; + + //determines if existing file + + let onSave = data => { + let savePath = "./fileSaves/" + data; + if (fs.existsSync(savePath)) { + console.log("That file exists, overwrite? y/n?"); + process.stdin.removeAllListeners("data"); + process.stdin.on("data", data => { + data = data.trim(); + saveOptions(data, savePath); + }); + } else { + saveFile(savePath); + } + }; + + //determine if you want to overwrite + + let saveOptions = (data, savePath) => { + console.log("In saveOptions"); + if (data == "y") { + saveFile(savePath); + } else if (data == "n") { + process.stdin.removeAllListeners("data"); + start(); + } else if (data == "q") { + process.exit(); + } + }; + + //saves file + + let saveFile = savePath => { + console.log(savePath); + fs.writeFile(savePath, found.join("\n"), "utf8", err => { + if (err) { + throw err; + } + console.log("File saved."); + }); + process.stdin.removeAllListeners("data"); + start(); + }; + + process.stdin.on("data", onData); +} + +// Start the app +start(); diff --git a/lib/dictionary.js b/lib/dictionary.js index 308d8fc..8b15167 100644 --- a/lib/dictionary.js +++ b/lib/dictionary.js @@ -1,7 +1,7 @@ var fs = require("fs"); function loadDictionary(path, callback) { - fs.readFile("../data/" + path, "utf8", (err, data) => { + fs.readFile("./data/" + path, "utf8", (err, data) => { if (err) { throw err; } diff --git a/lib/loader.js b/lib/loader.js index 481d8e4..cefed4e 100644 --- a/lib/loader.js +++ b/lib/loader.js @@ -1,14 +1,14 @@ fs = require("fs"); let dictionaries = { - arrayDictionaries: fs.readdirSync("../data/", (err, data) => { + arrayDictionaries: fs.readdirSync("./data/", (err, data) => { if (err) { throw err; } return data; }), loaderFunction: function loader() { - fs.readdir("../data/", (err, data) => { + fs.readdir("./data/", (err, data) => { if (err) { throw err; } diff --git a/lib/userInput.js b/lib/userInput.js deleted file mode 100644 index 524583f..0000000 --- a/lib/userInput.js +++ /dev/null @@ -1,154 +0,0 @@ -var dictionaries = require("./loader.js"); -var dictionary = require("./dictionary.js"); -var search = require("./search.js"); - -var found = []; -// Start listening to STDIN -process.stdin.resume(); -process.stdin.setEncoding("utf8"); - -let dicArray = [""]; -let dictPath = ""; - -function start() { - // Start listening to STDIN - process.stdin.resume(); - process.stdin.setEncoding("utf8"); - - // Set the listener - - // Inline function to handle - // message output - let showMessage = err => { - console.log("Welcome to the Node Dictionary Reader!"); - console.log("======================================"); - console.log("Enter q to quit"); - dicArray = dictionaries.arrayDictionaries; - dictionaries.loaderFunction(); - if (err) { - console.error(err); - } - }; - - // Display message - showMessage(); - - // Handler for starting input - let onData = data => { - data = data.trim(); - - if (data === "q") { - process.exit(); - } else if (!isNaN(data) && dicArray[Number(data) - 1]) { - dictPath = "../data/" + dicArray[Number(data) - 1]; - dictionary(dicArray[Number(data) - 1], () => { - console.log("What kind of search would you like to perform?"); - console.log("1. Exact"); - console.log("2. Partial"); - console.log("3. Begins With"); - console.log("4. Ends With"); - process.stdin.removeAllListeners("data"); - process.stdin.on("data", onSearch); - }); - } else { - console.log("Invalid choice"); - } - }; - - //Enter search term - - let onSearch = data => { - let searchType = data.trim(); - console.log("Please enter your search term:"); - process.stdin.removeAllListeners("data"); - process.stdin.on("data", data => { - let searchTerm = data.trim(); - dictionaries.loadDictionary(dictPath).then(loadedDictionary => { - switch (searchType) { - case "1": - found = search(loadedDictionary, "exact", searchTerm); - break; - case "2": - found = search(loadedDictionary, "partial", searchTerm); - break; - case "3": - found = search(loadedDictionary, "begins", searchTerm); - break; - case "4": - found = search(loadedDictionary, "ends", searchTerm); - break; - default: - console.log("Invalid choice"); - } - process.stdin.removeAllListeners("data"); - console.log("Do you want to save the results to a file? y/n?"); - process.stdin.on("data", onSaveChoice); - }); - }); - }; - - //do they want to save - - const onSaveChoice = data => { - data = data.trim(); - if (data === "y") { - console.log("What filepath should we write results to?"); - process.stdin.removeAllListeners("data"); - process.stdin.on("data", onSave); - } else if (data === "n") { - process.stdin.removeAllListeners("data"); - start(); - } else if (data === "q") { - process.exit(); - } - }; - - //determines if existing file - - let onSave = data => { - let savePath = "../fileSaves/" + data; - if (fs.existsSync(savePath)) { - console.log("That file exists, overwrite? y/n?"); - process.stdin.removeAllListeners("data"); - process.stdin.on("data", data => { - data = data.trim(); - saveOptions(data, savePath); - }); - } else { - saveFile(savePath); - } - }; - - //determine if you want to overwrite - - let saveOptions = (data, savePath) => { - console.log("In saveOptions"); - if (data == "y") { - saveFile(savePath); - } else if (data == "n") { - process.stdin.removeAllListeners("data"); - start(); - } else if (data == "q") { - process.exit(); - } - }; - - //saves file - - let saveFile = savePath => { - console.log(found); - fs.writeFile(savePath, found.join("\n"), "utf8", err => { - if (err) { - throw err; - } - console.log("File saved."); - }); - process.stdin.removeAllListeners("data"); - start(); - }; - - process.stdin.on("data", onData); -} - -// Start the app -start(); From 1ea8ed1bf02f8aac796464e68602bf26084fde78 Mon Sep 17 00:00:00 2001 From: SamuelLangenfeld Date: Wed, 15 Nov 2017 08:15:03 -0500 Subject: [PATCH 16/17] minor --- fileSaves/dummyFile.txt | 0 "fileSaves/dummyFile.txt\n" | 172 +++++++++++++++++++++++++ "fileSaves/kindly.txt\n" | 245 ++++++++++++++++++++++++++++++++++++ 3 files changed, 417 insertions(+) delete mode 100644 fileSaves/dummyFile.txt create mode 100644 "fileSaves/dummyFile.txt\n" create mode 100644 "fileSaves/kindly.txt\n" diff --git a/fileSaves/dummyFile.txt b/fileSaves/dummyFile.txt deleted file mode 100644 index e69de29..0000000 diff --git "a/fileSaves/dummyFile.txt\n" "b/fileSaves/dummyFile.txt\n" new file mode 100644 index 0000000..f3fc666 --- /dev/null +++ "b/fileSaves/dummyFile.txt\n" @@ -0,0 +1,172 @@ +accreditation +antlered +armored +assured +assuredly +assuredness +bewildered +bred +chambered +collared +colored +cornered +covered +credence +credential +credibility +credible +credibly +credit +creditably +creditor +credo +credulity +credulously +credulousness +crossbred +depredate +depredation +depredator +depredatory +discreditable +dredge +dredger +eared +feathered +firedog +flavored +foredoom +fred +hatred +hereditarily +heredity +holstered +hundred +hundredfold +hundredth +hundredweight +inbred +incredible +incredibleness +incredibly +incredulity +incredulously +incredulousness +ingredient +irredeemable +irreducibility +irreducible +kindred +labored +leisured +lowbred +measured +natured +particolored +pilastered +pillared +powdered +predaceous +predate +predation +predatorily +predatory +predecease +predecessor +predesignate +predestinate +predestination +predestine +predeterminate +predetermination +predetermine +predicable +predicament +predicate +predicative +predict +predictable +prediction +predictive +predictor +predigest +predigestion +predilection +predominance +predominancy +predominant +predominantly +predominate +predomination +prepared +red +redact +redaction +redactor +redbreast +redcap +redcoat +redden +reddish +redeem +redemonstrate +redemptive +redemptory +redeposit +redevelop +redhead +redigest +redintegrate +redintegration +redirect +rediscover +redissolve +redistill +redistribute +redistrict +redivide +redivivus +redly +redness +redolent +redouble +redoubt +redoubtable +redraft +redraw +redress +redressal +redresser +reduce +reducer +reducible +reduction +reductive +redundantly +reduplicate +reduplication +sacred +scattered +slurred +smeared +strictured +structured +sugared +tapered +tempered +teredo +thoroughbred +tired +tiredness +towered +tricolored +unconsidered +underbred +unnumbered +unpaired +unredeemed +verdured +visored +weathered +whiskered +withered \ No newline at end of file diff --git "a/fileSaves/kindly.txt\n" "b/fileSaves/kindly.txt\n" new file mode 100644 index 0000000..3836078 --- /dev/null +++ "b/fileSaves/kindly.txt\n" @@ -0,0 +1,245 @@ +foal +foam +foamy +fob +focal +focus +fodder +foe +foeman +foetal +foetus +fog +fogey +foggily +fogginess +fogy +foible +foil +foist +fold +folder +folderol +foliage +foliate +foliated +folio +follicle +follow +follower +following +fomalhaut +fomenter +fond +fondant +fondle +fondu +font +fontanel +fontanelle +food +fool +foolhardily +foolhardiness +foolhardy +foolishly +foolscap +foot +football +footbridge +footfall +foothill +foothold +footing +footless +footman +footnote +footpad +footpath +footprint +footstool +fop +foppish +for +forage +forager +foray +forayer +forbade +forbear +forbearance +forbearer +forbid +forbiddance +forbidden +forbidding +forbore +forborne +force +forced +forceful +forceless +forceps +forcibly +ford +fordable +fore +forearm +forebear +forebode +foreboding +forebodingly +forecast +forecaster +foreclose +foreclosure +foredoom +forefather +forefend +forefinger +forefoot +forefront +foregather +forego +foregoer +foreground +forehand +foreigner +foreignness +foreknow +foreknowledge +forelock +foreman +foremast +foremost +forename +forenamed +forenoon +forensic +foreordain +foreordination +forerunner +foresee +foreseen +foreseer +foreshadow +foreshorten +foresight +foresighted +foreskin +forest +forestall +forester +forestry +foretaste +foretell +foreteller +forethought +foretoken +foretop +forewarn +forewoman +foreword +forfeit +forfeitable +forfeiter +forfend +forgather +forgave +forge +forger +forgetfully +forgettable +forging +forgivable +forgiver +forgiving +forgo +forgot +forgotten +fork +forlornly +forlornness +form +formaldehyde +formalism +formalist +formality +formalize +formally +format +formation +formative +formerly +formic +formica +formication +formidability +formidable +formidableness +formidably +formless +formula +formulate +formulation +fornicate +fornicator +forsooth +forster +forswear +forswore +forsworn +forsythia +fort +forte +forth +forthcoming +forthright +forthrightness +forthwith +fortieth +fortifier +fortify +fortissimo +fortnight +fortnightly +fortress +fortuitous +fortuity +fortunately +fortune +forty +forward +forwarder +forwarding +forwardly +forwardness +forwards +fossil +fossilization +foster +fosterling +fought +foul +foulard +foully +foulness +found +foundation +founder +founding +foundling +fount +four +fourfold +fourscore +foursome +foursquare +fourteen +fourteenth +fourth +fourthly +fowl +fox +foxglove +foxhound \ No newline at end of file From 964123cf95f9bf799920334c677508e98707a881 Mon Sep 17 00:00:00 2001 From: SamuelLangenfeld Date: Wed, 15 Nov 2017 08:21:41 -0500 Subject: [PATCH 17/17] changed file names to be trimmed before saving --- fileSaves/dummyFile.txt | 62 ++++++++- "fileSaves/dummyFile.txt\n" | 172 ------------------------- "fileSaves/kindly.txt\n" | 245 ------------------------------------ index.js | 1 + 4 files changed, 62 insertions(+), 418 deletions(-) delete mode 100644 "fileSaves/dummyFile.txt\n" delete mode 100644 "fileSaves/kindly.txt\n" diff --git a/fileSaves/dummyFile.txt b/fileSaves/dummyFile.txt index 46f29e8..4c066fc 100644 --- a/fileSaves/dummyFile.txt +++ b/fileSaves/dummyFile.txt @@ -1 +1,61 @@ -red \ No newline at end of file +afresh +alfresco +comfrey +confrere +freak +freakish +freckle +freckled +freckly +fred +free +freebooter +freeborn +freedman +freehold +freeholder +freely +freemason +freemasonry +freeness +freestone +freethinker +freethinking +freewheel +freewill +freezable +freeze +freezer +freezing +freight +french +frenchman +frenetic +frenetical +frenum +frenzied +frenzy +frequentative +frequenter +frequently +frequentness +fresco +fresh +freshen +freshly +freshman +freshness +fret +fretful +fretted +fretter +fretwork +freya +infrequent +infrequently +refresh +refresher +refreshing +unfree +unfreeze +unfrequented \ No newline at end of file diff --git "a/fileSaves/dummyFile.txt\n" "b/fileSaves/dummyFile.txt\n" deleted file mode 100644 index f3fc666..0000000 --- "a/fileSaves/dummyFile.txt\n" +++ /dev/null @@ -1,172 +0,0 @@ -accreditation -antlered -armored -assured -assuredly -assuredness -bewildered -bred -chambered -collared -colored -cornered -covered -credence -credential -credibility -credible -credibly -credit -creditably -creditor -credo -credulity -credulously -credulousness -crossbred -depredate -depredation -depredator -depredatory -discreditable -dredge -dredger -eared -feathered -firedog -flavored -foredoom -fred -hatred -hereditarily -heredity -holstered -hundred -hundredfold -hundredth -hundredweight -inbred -incredible -incredibleness -incredibly -incredulity -incredulously -incredulousness -ingredient -irredeemable -irreducibility -irreducible -kindred -labored -leisured -lowbred -measured -natured -particolored -pilastered -pillared -powdered -predaceous -predate -predation -predatorily -predatory -predecease -predecessor -predesignate -predestinate -predestination -predestine -predeterminate -predetermination -predetermine -predicable -predicament -predicate -predicative -predict -predictable -prediction -predictive -predictor -predigest -predigestion -predilection -predominance -predominancy -predominant -predominantly -predominate -predomination -prepared -red -redact -redaction -redactor -redbreast -redcap -redcoat -redden -reddish -redeem -redemonstrate -redemptive -redemptory -redeposit -redevelop -redhead -redigest -redintegrate -redintegration -redirect -rediscover -redissolve -redistill -redistribute -redistrict -redivide -redivivus -redly -redness -redolent -redouble -redoubt -redoubtable -redraft -redraw -redress -redressal -redresser -reduce -reducer -reducible -reduction -reductive -redundantly -reduplicate -reduplication -sacred -scattered -slurred -smeared -strictured -structured -sugared -tapered -tempered -teredo -thoroughbred -tired -tiredness -towered -tricolored -unconsidered -underbred -unnumbered -unpaired -unredeemed -verdured -visored -weathered -whiskered -withered \ No newline at end of file diff --git "a/fileSaves/kindly.txt\n" "b/fileSaves/kindly.txt\n" deleted file mode 100644 index 3836078..0000000 --- "a/fileSaves/kindly.txt\n" +++ /dev/null @@ -1,245 +0,0 @@ -foal -foam -foamy -fob -focal -focus -fodder -foe -foeman -foetal -foetus -fog -fogey -foggily -fogginess -fogy -foible -foil -foist -fold -folder -folderol -foliage -foliate -foliated -folio -follicle -follow -follower -following -fomalhaut -fomenter -fond -fondant -fondle -fondu -font -fontanel -fontanelle -food -fool -foolhardily -foolhardiness -foolhardy -foolishly -foolscap -foot -football -footbridge -footfall -foothill -foothold -footing -footless -footman -footnote -footpad -footpath -footprint -footstool -fop -foppish -for -forage -forager -foray -forayer -forbade -forbear -forbearance -forbearer -forbid -forbiddance -forbidden -forbidding -forbore -forborne -force -forced -forceful -forceless -forceps -forcibly -ford -fordable -fore -forearm -forebear -forebode -foreboding -forebodingly -forecast -forecaster -foreclose -foreclosure -foredoom -forefather -forefend -forefinger -forefoot -forefront -foregather -forego -foregoer -foreground -forehand -foreigner -foreignness -foreknow -foreknowledge -forelock -foreman -foremast -foremost -forename -forenamed -forenoon -forensic -foreordain -foreordination -forerunner -foresee -foreseen -foreseer -foreshadow -foreshorten -foresight -foresighted -foreskin -forest -forestall -forester -forestry -foretaste -foretell -foreteller -forethought -foretoken -foretop -forewarn -forewoman -foreword -forfeit -forfeitable -forfeiter -forfend -forgather -forgave -forge -forger -forgetfully -forgettable -forging -forgivable -forgiver -forgiving -forgo -forgot -forgotten -fork -forlornly -forlornness -form -formaldehyde -formalism -formalist -formality -formalize -formally -format -formation -formative -formerly -formic -formica -formication -formidability -formidable -formidableness -formidably -formless -formula -formulate -formulation -fornicate -fornicator -forsooth -forster -forswear -forswore -forsworn -forsythia -fort -forte -forth -forthcoming -forthright -forthrightness -forthwith -fortieth -fortifier -fortify -fortissimo -fortnight -fortnightly -fortress -fortuitous -fortuity -fortunately -fortune -forty -forward -forwarder -forwarding -forwardly -forwardness -forwards -fossil -fossilization -foster -fosterling -fought -foul -foulard -foully -foulness -found -foundation -founder -founding -foundling -fount -four -fourfold -fourscore -foursome -foursquare -fourteen -fourteenth -fourth -fourthly -fowl -fox -foxglove -foxhound \ No newline at end of file diff --git a/index.js b/index.js index 186fc30..079e083 100644 --- a/index.js +++ b/index.js @@ -106,6 +106,7 @@ function start() { //determines if existing file let onSave = data => { + data = data.trim(); let savePath = "./fileSaves/" + data; if (fs.existsSync(savePath)) { console.log("That file exists, overwrite? y/n?");