<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: KiminLee</title>
    <description>The latest articles on DEV Community by KiminLee (@klee214).</description>
    <link>https://dev.to/klee214</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F469152%2F388dbfdc-956a-4b83-810b-d4e2d07102a8.png</url>
      <title>DEV Community: KiminLee</title>
      <link>https://dev.to/klee214</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/klee214"/>
    <language>en</language>
    <item>
      <title>Release 04 part3: Changing the lexer algorithm</title>
      <dc:creator>KiminLee</dc:creator>
      <pubDate>Fri, 11 Dec 2020 16:04:16 +0000</pubDate>
      <link>https://dev.to/klee214/release-04-part3-changing-the-lexer-algorithm-148f</link>
      <guid>https://dev.to/klee214/release-04-part3-changing-the-lexer-algorithm-148f</guid>
      <description>&lt;h3&gt;
  
  
  Read the previous blog please (this blog is written assuming readers already read the previous blog)
&lt;/h3&gt;

&lt;h3&gt;
  
  
  Before start
&lt;/h3&gt;

&lt;p&gt;Previosuly, I used es6 arrow function, but after I went through the program, I realized that the program did not use arrow function at all, so I changed the new arrow function to the es5 function.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const regexTerms = () =&amp;gt; {
function regexTerms() {
...

const resolveRegex = () =&amp;gt; {
function resolveRegex() {
...
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Also, most of the code was using &lt;code&gt;let&lt;/code&gt;, even if the variable was actually constant. So I changed them either.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  let rawRegex = regexTerms.join("|");
  let mainRegex = new RegExp(rawRegex, "gi");
  let mainRegex = regexTerms();
  let resolverRegexes = resolveRegex();

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  const rawRegex = regexTerms.join("|");
  const mainRegex = new RegExp(rawRegex, "gi");
  const mainRegex = regexTerms();
  const resolverRegexes = resolveRegex(lexerItem);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Problem
&lt;/h3&gt;

&lt;p&gt;So, the main problem was there was too many loop to generate "lexer object" to be compiled after all. &lt;/p&gt;

&lt;p&gt;Simply the algorithm looks like this,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// three levels loop
lexerResults.map(lexerResult=&amp;gt;{
   for(let i = 0; i &amp;lt; resolverRegexes.length; i++){
      ...
      Object.keys(tokens.tokens).forEach((token)=&amp;gt;{
       ...
      })
   }
})
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So, inside the &lt;code&gt;map&lt;/code&gt; loop, there is &lt;code&gt;for&lt;/code&gt; loop, then inside the &lt;code&gt;for&lt;/code&gt; there is also &lt;code&gt;foreach&lt;/code&gt; loop. If we can solve this problem out. (For example, reduce &lt;code&gt;loop&lt;/code&gt;), the efficiency will be enhanced.&lt;/p&gt;

&lt;h3&gt;
  
  
  Solution
&lt;/h3&gt;

&lt;p&gt;So, essentially &lt;code&gt;resolveLexerItemMetadata&lt;/code&gt; was doing compare first, then make the object later (which was made in another function beforehand). But, what if the process is combined into one single function, I mean, compare and make the object at the same time.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// function: creating the object.
function resolveRegex() {
  let resolverRegexes = [];
  Object.keys(tokens.tokens).forEach((token) =&amp;gt; {
    resolverRegexes.push({
      match: new RegExp(`(${tokens.tokens[token].match})`, "gi"),
      data: {
        identifier: token,
      },
    });

// function: comparing with the given token and object
unction resolveLexerItemMetadata(lexerItem) {
  let data = {};
  const resolverRegexes = resolveRegex(lexerItem);
  for (let i = 0; i &amp;lt; resolverRegexes.length; i++) {
    if (lexerItem.match(resolverRegexes[i].match) != null) {
      data["identifier"] = resolverRegexes[i].data.identifier;
      data["token"] = lexerItem;

      break;
    }
  }
  return data;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Solution 2
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/* Instead of creating an array of objects for Token to be compared with given lexerItm,
*  Find the token with the lexerItm, then return a single object
*  Previous version, let n = the num of tokens, the best case is Ω(n) runtime.
*  This version, let n = the num of tokens, the best case is Ω(1) runtime.
*/
function resolveRegex(lexerItem) {
  const foundToken = Object.keys(tokens.tokens).find((token) =&amp;gt; {
    const matchReg = new RegExp(`(${tokens.tokens[token].match})`, "gi");
    return lexerItem.match(matchReg) != null ? true : false;
  });
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Instead of creating a &lt;code&gt;resolvedToken&lt;/code&gt; object (intermediate object), simply find the token and if found, creating a final version of object.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function parseLine(line) {
  const lexerResults = line.match(mainRegex); // The Regex result is quickly translated into an array
  let lexeredLine = [];
  lexerResults.map((lexerResult) =&amp;gt; {
    lexeredLine.push(resolveRegex(lexerResult));
  });
  return lexeredLine;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;By doing so, we can remove the &lt;code&gt;resolveLexerItemMetadata&lt;/code&gt; function and put the process altogether.&lt;br&gt;
This will results in reducing one extra loop (&lt;code&gt;foreach&lt;/code&gt; loop).&lt;/p&gt;

&lt;p&gt;After testing the runtime, I could see the runtime is much faster: approximately 20%. &lt;/p&gt;

&lt;p&gt;Visit the &lt;a href="https://github.com/PrivateGER/GreenLight/pull/21/commits/930c229932a6600a83494e41345de422344084ab"&gt;PR&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Conclusion
&lt;/h3&gt;

&lt;p&gt;At first, I tried to contribute to the bigger project (even if a small change). However, It is hard to find a good one for me even though I watched lecture and  tried to practice. &lt;br&gt;
The simple bug is already taken by others, and lots of code I cannot understand. &lt;br&gt;
The reason, I think, is I might be too afraid of failing to create PR. So personally, I score myself 80/100&lt;/p&gt;

&lt;p&gt;Even though I could not achieve my goal(contributing to the real project like react.js, next.js ...), I learned a lot of Open Source Development community and environment. How to look for contribution, license, unit testing, git command and communicate with open source development community. &lt;/p&gt;

&lt;p&gt;These assets are not something to disappear. This semester is to be end, but my programming experience just begin. I will keep practice the thing I have learned in this course and try to keep connecting with the community. And later I will be able to contribute to the real world project.  &lt;/p&gt;

</description>
    </item>
    <item>
      <title>The last lab: git tagging, and publishing to npm</title>
      <dc:creator>KiminLee</dc:creator>
      <pubDate>Sun, 06 Dec 2020 00:05:26 +0000</pubDate>
      <link>https://dev.to/klee214/the-last-lab-git-tagging-and-publishing-to-npm-310j</link>
      <guid>https://dev.to/klee214/the-last-lab-git-tagging-and-publishing-to-npm-310j</guid>
      <description>&lt;h3&gt;
  
  
  git tagging
&lt;/h3&gt;

&lt;p&gt;Git has the ability to tag specific points in a repository’s history as being important. Git tag is essentially a kind of version control. The semantic versioning has a convention to be followed. For more information visit the &lt;a href="https://docs.npmjs.com/about-semantic-versioning"&gt;site&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;At first, I have zero idea about git tagging. I have used branches name and commit number to track down or retrieve my previous commit. BUT never tagging my commit with version number.&lt;/p&gt;

&lt;p&gt;So, I needed to first understand what the tagging is and how to use that. Thankfully we have a great professor who are teaching us about git. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Here is the basic instruction you to follow to add a git tag:&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;code&gt;git tag -a &amp;lt;version&amp;gt; -m [message]&lt;/code&gt; :  this will add the new tag to your current commit.&lt;br&gt;
&lt;code&gt;git tag -d &amp;lt;version&amp;gt;&lt;/code&gt; :  this will drop the tag&lt;br&gt;
&lt;code&gt;git tag show&lt;/code&gt; : this will show the lists of the git tag&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  v0.9.0
&lt;/h3&gt;

&lt;p&gt;Up until now, the code is not ready to be published. So I decided to call the program at that moment is version 0.9.0. Before making release 1.0.0. I needed to make couple update in the program.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;The first: If your file is not inside the same directory of the program. The file cannot be read. Because the file is just passed by name only without path. So I needed to make sure that regardless where the file is, the program should read the file based on their name only. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Update the README.md and changing the program name: Since the npm package should have unique name I needed to come up with a real unique name, for this I decided to add my name to the program name &lt;code&gt;kimin-url-tester&lt;/code&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  release 1.0.0
&lt;/h3&gt;

&lt;p&gt;To publish the program. First I needed to sign up the npm website. Once verifying email, we can publish our package. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--WkHrRfn_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/l7b1h2t990jzs5ipij97.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--WkHrRfn_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/l7b1h2t990jzs5ipij97.PNG" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;After success in login, you can hit &lt;code&gt;npm publish&lt;/code&gt;&lt;br&gt;
Keep in mind! this will only happen after verifying your email. &lt;/p&gt;

&lt;p&gt;You can see your package in your profile&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--4WGR7m0Y--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/ky5zsndywa4wft5plepb.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--4WGR7m0Y--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/ky5zsndywa4wft5plepb.PNG" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The test:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Te7-LPUF--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/ujgog2xaqvbz9a4tw0xc.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Te7-LPUF--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/ujgog2xaqvbz9a4tw0xc.PNG" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>What is the problem, what would be the best solution?</title>
      <dc:creator>KiminLee</dc:creator>
      <pubDate>Sat, 05 Dec 2020 00:52:30 +0000</pubDate>
      <link>https://dev.to/klee214/what-is-the-problem-what-would-be-the-best-solution-15c3</link>
      <guid>https://dev.to/klee214/what-is-the-problem-what-would-be-the-best-solution-15c3</guid>
      <description>&lt;h3&gt;
  
  
  Make another lexer.js vs use the original one and update it
&lt;/h3&gt;

&lt;p&gt;The issue is updating the &lt;code&gt;lexer.js&lt;/code&gt;. And the maintainer of the open source project allowed me to modify the code structure. However, it is really good idea to create a whole new brand of &lt;code&gt;lexer.js&lt;/code&gt; or just to remove the useless parts and replace them with new codes? &lt;/p&gt;

&lt;p&gt;To decide it, let's take a look at the code.&lt;/p&gt;

&lt;h3&gt;
  
  
  What does the lexer.js really do in the program.
&lt;/h3&gt;

&lt;p&gt;This program mainly have 4 parts.&lt;/p&gt;

&lt;blockquote&gt;
&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;em&gt;tokens: A pair of keyword and value. This is the list of syntax of the program to be compiled. If the words read from a file match with one of the token, the program know that the word is meaningful syntax.&lt;/em&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;_lexer: basically convert the raw input into meaningful object which later can be transplied.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;em&gt;transplie : take the object from &lt;code&gt;lexer.js&lt;/code&gt;. If all syntax are correct then make the codes to javascript codes.&lt;/em&gt; &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;em&gt;syntax checker : check if the object from &lt;code&gt;lexer.js&lt;/code&gt; is all correct if not issue the syntax errors&lt;/em&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  inside the lexer.js
&lt;/h3&gt;

&lt;p&gt;So, let's explain the lexer engine again step by step:&lt;/p&gt;

&lt;blockquote&gt;
&lt;ol&gt;
&lt;li&gt;&lt;p&gt;find all of the possible &lt;code&gt;token&lt;/code&gt;(the words predefined in the program to be compiled later, eg) 'print(), var ...')&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;transform the raw data into the array of the token (need to be sorted: first in first out)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;compare the token the object which has &lt;code&gt;identifier&lt;/code&gt;(the name of the token) and &lt;code&gt;regex&lt;/code&gt;(regular expression).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;If they are matched, it will create an object(&lt;code&gt;token&lt;/code&gt; and &lt;code&gt;identifier&lt;/code&gt;). This object will be compiled later in the &lt;code&gt;transplier.js&lt;/code&gt; (final version of object)&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;/blockquote&gt;

&lt;p&gt;step 1 to 2, I should not modify them because if they were changed, all the predefined &lt;code&gt;token&lt;/code&gt; will be useless (needs new token system).&lt;/p&gt;

&lt;p&gt;Also, the lexer engine has to pass the object to the &lt;code&gt;transplier.js&lt;/code&gt;, so that the raw code can be successfuly compiled later.&lt;/p&gt;

&lt;p&gt;So, I could only change the step 3.&lt;/p&gt;

&lt;h3&gt;
  
  
  The thing to be upgraded
&lt;/h3&gt;

&lt;p&gt;So far, there is so much work to be upgraded like &lt;code&gt;var&lt;/code&gt; ----&amp;gt; &lt;code&gt;let&lt;/code&gt; or &lt;code&gt;const&lt;/code&gt;. Removing global variable, reform the code structure...&lt;/p&gt;

&lt;p&gt;In this week, I changed the structure of the code first so that the upgrade can be done well later. &lt;/p&gt;

&lt;p&gt;I first removed all the global variable in the &lt;code&gt;lexer,js&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let colors = require("./colors");
let tokens = require("./tokens");


let regexTerms = [];
let rawRegex = "";
let mainRegex;
let resolverRegexes = [];

Object.keys(tokens.tokens).forEach((token) =&amp;gt; { // Populate main regex
    regexTerms.push(`${tokens.tokens[token].match}`);
});

Object.keys(tokens.tokens).forEach((token) =&amp;gt; {
    resolverRegexes.push({
        "match": new RegExp(`(${tokens.tokens[token].match})`, "gi"),
        "data": {
            "identifier": token
        }
    });
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And create a new &lt;code&gt;.js&lt;/code&gt; file called &lt;code&gt;lexerToken.js&lt;/code&gt;.  This new file will generate the intermediate &lt;code&gt;token&lt;/code&gt; object which will help to create the final version of object (used in &lt;code&gt;transpiler.js&lt;/code&gt;)&lt;/p&gt;

&lt;p&gt;This commit can be found in &lt;a href="https://github.com/PrivateGER/GreenLight/pull/21/commits/3876aaf2df1b98e8dca658b460624285ff00a287"&gt;here&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;After the work, now &lt;code&gt;lexerToken&lt;/code&gt; only handle the token related job. And &lt;code&gt;lexer&lt;/code&gt; will only handle transform the raw data into the completed object with token object.&lt;/p&gt;

&lt;h3&gt;
  
  
  next step
&lt;/h3&gt;

&lt;p&gt;The thing is, it took long time to compile big amount of codes. So the lexer engine needs to have smaller runtime. &lt;/p&gt;

&lt;p&gt;The main reason for too much runtime may be the too many &lt;code&gt;loop&lt;/code&gt;. So , the next step is find the extra &lt;code&gt;loop&lt;/code&gt; and reduce it and change the algorithm.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Release 0.4: Part1, choosing a open-source project </title>
      <dc:creator>KiminLee</dc:creator>
      <pubDate>Tue, 01 Dec 2020 23:25:09 +0000</pubDate>
      <link>https://dev.to/klee214/release-0-4-part1-choosing-a-open-source-project-2djg</link>
      <guid>https://dev.to/klee214/release-0-4-part1-choosing-a-open-source-project-2djg</guid>
      <description>&lt;h3&gt;
  
  
  First try and failure
&lt;/h3&gt;

&lt;p&gt;In the last weekend, I found the very nice project which is really huge. &lt;a href="https://github.com/magento/pwa-studio"&gt;PWA Studio&lt;/a&gt; is a collection of tools that lets developers build complex Progressive Web Applications on top of Magento 2 stores. There are more than 100 contributors.&lt;/p&gt;

&lt;p&gt;The issue was even if the filter was changed, it is not actually applied. &lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--H0co6fhJ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://user-images.githubusercontent.com/789614/100354582-aad9f780-2ff0-11eb-8fa9-eb01c42eef5f.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--H0co6fhJ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://user-images.githubusercontent.com/789614/100354582-aad9f780-2ff0-11eb-8fa9-eb01c42eef5f.png" alt="alt"&gt;&lt;/a&gt;&lt;br&gt;
The person who raised this issue told that it might be because of GraphQL or any front-end issue. As I didn't know the GraphQL, I tried to find out what it is, then try to install the code and figure out what the problem is. &lt;br&gt;
After spending couple days on it, I realized this was the thing that was beyond my ability. I needed to find out other project. &lt;/p&gt;

&lt;h3&gt;
  
  
  Small but needed to be changed a lot!
&lt;/h3&gt;

&lt;p&gt;I spent an entire day to search github for this release 0.4. However, I was more careful to choose one after the failure. I didn't want to take another risk.&lt;/p&gt;

&lt;p&gt;After all, I have decided to contribute the project that I have done before. The &lt;a href="https://github.com/PerhapsSomeone/GreenLight"&gt;GreenLight&lt;/a&gt; has been looking for someone to update the important part of the program since that time. He wants to update the lexical system of the program.&lt;br&gt;
 It requires a lot of coding and changing the program a lot. &lt;br&gt;
Even if the project is really small, I think this might be worth contribution.&lt;/p&gt;

&lt;h3&gt;
  
  
  Plan for this
&lt;/h3&gt;

&lt;p&gt;The issue is making a better system for transpiling the raw code to be read by Node.js. I don't know what would be the best solution for this system. So for next couple days, I will find out what would be the best model for it.&lt;/p&gt;

&lt;p&gt;I will keep update the changes.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Added unit-test and CI to the findBreakURL program!</title>
      <dc:creator>KiminLee</dc:creator>
      <pubDate>Thu, 26 Nov 2020 02:43:46 +0000</pubDate>
      <link>https://dev.to/klee214/added-unit-test-and-ci-to-the-findbreakurl-program-4034</link>
      <guid>https://dev.to/klee214/added-unit-test-and-ci-to-the-findbreakurl-program-4034</guid>
      <description>&lt;h3&gt;
  
  
  Should we run the program every time?
&lt;/h3&gt;

&lt;p&gt;After implementing all codes for this program, I need to manually run the program and if there is any bug on there. To see what lines are wrong and what function throws error, I coded &lt;code&gt;console.log&lt;/code&gt; hundreds of times. This is really TIME CONSUMING!&lt;/p&gt;

&lt;p&gt;Now, it is time to introduce unit tests for my program to make the process faster and more reliable. Then, the question is what is the unit tests?&lt;/p&gt;

&lt;h3&gt;
  
  
  One test module will make your life so much easier
&lt;/h3&gt;

&lt;p&gt;Test module is only for literally testing your program. However, it focuses on one specific job rather than a whole process. &lt;br&gt;
Let's imagine, you are baking a cookie. There are many ingredients to be prepared beforehand. How much sugar is needed and what type of flour should be used, something like these. It is hard to check them all at once just before put altogether. The best way is make a check list and check each of them are OK. Likewise, unit test is checking each function or component is passed. &lt;/p&gt;
&lt;h3&gt;
  
  
  JEST is the BEST
&lt;/h3&gt;

&lt;p&gt;There are many test tool like JASMINE, ENZYME and KARMA...BUT They are so much similar. So don't take too much time to choose the tools!&lt;/p&gt;

&lt;p&gt;For my project, I used JEST because I have used that before for my react.js project and my prof is using this tool too!&lt;/p&gt;

&lt;p&gt;To set up &lt;br&gt;
&lt;code&gt;npm i jest --save-dev&lt;/code&gt;&lt;br&gt;
This will make the jest installed as a devDependencies.&lt;/p&gt;
&lt;h3&gt;
  
  
  FileRead.test.js
&lt;/h3&gt;

&lt;p&gt;Let's create a test file for file reading. The file reading is essentially reading a file from given path or file name. However, we cannot use the normal file system for our test. We need to somehow create a mock file system.&lt;/p&gt;

&lt;p&gt;Thankfully, Jest already has mock file system. For more info please visit the &lt;a href="https://jestjs.io/docs/en/manual-mocks"&gt;JEST documentation&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In the &lt;code&gt;__mocks__/fs.js&lt;/code&gt; file :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const fs = jest.createMockFromModule('fs');
...
function __setMockFileData(filename, data) {
    mockFiles = {};
    mockFiles[filename] = data;
}
...
function readFileSync(filename) {
    const data = mockFiles[filename];

    if (data) {
        return data;
    } else {
        throw new Error("invalid file");
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;
&lt;code&gt;createMockFromModule&lt;/code&gt; will generate a mock filesystem.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;__setMockFileData&lt;/code&gt; will receive given filename and put the given value into the correspond filename (acting like the file and data)&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;readFileSync&lt;/code&gt; is overloaded and performed when the test file is needed to call this function.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Now, this module will generate mock file system. It is time to make a test&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const { fileRead, readDirectory } = require('./fileRead');

jest.mock('fs');
const fs = require('fs');

describe('file reading test', () =&amp;gt; {
    const filename = 'file';
    const fileData = '&amp;lt;p&amp;gt;Hello World&amp;lt;/p&amp;gt;';

    beforeAll(() =&amp;gt; {
        fs.__setMockFileData(filename, fileData);
    });

    ...

    test('reading an existing file should work', () =&amp;gt; {
        const data = fileRead(filename);
        expect(data).toEqual(fileData);
    });
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;test('reading an existing file should work')&lt;/code&gt; will be passed if &lt;code&gt;fileData&lt;/code&gt; is equal to "&lt;/p&gt;
&lt;p&gt;Hello World&lt;/p&gt;"

&lt;p&gt;Reading a directory is so much similar to this logic. You can also find more info &lt;a href="https://jestjs.io/docs/en/manual-mocks#examples"&gt;here&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  axios_fetch.test.js
&lt;/h3&gt;

&lt;p&gt;This will send a get request with axios. So before test this module, we need to create a mock request for testing. &lt;a href="https://www.npmjs.com/package/nock"&gt;nock&lt;/a&gt; is a great package for this.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const { axiosFetch } = require('./axios_fetch');
const nock = require('nock');

describe('fetching test', () =&amp;gt; {
...
    test('reading from an existing URL should work', async () =&amp;gt; {
        const url = 'https://test.ca';

        nock(url).get('/').reply(200);
        const status = await axiosFetch(url);
        expect(status).toEqual(200);
    });
...
})
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;nock(url).get(root).reply(status)&lt;/code&gt; will make a mock request which seems valid request just for testing. Once you make a fake http URL, you can test your fetch function using with this.&lt;/p&gt;

&lt;p&gt;However, if you use axios you need to first set your &lt;code&gt;@jest-environment&lt;/code&gt; configuration to node (default is jsdom).&lt;/p&gt;

&lt;p&gt;For more information visit this &lt;a href="https://github.com/axios/axios/issues/2654"&gt;issue&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now, your are read to test. result below:&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--zsVgbnY4--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/dy18c710etm4477fff3j.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--zsVgbnY4--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/dy18c710etm4477fff3j.PNG" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Add an infinite scroll  function to Telescope</title>
      <dc:creator>KiminLee</dc:creator>
      <pubDate>Thu, 19 Nov 2020 02:52:41 +0000</pubDate>
      <link>https://dev.to/klee214/add-an-infinite-scroll-function-to-telescope-51f5</link>
      <guid>https://dev.to/klee214/add-an-infinite-scroll-function-to-telescope-51f5</guid>
      <description>&lt;h3&gt;
  
  
  getting started
&lt;/h3&gt;

&lt;p&gt;So far, the Telescope generates more posts only when the "more post" button was click. Thanks to &lt;code&gt;useSWRInfinite()&lt;/code&gt; and &lt;code&gt;IntersectionObserver&lt;/code&gt;, the new posts can be rendered infinitely. &lt;/p&gt;

&lt;h3&gt;
  
  
  Implementation
&lt;/h3&gt;

&lt;p&gt;First of all, we are going to grab a node, so we need &lt;code&gt;useRef&lt;/code&gt; hook. Also, &lt;code&gt;IntersectionObserver&lt;/code&gt; will be declared and assigned once the page is all loaded, so we need to have &lt;code&gt;useEffect&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import React, { useEffect, useRef } from 'react';
...
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Second, we need to find out which node should be the flag that the current post is the last post, and the new posts should rendered. &lt;/p&gt;

&lt;p&gt;We can reuse the code from previous &lt;code&gt;loadMoreButton.jsx&lt;/code&gt; button node.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    &amp;lt;Container&amp;gt;
      &amp;lt;Grid item xs={12} className={classes.content}&amp;gt;
        &amp;lt;Button ref={$buttonRef}&amp;gt;Load More Posts&amp;lt;/Button&amp;gt;
      &amp;lt;/Grid&amp;gt;
    &amp;lt;/Container&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This node will be the reference to indicate the post is the end of the current posts.&lt;/p&gt;

&lt;p&gt;Third, we need to make it actually happen!&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;useEffect(() =&amp;gt; {
    const options = {
      root: null,
      threshold: 1.0,
    };

    const observer = new IntersectionObserver(
      (entries) =&amp;gt;
        entries.forEach((entry) =&amp;gt; {
          if (entry.isIntersecting) {
            onScroll();
          }
        }),
      options
    );
    observer.observe($buttonRef.current);

    return () =&amp;gt; {
      observer.unobserve($buttonRef.current);
    };
  }, []);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will make the selected button node to be acted like a flag for check.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Migrating Weather application to React.js</title>
      <dc:creator>KiminLee</dc:creator>
      <pubDate>Wed, 18 Nov 2020 19:23:53 +0000</pubDate>
      <link>https://dev.to/klee214/migrating-weather-application-to-react-js-5b1k</link>
      <guid>https://dev.to/klee214/migrating-weather-application-to-react-js-5b1k</guid>
      <description>&lt;h3&gt;
  
  
  Before getting started
&lt;/h3&gt;

&lt;p&gt;For 1 weeks and half, I wandered in Github, finding an issue that is interesting to me. There are many people who are looking for contribution to get help, or many company to solve buggy issues. Those are all OK, but this time none of them is actually appealing to me.&lt;/p&gt;

&lt;p&gt;SO, this time, I decided to enhance one of my project which I always wanted to be done since deploying the application, &lt;a href="https://kimin-weather-app.herokuapp.com/weather" rel="noopener noreferrer"&gt;Weather App&lt;/a&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  How is the weather?
&lt;/h3&gt;

&lt;p&gt;Thanks to Google service, we can know the weather without an weather forecast or actually going outside. &lt;/p&gt;

&lt;p&gt;But, when you wonder what the current weather is in a certain city, not your place, and if you want to find it out, Google is not a great option. It is not faster that you expected and it might be a too heavy web service. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fwwweag2qhdjft6dqupku.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fwwweag2qhdjft6dqupku.PNG" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://kimin-weather-app.herokuapp.com/weather" rel="noopener noreferrer"&gt;Weather Application&lt;/a&gt; is a small-size web application to help search weather by a city name. &lt;/p&gt;

&lt;p&gt;It uses Darksky API and Mapbox API to get real-time weather information.&lt;/p&gt;

&lt;h3&gt;
  
  
  What is the issue?
&lt;/h3&gt;

&lt;p&gt;The &lt;a href="https://github.com/klee214/Weather.app/issues/1" rel="noopener noreferrer"&gt;issue&lt;/a&gt; is integrate the program with react.js. Which means, the app is currently only written in Node.js. It only has server-side program, and to render &lt;code&gt;.html&lt;/code&gt; page, it relies on &lt;code&gt;handlebars&lt;/code&gt;. &lt;/p&gt;

&lt;p&gt;It perfectly works, but the problem is, It doesn't support responsive UI. When you view this on mobile-platform, it isn't good. Also, because it has many &lt;code&gt;handlebar&lt;/code&gt; files, and render them, it took some time to load the pages.&lt;/p&gt;

&lt;p&gt;These problem would be solved if the program is separated to server-side with node.js and front-end with react.js&lt;/p&gt;

&lt;h3&gt;
  
  
  Install React.js
&lt;/h3&gt;

&lt;p&gt;To get started, we need to first install React.js.&lt;br&gt;
&lt;code&gt;npx create-react-app [app-name]&lt;/code&gt; will generate the React app in the directory. If you don't install react on your machine, it will ask for installation first.&lt;/p&gt;

&lt;p&gt;After that you will get a sample react.js project.&lt;/p&gt;
&lt;h3&gt;
  
  
  Make a component structure
&lt;/h3&gt;

&lt;p&gt;The application has mainly 6 parts. --- Header, Navbar, About, Search, Result, Footer ---. So, create a component tree like this.&lt;/p&gt;

&lt;p&gt;Main/ &lt;br&gt;
   |---Header/Navbar/&lt;br&gt;
|---Header/NavBand/&lt;br&gt;
|---Header/NavLink/&lt;br&gt;
   |--- Footer/&lt;br&gt;
   |--- Search/&lt;/p&gt;

&lt;p&gt;And for each folder they have &lt;code&gt;[component_name].jsx&lt;/code&gt; file.&lt;/p&gt;
&lt;h3&gt;
  
  
  Make a migrating a program from &lt;code&gt;handlebars&lt;/code&gt; to &lt;code&gt;.jsx&lt;/code&gt;
&lt;/h3&gt;

&lt;p&gt;Main folder is a root container which will contain all components. This will use &lt;code&gt;Switch&lt;/code&gt; and &lt;code&gt;React.lazy&lt;/code&gt; load, and &lt;code&gt;react-router-dom&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import React from "react";
import { Route, Switch } from "react-router-dom";
import "./App.css";
...
const App = () =&amp;gt; {
...
  return (
         &amp;lt;div className="App"&amp;gt;
          ....
         &amp;lt;/div&amp;gt; 
   );
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Search component:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const Search = (props) =&amp;gt; {
  ...
  return (
    &amp;lt;div className={styles.main-content}&amp;gt;
      &amp;lt;p&amp;gt;Use this site to get your weather!&amp;lt;/p&amp;gt;

      &amp;lt;form &amp;gt;
        &amp;lt;input className={styles.input} placeholder="Location..." /&amp;gt;
        &amp;lt;button className={styles.button}&amp;gt;Search&amp;lt;/button&amp;gt;
      &amp;lt;/form&amp;gt;
    ...
    &amp;lt;/div&amp;gt;
  );
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Header Component
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const Header = (props) =&amp;gt; {
 ...
  return (
    &amp;lt;div className={styles.header}&amp;gt;
        ...
    &amp;lt;/div&amp;gt;
  );
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Like above two components, other component is implemented similarily.&lt;/p&gt;

&lt;h3&gt;
  
  
  What's the next?
&lt;/h3&gt;

&lt;p&gt;Because of limited time, and so much works to do for this. I separate the issue into 3 more. &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://github.com/klee214/Weather.app/issues/3" rel="noopener noreferrer"&gt;We need to make a REST API server&lt;/a&gt; ----&amp;gt; which will our client &lt;code&gt;axios&lt;/code&gt; can get the request from there.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://github.com/klee214/Weather.app/issues/4" rel="noopener noreferrer"&gt;Make a different CSS style&lt;/a&gt; -----&amp;gt; So far, the program is using the same CSS style for now. Bootstrap and &lt;code&gt;.module.css&lt;/code&gt; will be used.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://github.com/klee214/Weather.app/issues/4" rel="noopener noreferrer"&gt;Make a &lt;code&gt;redux&lt;/code&gt; or &lt;code&gt;hook&lt;/code&gt; to handle &lt;code&gt;state&lt;/code&gt; and communicate with REST API.&lt;/a&gt; -----&amp;gt; this will make the app is fully implemented.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Once the above are all solved, the issue will be continued. I will update gradually once all three issues are done.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Installing and setting up eslint and prettier configuration!! </title>
      <dc:creator>KiminLee</dc:creator>
      <pubDate>Thu, 12 Nov 2020 00:27:17 +0000</pubDate>
      <link>https://dev.to/klee214/installing-and-setting-up-eslint-and-prettier-configuration-18hb</link>
      <guid>https://dev.to/klee214/installing-and-setting-up-eslint-and-prettier-configuration-18hb</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;If you were working alone, coding yourself and make a good project without others' contribution, you might seem OK so far, BUT NOT ANYMORE.&lt;br&gt;
If you are thinking of being a open source developer, you need to collaborate with strangers via online. Trust them, and give them a freedom on the project to fix bug, improve the code. Which means you barely have a full control on your project (since the project is NOT for all yours, but for everyone). &lt;/p&gt;

&lt;p&gt;As you have a certain preference on your coding style, others do. If everyone code with different coding-style, the project is not readable and maintainable. Also, for the new contributor, they will be too exhausted to find out what's going on the project. &lt;/p&gt;
&lt;h3&gt;
  
  
  &lt;strong&gt;There are two possible solution to solve this problem&lt;/strong&gt;
&lt;/h3&gt;
&lt;h4&gt;
  
  
  &lt;em&gt;1. Make a good documentation to give a guideline for contributors&lt;/em&gt;
&lt;/h4&gt;

&lt;p&gt;You can choose a one great style-guideline and let them know your project is following this style. By doing so, everyone knows that they need to follow the code-style to contribute.&lt;/p&gt;
&lt;h4&gt;
  
  
  &lt;em&gt;2. Force them to follow the style anyhow&lt;/em&gt;
&lt;/h4&gt;

&lt;p&gt;If we can make them "have to" follow the code-style, it will save time and we can spend more effort on the real thing!&lt;br&gt;
In this post, we are going to talk about the second solution&lt;/p&gt;
&lt;h2&gt;
  
  
  prettier
&lt;/h2&gt;

&lt;p&gt;What prettier does? the prettier is a kind of code-styling-checker. The users can make their own style setting and re-organize the code. For example, if you type &lt;code&gt;shift + alt + f&lt;/code&gt; on vscode, this will re-format your code to look nicer. If you are not using proper indent and curly bracket and others, it will do them for you. Likewise the prettier do this, but you can MAKE your style.&lt;/p&gt;
&lt;h4&gt;
  
  
  first you need to create configuration file
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;A "prettier" key in your package.json file.&lt;/li&gt;
&lt;li&gt;A .prettierrc file written in JSON or YAML.&lt;/li&gt;
&lt;li&gt;A .prettierrc.json, .prettierrc.yml, .prettierrc.yaml, or .prettierrc.json5 file.&lt;/li&gt;
&lt;li&gt;A .prettierrc.js, .prettierrc.cjs, prettier.config.js, or prettier.config.cjs file that exports an object using module.exports.&lt;/li&gt;
&lt;li&gt;A .prettierrc.toml file.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Once you create one of them, now you can make your rules on that. For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
  "trailingComma": "es5",
  "tabWidth": 4,
  "semi": false,
  "singleQuote": true
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;br&gt;
 in .prettierrc.json&lt;/p&gt;

&lt;p&gt;You can find more info on &lt;a href="https://prettier.io/docs/en/configuration.html"&gt;How to create configuration files?&lt;/a&gt;, &lt;a href="https://prettier.io/docs/en/options.html"&gt;Options for prettier&lt;/a&gt; &lt;/p&gt;
&lt;h2&gt;
  
  
  eslint
&lt;/h2&gt;

&lt;p&gt;eslint seem similar to prettier, but it will check the syntax before running the program. So if it finds some invalid syntax, it will complain about that. Setting up eslint is same with prettier&lt;/p&gt;

&lt;p&gt;You can find info &lt;a href="https://eslint.org/docs/user-guide/configuring"&gt;here&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  .vscode
&lt;/h2&gt;

&lt;p&gt;Many programmers use vscode, and the vscode provide nice feature "extension". prettier and eslint is also distributed by extension. You can make contributors to install them.&lt;/p&gt;

&lt;p&gt;In the &lt;code&gt;.vscode/extensions.json&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
    "recommendations": [
        "editorconfig.editorconfig",
        "dbaeumer.vscode-eslint",
        "esbenp.prettier-vscode"
    ]
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Example with findBreakUrl
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// in .eslintrc.json
{
    "parserOptions": { "ecmaVersion": 8 },
    "rules": {
        "semi": "error",
        "quotes": ["error", "single"]
    }
}

// in .prettierrc.json
{
    "trailingComma": "es5",
    "tabWidth": 4,
    "semi": true,
    "singleQuote": true,
    "bracketSpacing": true,
    "arrowParens": "always"
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
    </item>
    <item>
      <title>Update: Take a API from telescope API for findbrokenURL</title>
      <dc:creator>KiminLee</dc:creator>
      <pubDate>Sat, 07 Nov 2020 20:37:35 +0000</pubDate>
      <link>https://dev.to/klee214/update-take-a-api-from-telescope-api-for-findbrokenurl-3h05</link>
      <guid>https://dev.to/klee214/update-take-a-api-from-telescope-api-for-findbrokenurl-3h05</guid>
      <description>&lt;h3&gt;
  
  
  Before start
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://github.com/Seneca-CDOT/telescope"&gt;telescope&lt;/a&gt; is an amazing web project in Seneca. Telescope is an open source web server and client application for aggregating and presenting a timeline of Seneca's open source blogs. Telescope makes it easy to see what's happening with open source at Seneca right now.&lt;/p&gt;

&lt;h2&gt;
  
  
  Installation
&lt;/h2&gt;

&lt;p&gt;To run the telescope, we need &lt;a href="https://github.com/Seneca-CDOT/telescope/blob/master/docs/environment-setup.md"&gt;docker, redis and elasticsearch&lt;/a&gt;. As I am a window 10 home user, I needed to install &lt;a href="https://docs.microsoft.com/en-us/windows/wsl/compare-versions"&gt;WSL2&lt;/a&gt;-Ubuntu on my machine. &lt;/p&gt;

&lt;p&gt;After install WSL2, go to the docker website and install the &lt;a href="https://docs.docker.com/docker-for-windows/wsl-tech-preview/"&gt;docker desktop app&lt;/a&gt;. After all installing all the prerequisites, we are ready to go.&lt;/p&gt;

&lt;h3&gt;
  
  
  Issues
&lt;/h3&gt;

&lt;p&gt;However, after installing everything by following the step, you might come across some very buggy issues. One is you may not be able to run the docker as a background running &lt;code&gt;sudo systemctl start docker&lt;/code&gt; on your subsystem. If you spent some time to figure it out, you might try this &lt;code&gt;alias systemctl='/etc/init.d/docker&lt;/code&gt;, if it fails, that means you don't have /etc/init.d/ file on your subsytem. &lt;br&gt;
As far as I know, if you are in this stage, you would have 2 options. &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Just use desktop app, you can simply turn off and on using with desktop app(GUI), actually no need to use CLI "AT ALL."&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Install the docker engine -Linux version- again. This may anyhow create init.d files on your subsystem, so you probably would be able to use the above command. &lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;I chose the first option.&lt;/p&gt;

&lt;p&gt;"&lt;em&gt;Do I use Window for development? : hell NO&lt;/em&gt;"&lt;br&gt;
--  telescope community --&lt;/p&gt;
&lt;h2&gt;
  
  
  Running Telescope
&lt;/h2&gt;

&lt;p&gt;If you don't have issues or solved them already, CONGRATULATION! you are "really" good to go. &lt;/p&gt;

&lt;p&gt;First you need to install redis and elasticsearch on your system. With docker, this can be managed automatically. To install and run the multiple images and make them containers you can simply do this &lt;code&gt;docker-compose up --build redis elasticsearch&lt;/code&gt;. &lt;/p&gt;

&lt;p&gt;After that, you can find that you are running redis and elasticsearch is running. Then you can &lt;code&gt;npm start&lt;/code&gt; to run the backend server.&lt;/p&gt;
&lt;h2&gt;
  
  
  Update: enable to take &lt;code&gt;.json&lt;/code&gt; from telescope API
&lt;/h2&gt;

&lt;p&gt;I added one more option which is --api/-a. With this option user can pass a certain host+apiURL to communicate with them.&lt;/p&gt;

&lt;p&gt;changes&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;if (arg.a) {
  console.log(chalk.bgBlueBright("*******API Request start*******"))
  axios
    .get(arg.a)
    .then(async (response) =&amp;gt; {
      console.log(chalk.bgGreenBright("*******API Request Success*******"))
      if (arg.j) {
        response.data.map(res=&amp;gt;{
          await jsonFetch(path.resolve(arg.a, `./${res[id]}`));
        })
      } else {
        response.data.map(res=&amp;gt;{
          await fetchFunction(path.resolve(arg.a, `./${res[id]}`), arg.a);
        })
      }
    })
    .catch((error) =&amp;gt; {
      console.log(chalk.bgRedBright("*******API Request Fails*******"))
      console.log(
        chalk.yellowBright(
          `Cannot found: ${arg.a}. Probably because of network connection problem or wrong API address`
        )
      );
    });
} else 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, this tool can be used for any api if the api has json format URL.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;a href="https://gist.github.com/klee214/81c3906a0b1fa138902bfdbd0e035efa"&gt;find more info&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Last commit for "2020 hacktoberfest"</title>
      <dc:creator>KiminLee</dc:creator>
      <pubDate>Thu, 29 Oct 2020 21:06:23 +0000</pubDate>
      <link>https://dev.to/klee214/last-commit-for-2020-hacktoberfest-1keo</link>
      <guid>https://dev.to/klee214/last-commit-for-2020-hacktoberfest-1keo</guid>
      <description>&lt;h2&gt;
  
  
  getting start
&lt;/h2&gt;

&lt;p&gt;For my last contribution to "2020 hacktoberfest", I chose a little simple project but really needs some help. &lt;a href="https://github.com/redxzeta/Awesome-Adoption"&gt;Awesome-Adoption&lt;/a&gt; is a working project, finding available pets for adoption. &lt;/p&gt;

&lt;p&gt;To get all the information for pets, this project is using a third party API &lt;a href="https://www.petfinder.com/developers/"&gt;PetFinder&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;The issue was token is not stored in local-storage, so whenever refreshing the browser or changing the components the &lt;code&gt;api request&lt;/code&gt; kept sending to the server.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;...
export default function App() {
  const [token, setToken] = useState("");
  useEffect(() =&amp;gt; {
    axios
      .post(
        "https://api.petfinder.com/v2/oauth2/token",
        `grant_type=client_credentials&amp;amp;client_id=${process.env.REACT_APP_PETFINDER_KEY}`
      )
      .then((response) =&amp;gt; {
        setToken(response.data.access_token);
      })
      .catch((error) =&amp;gt; {
        console.log(error);
      });
  }, []);
...
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I suggested &lt;a href="https://github.com/redxzeta/Awesome-Adoption/issues/30#issuecomment-718983445"&gt;a better solution&lt;/a&gt; which is using &lt;code&gt;redux&lt;/code&gt;. The token will be used across the component and it shouldn't be changed as long as the user is same. &lt;code&gt;redux&lt;/code&gt; can keep the token as an available state for all &lt;code&gt;jsx&lt;/code&gt; components, and it won't be removed if it is in the &lt;code&gt;localstorage&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;HOWEVER, this could cost a lot of time to modify the codes, and change a lot of lines of code, so I tried to make a small change and follow the original code as possible as I can.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;First&lt;/strong&gt;, I created a function for &lt;code&gt;axios fetch&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;...
function fetchFunction(){
  axios
  .post(
    "https://api.petfinder.com/v2/oauth2/token",
    `grant_type=client_credentials&amp;amp;client_id=${process.env.REACT_APP_PETFINDER_KEY}`
  )
  .then((response) =&amp;gt; {
    localStorage.setItem("token",response.data.access_token);
  })
  .catch((error) =&amp;gt; {
    console.log(error);
  });
}
...
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If there is a &lt;code&gt;token&lt;/code&gt; in a &lt;code&gt;localstorage&lt;/code&gt; it doesn't need to send &lt;code&gt;post request&lt;/code&gt;, otherwise it should.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;...
if (!localStorage.getItem("token")) {
  fetchFunction();
}
...
useEffect(() =&amp;gt; {
    ...
    if(!localStorage.getItem("token")){
      fetchFunction();
    }
    setToken(localStorage.getItem("token"));
  }, []);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here is &lt;a href="https://github.com/redxzeta/Awesome-Adoption/pull/34"&gt;PR&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;This 2020 hacktoberfest is the first time for me to work as a open source developer. I always tried to contribute to bigger and commercial project, but I couldn't find the reason for the bug or don't know how to fix it. Also, I felt it is really hard to find a "good" project which I can handle. &lt;/p&gt;

&lt;p&gt;The good things for me is there are still hundreds of small projects that I can actually help! They are really looking for a small contribution, but no one really care about them. For a beginner, these project would be the "good first contribution." However, I am not so happy that I didn't contribute to the bigger project.&lt;/p&gt;

&lt;p&gt;Is that because of my lack of skills? or Am I too afraid of getting the first step on the big project? The answer was both. I was too intimidated by a "fancy" project. At the same time, I needed to learn a more thing about "server", "testing" or other deeper advanced programming skills. Luckily, this is just a beginning!! &lt;/p&gt;

</description>
    </item>
    <item>
      <title>GreenLight : Added a syntax checker feature!</title>
      <dc:creator>KiminLee</dc:creator>
      <pubDate>Mon, 26 Oct 2020 21:27:05 +0000</pubDate>
      <link>https://dev.to/klee214/greenlight-added-a-syntax-checker-feature-54df</link>
      <guid>https://dev.to/klee214/greenlight-added-a-syntax-checker-feature-54df</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://github.com/PerhapsSomeone/GreenLight"&gt;GreenLight&lt;/a&gt; is a new simple programming language created by &lt;a href="https://github.com/PerhapsSomeone"&gt;Marc&lt;/a&gt;. This new simple language can help to make CLI program much easier and faster. It takes all the good features from JAVASCRIPT and other many languages. &lt;br&gt;
&lt;strong&gt;Variables:&lt;/strong&gt;&lt;br&gt;
&lt;code&gt;var hello = "world"; // Mutable variable&lt;br&gt;
const constant = "light"; // Constant variable&lt;/code&gt;&lt;br&gt;
&lt;strong&gt;Objects/Array:&lt;/strong&gt;&lt;br&gt;
&lt;code&gt;let array = [498, 49, 299, 18]; // Declare a new array&lt;br&gt;
array[1] = 133; // Modify the second element of the array&lt;br&gt;
print(array[1]); // Print the second element of the array&lt;br&gt;
let object = { // Declare a new object...&lt;br&gt;
  "key": "hello world"&lt;br&gt;
};&lt;br&gt;
print(object&amp;gt;&amp;gt;key); // Print the value located at the key "key"&lt;br&gt;
&lt;/code&gt;&lt;br&gt;
It also, provides general &lt;strong&gt;standard library&lt;/strong&gt;!&lt;br&gt;
&lt;code&gt;sqrt(16); // =&amp;gt; 4 Get the square root of a number&lt;br&gt;
log(1); // =&amp;gt; 0 Get the natural logarithm of a number&lt;br&gt;
pow(2, 10); // =&amp;gt; 1024 Raise a number to an arbitrary power&lt;br&gt;
exp(1); // =&amp;gt; 2.718281828459045 Get the exponential of a number&lt;br&gt;
...&lt;br&gt;
&lt;/code&gt;&lt;br&gt;
&lt;a href="https://github.com/PerhapsSomeone/GreenLight#documentation"&gt;More Info&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Getting start
&lt;/h2&gt;

&lt;p&gt;There was a one &lt;a href="https://github.com/PerhapsSomeone/GreenLight/issues/13"&gt;good issue&lt;/a&gt; on this project. It didn't catch syntax errors and handle them properly. So, GreenLight decided to improve this feature and let someone help them. Luckily, I was there for help!&lt;/p&gt;
&lt;h2&gt;
  
  
  Step 1: Testing
&lt;/h2&gt;

&lt;p&gt;The first thing to do is always testing first! So I have run the demo &lt;code&gt;hello_world.gl&lt;/code&gt; file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;print("Welcome to GreenLight!");
print("Hello world!");
logError("I'm an error.");

print("---Cryptography---");
print("The SHA256 hash of 'Hello World' is " + sha256("Hello World") + "!");
print("The SHA3-256 hash of 'Hello World' is " + sha3("Hello World") + "!");

print("A random number between 50 and 100 is " + randomNumberBetween(50, 100));


print("---Array Functions---");

print("- Array Difference:");
const school_subjects = ['Math', 'Geography','History'];
var approved_school_subjects = ['Geography'];
const pending_subjects = arrDiff(school_subjects, approved_school_subjects);
print("The school subjects that still need approval are: " + pending_subjects);

print("- Array Difference Symmetric:");
const female_animals = ['Duck', 'Cat','Elephant','Tiger'];
var male_animals = ['Duck', 'Dog','Elephant','Tiger'];
const animals_alone = arrDiffSymmetric(female_animals, male_animals);
print("Animals that do not have a pair are: " + animals_alone);

print("- Array Intersection:");
const fruits = ['Banana', 'Apple', 'Grape', 'Strawberry'];
var fruits_find = ['Strawberry', 'Apple', 'Watermelon'];
const fruits_found = arrIntersect(fruits, fruits_find);
print("The fruits found were: " + fruits_found);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It was a simple code file, just printed some messages. After compiling this, it showed that the compilations is OK, and ready to run&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[*] Executing lexer...
[OK] Lexer finished successfully!
[*] Transpiling...
[OK] Transpilation complete!
[*] Running syntax checker &amp;amp; linter...
[OK] Syntax checker finished, no issues found!
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;and following output message.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Welcome to GreenLight!
Hello world!
I'm an error.
---Cryptography---
The SHA256 hash of 'Hello World' is a591a6d40bf420404a011733cfb7b190d62c65bf0bcda32b57b277d9ad9f146e!
The SHA3-256 hash of 'Hello World' is e167f68d6563d75bb25f3aa49c29ef612d41352dc00606de7cbd630bb2665f51!
A random number between 50 and 100 is 100
---Array Functions---
- Array Difference:
The school subjects that still need approval are: Math,History
- Array Difference Symmetric:
Animals that do not have a pair are: Cat,Dog
- Array Intersection:
The fruits found were: Apple,Strawberry
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So far, it seems OK when we correctly write the code using GreenLight syntax. However, what if I intentionally break this?&lt;/p&gt;

&lt;p&gt;So, I deleted the ')' on the first line &lt;code&gt;print("Welcome to GreenLight!");&lt;/code&gt;. It turned out the program didn't catch the syntax error &lt;code&gt;UnhandledPromiseRejectionWarning: ReferenceError:&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 2: Spot the exact code file that should be improved!
&lt;/h2&gt;

&lt;p&gt;To make an enhancement, I needed to find out which code file is dealing with syntax checking function among the dozens of &lt;code&gt;.js&lt;/code&gt; code files. Luckily there is a hint from Marc and code itself. When I compiled the code, it showed that &lt;code&gt;[*] Transpiling...&lt;/code&gt; is ahead of &lt;code&gt;[*] Running syntax checker &amp;amp; linter...&lt;/code&gt; That means somehow the &lt;code&gt;Transpiling&lt;/code&gt; process will transform the &lt;code&gt;.gl&lt;/code&gt; file to '.js' file, and then it will run the &lt;code&gt;syntax checker&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 3: Inside &lt;code&gt;transpiler.js&lt;/code&gt;
&lt;/h2&gt;

&lt;p&gt;In the &lt;code&gt;transpiler.js&lt;/code&gt; file, there is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function runChecks() {
    return syntaxChecker.checkSyntax(code);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The "code" is already transformed to &lt;code&gt;.js&lt;/code&gt; syntax. So, in this stage the "code" looks like&lt;br&gt;
&lt;code&gt;console.log("Welcome to GreenLight!";print("Helloworld!");greenlight_internal_log_error("I'm an error.");console.log("---Cryptography---");&lt;br&gt;
...&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;As we can see, &lt;code&gt;console.log("Welcome to GreenLight!";&lt;/code&gt; is not closed with ')'. &lt;/p&gt;
&lt;h2&gt;
  
  
  Step 4: Inside &lt;code&gt;syntax_checker.js&lt;/code&gt;
&lt;/h2&gt;

&lt;p&gt;In this file, there was no syntax checking feature. It only catched if the user-built function was properly called with &lt;code&gt;call&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function checkSyntax(compiledCode) {
    let checkPassed = true;
    let splitCode = compiledCode.split(" ");
    if (!checkAsyncFunctionCalls(splitCode)) checkPassed = false;

    return checkPassed;
}

function checkAsyncFunctionCalls(code) {
    let passed = true;
    let withinString = false;
    ...
    return passed;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Step 4: Added bracket checking feature
&lt;/h2&gt;

&lt;p&gt;It is impossible for me to added all the syntax checking functions for the "GreenLight." So, I decided to specifically deal with open and close bracket syntax checker. First of all creating a function,&lt;br&gt;
&lt;code&gt;checkParenthesesBracket&lt;/code&gt; it should &lt;code&gt;return false&lt;/code&gt; if the bracket doesn't open and close properly.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;For example)&lt;/em&gt;&lt;br&gt;
&lt;code&gt;({)}&lt;/code&gt; false&lt;br&gt;
&lt;code&gt;({[]})&lt;/code&gt; true&lt;br&gt;
&lt;code&gt;([[])&lt;/code&gt; false&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;checkParenthesesBracket&lt;/code&gt; takes code as parameter. The code was separated by whitespace, but it wouldn't be good idea for this. So It had to be separated by &lt;code&gt;;&lt;/code&gt;. &lt;code&gt;let splitCode = compiledCode.split(";");&lt;/code&gt; As a result, &lt;code&gt;code&lt;/code&gt; is lines of the entire code.&lt;/p&gt;

&lt;p&gt;For each line, &lt;code&gt;for (let i = 0; i &amp;lt; code.length; i++)&lt;/code&gt; must have closing bracket if the open bracket is used.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;if (code[i].includes("(")) {
            let flag = true; // check '(', ')' is a pair
            code[i].split("").forEach(char =&amp;gt; {
                if (flag &amp;amp;&amp;amp; char === "(") flag = false; // needs ')'
                if (!flag &amp;amp;&amp;amp; char === ")") flag = true; // needs '('
            });
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;same for &lt;code&gt;[]&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;if (code[i].includes("[")) {
...
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Step 5: Testing and Wrap up
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;if (!checkParenthesesBracket(splitCode)) checkPassed = false;&lt;/code&gt; is added in the &lt;code&gt;checkSyntax&lt;/code&gt; function right before &lt;code&gt;checkAsyncFunctionCalls&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Now run the code again.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[*] Executing lexer...
[OK] Lexer finished successfully!
[*] Transpiling...
[OK] Transpilation complete!
[*] Running syntax checker &amp;amp; linter...
[WARN] '(' is not closed. This could cause syntax errors: console.log("Welcome to GreenLight!"
[WARN] Syntax checker found at least one issue in your code!
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, we can catch the error!&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Refactoring findBreakURL to improve maintainability!</title>
      <dc:creator>KiminLee</dc:creator>
      <pubDate>Fri, 23 Oct 2020 17:28:35 +0000</pubDate>
      <link>https://dev.to/klee214/refactoring-findbreakurl-to-improve-maintainability-4i80</link>
      <guid>https://dev.to/klee214/refactoring-findbreakurl-to-improve-maintainability-4i80</guid>
      <description>&lt;h2&gt;
  
  
  Before Start
&lt;/h2&gt;

&lt;p&gt;While I am participating "2020 hacktoberfest", I realized that some of the projects on github are not really easy to get start as a new contributor for them. The reason is their codes usually written by one or two contributors and didn't really think about maintainability and let others join in the project. Most of the my projects are also done by me, so to be honest, I didn't really care about the maintainability and conventions as well. &lt;a href="https://github.com/klee214/findBreakURL"&gt;findBreakURL&lt;/a&gt; is also one of them. However, being a open source developer is not only improving my coding skills but also learn how to interactively work with others and effectively maintain the existing codes.&lt;/p&gt;

&lt;p&gt;So, this week, I have decided to improve the code style of &lt;a href="https://github.com/klee214/findBreakURL"&gt;findBreakURL&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  What should be changed?
&lt;/h2&gt;

&lt;p&gt;So far, the program has 4 different &lt;code&gt;.js&lt;/code&gt; files.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;fetch.js&lt;/code&gt; : &lt;em&gt;With axios, we will do 'header fetch' to check status code&lt;/em&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;json.js&lt;/code&gt; : &lt;em&gt;This file will make a &lt;code&gt;json&lt;/code&gt; style output&lt;/em&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;yargs.js&lt;/code&gt; : &lt;em&gt;This file handle the arguments and options and read directory to find files&lt;/em&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;index.js&lt;/code&gt; : &lt;em&gt;This is the entry for the program, will read files and following functions&lt;/em&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Wait, What?&lt;/strong&gt; &lt;code&gt;index.js&lt;/code&gt; will read files? and &lt;code&gt;yargs.js&lt;/code&gt; read directory to find files? &lt;br&gt;
This looks not so consistency and maybe a little bit irrelevant for their desired functions. Maybe we can split the functions to another files.&lt;/p&gt;

&lt;p&gt;let's start with &lt;code&gt;git checkout -b refactoring&lt;/code&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Step 0 : Make a &lt;code&gt;fileRead.js&lt;/code&gt;
&lt;/h2&gt;

&lt;p&gt;It will be better if we extract reading a file/directory function from &lt;code&gt;index.js&lt;/code&gt; and &lt;code&gt;yargs.js&lt;/code&gt; and make a separate file for the change.&lt;/p&gt;
&lt;h2&gt;
  
  
  Step 1 : Make a &lt;code&gt;fileRead()&lt;/code&gt; function
&lt;/h2&gt;

&lt;p&gt;In &lt;code&gt;index.js&lt;/code&gt;, &lt;code&gt;fileData&lt;/code&gt; is extracted.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;...
try {
        fileData = fs.readFileSync(`${__dirname}\\${file}`, {
            encoding: "utf-8",
        });

    // wrong file name
    } catch (error) {
        console.log(file + " is a WRONG file name");
        return process.exit(1);
    }
...
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Maybe we can make this part as a fileRead() function:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const fileRead = (file) =&amp;gt; {
    let fileData = null;

    try {
        fileData = fs.readFileSync(`${__dirname}\\${file}`, {
            encoding: "utf-8",
        ...
    return fileData
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After change, commit this change.&lt;br&gt;
&lt;code&gt;git add index.js + git commit split index.js to index.js and fileRead.js&lt;/code&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Step 2 : Make a &lt;code&gt;fileDirectory()&lt;/code&gt; function
&lt;/h2&gt;

&lt;p&gt;In the &lt;code&gt;yargs.js&lt;/code&gt;, files are declared globally. And all conditions are not inside a function. It looks better if the variable is only used inside a function and the conditions are also in the function.&lt;/p&gt;

&lt;p&gt;Before:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let files = [];
    if (yargs.argv._.length === 1 &amp;amp;&amp;amp; yargs.argv._[0] === "start") {

      // decide the option if it is -f or -a
      if (yargs.argv.a &amp;amp;&amp;amp; typeof yargs.argv.f !== "string") {
        const tmpFiles = fs.readdirSync(__dirname, { encoding: "utf-8" });

        // if -a, store all files into the files variable
        files = tmpFiles.filter((file) =&amp;gt; {
          return file.toLowerCase().endsWith(".html");
        });

      } else if (typeof yargs.argv.f === "string") {
        files = [...yargs.argv.f.split(",")];
      } else {
        console.log(chalk.yellow("Please enter filenames or -a following -f"))
      }
      return files;
    } else {
      console.log(chalk.yellow("Wrong argument: use [start]"));
    }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const readDirectory = (yargs) =&amp;gt; {
    let files = [];
    if (yargs.argv._.length === 1 &amp;amp;&amp;amp; yargs.argv._[0] === "start") {

      ...
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Commit the changes as &lt;code&gt;extract fileDirectory(), put that into fileRead.js&lt;/code&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 4 : &lt;code&gt;Split index.js&lt;/code&gt; and &lt;code&gt;yargs.js&lt;/code&gt;
&lt;/h2&gt;

&lt;p&gt;Now let's move those functions to &lt;code&gt;fileRead.js&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const fs = require("fs");
const chalk = require('chalk')

const fileRead = (file) =&amp;gt; {
    ...
}

const readDirectory = (yargs) =&amp;gt; {
    ...
}

module.exports = { fileRead, readDirectory }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And &lt;code&gt;index.js&lt;/code&gt; should be used &lt;code&gt;fileRead&lt;/code&gt; and yargs needs 'readDirectory'&lt;br&gt;
&lt;code&gt;index.js&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Start testing files each
files.map((file) =&amp;gt; {
  const fileData = fileRead(file);
...
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;yargs.js&lt;/code&gt; :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;...
const files = readDirectory(yargs);

module.exports = {
  files,
  arg: yargs.argv,
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h1&gt;
  
  
  Step 5 : Squash the commit and merge!
&lt;/h1&gt;

&lt;p&gt;We have currently 4 changes. However, we only need the last finalized version of changes. We can do this using with &lt;code&gt;git rebase master -i&lt;/code&gt;&lt;br&gt;
It enable us to squash all the previous changes and make them a one single commit&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;pick 4710009 split index.js to index.js and fileRead.js
squash 0c01069 extract fileDirectory(), put that into fileRead.js
squash fd8e932 variables name changed
squash f9d85bf squash index.js and package-lock.json
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Also, we can change the commit name with &lt;code&gt;git commit --ammend&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;commit d740f80e8c0e2b1d4c9d50613e5812016bcf86de (HEAD -&amp;gt; master, origin/master, origin/HEAD, refactoring)
Author: klee214 &amp;lt;klee214@myseneca.ca&amp;gt;
Date:   Fri Oct 23 12:25:19 2020 -0400

    Refactoring findBreakUrl to improve code maintainability

    *extract fileDirectory(), put that into fileRead.js

    *variables name changed

    *split index.js to fileRead.js and index.js
...
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  More information
&lt;/h2&gt;

&lt;p&gt;Visit and see &lt;a href="https://github.com/klee214/findBreakURL/commit/d740f80e8c0e2b1d4c9d50613e5812016bcf86de"&gt;this&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
