<?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: Srinivasan K K</title>
    <description>The latest articles on DEV Community by Srinivasan K K (@srinivasankk).</description>
    <link>https://dev.to/srinivasankk</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.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F123756%2Fbf29a2ee-1af6-4b5e-ba9a-8fb95ce32ae8.jpeg</url>
      <title>DEV Community: Srinivasan K K</title>
      <link>https://dev.to/srinivasankk</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/srinivasankk"/>
    <language>en</language>
    <item>
      <title>I Was Tired of Losing Disk Space to node_modules - So I Built ArtifactSweep</title>
      <dc:creator>Srinivasan K K</dc:creator>
      <pubDate>Thu, 13 Aug 2026 06:40:00 +0000</pubDate>
      <link>https://dev.to/srinivasankk/i-was-tired-of-losing-disk-space-to-nodemodules-so-i-built-artifactsweep-438p</link>
      <guid>https://dev.to/srinivasankk/i-was-tired-of-losing-disk-space-to-nodemodules-so-i-built-artifactsweep-438p</guid>
      <description>&lt;p&gt;Being a developer, we all create many projects for learning, work, and experiments.&lt;/p&gt;

&lt;p&gt;Over time my machine started filling up — not with source code, but with &lt;strong&gt;generated junk&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;node_modules&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;target&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;dist&lt;/code&gt; / &lt;code&gt;build&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;framework caches like &lt;code&gt;.next&lt;/code&gt;, &lt;code&gt;.angular&lt;/code&gt;, &lt;code&gt;.nuxt&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;and more of the same across every cloned repo&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Every few months I would hunt folders manually, delete something, free a few GB, then the same problem would come back.&lt;/p&gt;

&lt;p&gt;Only learning about “clean your disk” tips doesn’t help much. &lt;strong&gt;Building something for the problem&lt;/strong&gt; does.&lt;/p&gt;

&lt;p&gt;So I ended up building &lt;strong&gt;&lt;a href="https://kksrini89.github.io/artifactsweep/" rel="noopener noreferrer"&gt;ArtifactSweep&lt;/a&gt;&lt;/strong&gt; — a small open-source tool for this everyday developer issue.&lt;/p&gt;

&lt;h2&gt;
  
  
  The real problem
&lt;/h2&gt;

&lt;p&gt;As developers we regenerate these folders all the time:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm &lt;span class="nb"&gt;install
&lt;/span&gt;cargo build
ng build
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;They are &lt;strong&gt;not&lt;/strong&gt; our source of truth. But they sit on the SSD for months.&lt;/p&gt;

&lt;p&gt;The painful part is not only size. It is:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Finding them across many project roots&lt;/li&gt;
&lt;li&gt;Knowing &lt;strong&gt;how big&lt;/strong&gt; they are before delete&lt;/li&gt;
&lt;li&gt;Not deleting the wrong folder by mistake&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;I wanted something that could:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Scan&lt;/strong&gt; a folder tree&lt;/li&gt;
&lt;li&gt;Show &lt;strong&gt;sizes&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Let me &lt;strong&gt;clean&lt;/strong&gt; with more control&lt;/li&gt;
&lt;li&gt;Work on my day-to-day machines (Windows, Linux, Mac)&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Step 1: Start with a CLI
&lt;/h2&gt;

&lt;p&gt;I started with the command line first.&lt;/p&gt;

&lt;p&gt;Why CLI?&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Fast to build and test&lt;/li&gt;
&lt;li&gt;Fits terminal-first workflow&lt;/li&gt;
&lt;li&gt;Easy to script and share&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The CLI is called &lt;strong&gt;&lt;code&gt;sweep&lt;/code&gt;&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Basic usage:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# Safe: only list junk under a path&lt;/span&gt;
sweep scan &lt;span class="nb"&gt;.&lt;/span&gt;

&lt;span class="c"&gt;# Preview deletes&lt;/span&gt;
sweep clean &lt;span class="nb"&gt;.&lt;/span&gt; &lt;span class="nt"&gt;--dry-run&lt;/span&gt;

&lt;span class="c"&gt;# Delete&lt;/span&gt;
sweep clean &lt;span class="nb"&gt;.&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;On one of my project folders alone, it reclaimed nearly &lt;strong&gt;5 GB&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;That was enough validation: this is not a fake problem. Every active developer hits it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 2: Then came the desktop app
&lt;/h2&gt;

&lt;p&gt;CLI is great when you already know the path and trust dry-run.&lt;/p&gt;

&lt;p&gt;But sometimes I wanted to:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;See a &lt;strong&gt;list&lt;/strong&gt; of folders and sizes&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Filter&lt;/strong&gt; by type&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Confirm&lt;/strong&gt; before delete&lt;/li&gt;
&lt;li&gt;Click through without remembering flags&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;So I added a &lt;strong&gt;desktop app&lt;/strong&gt; on top of the same idea (same cleanup job, different UI).&lt;/p&gt;

&lt;p&gt;Flow is simple:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Choose folder&lt;/li&gt;
&lt;li&gt;Scan&lt;/li&gt;
&lt;li&gt;Review results (and filters if needed)&lt;/li&gt;
&lt;li&gt;Clean with confirmation&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;If you like GUIs for this kind of cleanup, the desktop app is friendlier.&lt;br&gt;&lt;br&gt;
If you live in the terminal, keep using &lt;code&gt;sweep&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;You don’t need two different products in your head. One tool family: &lt;strong&gt;ArtifactSweep&lt;/strong&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Open source for developers
&lt;/h2&gt;

&lt;p&gt;This is a &lt;strong&gt;day-to-day&lt;/strong&gt; issue, not a rare edge case.&lt;/p&gt;

&lt;p&gt;So I open-sourced it under &lt;strong&gt;MIT&lt;/strong&gt;.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;You can download the ArtifactSweep tool from &lt;a href="https://github.com/kksrini89/artifactsweep/releases" rel="noopener noreferrer"&gt;here&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

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

&lt;ol&gt;
&lt;li&gt;Open a &lt;strong&gt;new&lt;/strong&gt; terminal (important on Windows for PATH)&lt;/li&gt;
&lt;li&gt;Run &lt;code&gt;sweep --help&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Or open the &lt;strong&gt;ArtifactSweep&lt;/strong&gt; desktop app&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Optional: standalone &lt;code&gt;sweep-*&lt;/code&gt; binaries if you only want the CLI.&lt;/p&gt;

&lt;h2&gt;
  
  
  What it looks for
&lt;/h2&gt;

&lt;p&gt;Folders matched by &lt;strong&gt;name&lt;/strong&gt;, for example:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;JS/TS: &lt;code&gt;node_modules&lt;/code&gt;, &lt;code&gt;dist&lt;/code&gt;, &lt;code&gt;.next&lt;/code&gt;, &lt;code&gt;.angular&lt;/code&gt;, …&lt;/li&gt;
&lt;li&gt;Rust: &lt;code&gt;target&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Python: &lt;code&gt;__pycache__&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Other common caches (you will see them after a scan)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;It does not walk &lt;em&gt;inside&lt;/em&gt; a matched junk folder looking for more junk names. Keep the list review before you clean — some names like &lt;code&gt;bin&lt;/code&gt; / &lt;code&gt;build&lt;/code&gt; can appear in real projects too.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why I’m sharing this
&lt;/h2&gt;

&lt;p&gt;I built ArtifactSweep because &lt;strong&gt;I needed it&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Then I polished it enough that other developers can use it without setting up a full toolchain just to free disk space.&lt;/p&gt;

&lt;p&gt;If you face the same “where did my free space go?” moment every few months, try it from the links above.&lt;/p&gt;

&lt;p&gt;If it saves you disk space or time, you can &lt;a href="https://www.buymeacoffee.com/SrinivasanKK" rel="noopener noreferrer"&gt;support&lt;/a&gt; the work.&lt;/p&gt;

&lt;p&gt;That’s it. You can also share your opinion on improving it further. Feel free to raise an issue on GitHub.&lt;/p&gt;

&lt;p&gt;Happy cleaning, and keep building.&lt;/p&gt;

</description>
      <category>opensource</category>
      <category>productivity</category>
      <category>rust</category>
      <category>vue</category>
    </item>
    <item>
      <title>My Top 5 Favorite Things from JavaScript ES2020</title>
      <dc:creator>Srinivasan K K</dc:creator>
      <pubDate>Thu, 09 Apr 2020 10:37:00 +0000</pubDate>
      <link>https://dev.to/srinivasankk/my-top-5-favorite-things-from-javascript-es2020-43d1</link>
      <guid>https://dev.to/srinivasankk/my-top-5-favorite-things-from-javascript-es2020-43d1</guid>
      <description>&lt;p&gt;Being a JavaScript developer, knowing the ECMAScript standards is the essential one.&lt;/p&gt;

&lt;p&gt;So, I would like to share my top 5 favorite things from JavaScript &lt;code&gt;ES2020&lt;/code&gt; which are all finalized proposals (&lt;code&gt;stage 4&lt;/code&gt;).&lt;/p&gt;

&lt;h1&gt;
  
  
  Top 5 Favorite Things From JavaScript ES2020
&lt;/h1&gt;

&lt;h3&gt;
  
  
  1. Nullish Operator (&lt;code&gt;??&lt;/code&gt;)
&lt;/h3&gt;

&lt;p&gt;Before this introduced, we have been using &lt;code&gt;||&lt;/code&gt; OR operator. But &lt;code&gt;??&lt;/code&gt; and &lt;code&gt;||&lt;/code&gt; basically serves a different purpose.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;||&lt;/code&gt; is to check &lt;code&gt;falsy&lt;/code&gt; &lt;a href="https://developer.mozilla.org/en-US/docs/Glossary/Falsy" rel="noopener noreferrer"&gt;values&lt;/a&gt; whereas &lt;code&gt;??&lt;/code&gt; operator is to check both &lt;code&gt;NULL&lt;/code&gt; or &lt;code&gt;Undefined&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 user = { name: 'John' };
console.log(user.name ?? 'Not Exists.');
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  2. Optional Chaining (&lt;code&gt;?.&lt;/code&gt;)
&lt;/h3&gt;

&lt;p&gt;Before this, we have been using &lt;code&gt;&amp;amp;&amp;amp;&lt;/code&gt; AND operator to check whether left-hand side expression returns true, then the right-hand side expression would be evaluated.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const user = { name: 'John' };
console.log(user?.name);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  3. Dynamically Importing JS Module
&lt;/h3&gt;

&lt;p&gt;We could lazy load the JS module at runtime by using this option,&lt;br&gt;
&lt;code&gt;import(&amp;lt;module_file_name&amp;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;async loadUser() {
  const user = await import(`./user.js`);
  console.log(user.getName());
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  4. Accessing Global Context
&lt;/h3&gt;

&lt;p&gt;We use a certain keyword to access the &lt;code&gt;global&lt;/code&gt; context but it differs for each environment. For instance, &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;window&lt;/code&gt; is the keyword for &lt;code&gt;browser&lt;/code&gt; environment,&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;global&lt;/code&gt; is the keyword for &lt;code&gt;Node.js&lt;/code&gt; environment,&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;self&lt;/code&gt; is the keyword for &lt;code&gt;Web/service workers&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;code&gt;globalThis&lt;/code&gt; is the new keyword that solves the above environment context issue.&lt;/p&gt;

&lt;p&gt;As a web developer, We often stick to &lt;code&gt;write once run it anywhere&lt;/code&gt; principle. In this fashion, this new addition would help us a lot.&lt;/p&gt;

&lt;h3&gt;
  
  
  5. Promise.allSettled (&lt;code&gt;Promise.allSettled([inputs])&lt;/code&gt;)
&lt;/h3&gt;

&lt;p&gt;As a web developer, invoking multiple HTTP requests simultaneously is the usual thing.&lt;br&gt;
&lt;code&gt;Promise.allSettled([])&lt;/code&gt;, this one will be settled down when all the inputs are either resolved/rejected.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const getUser = () =&amp;gt; Promise.resolve({ name: 'John' });
const getUserRights = () =&amp;gt; Promise.reject(new Error(`Unauthorized Access...`));
const getUsersCount = () =&amp;gt; Promise.resolve({ total: 5000 });
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let's say we have 3 promise calls which we are going to invoke parallelly.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Promise.allSettled([getUser(), getUserRights(), getUsersCount()])
       .then(([user, rights, count]) =&amp;gt; {
           if(user.status === 'resolved') { console.log(user.value); }
        })
       .catch(console.error);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We have different options available to invoke multiple &lt;code&gt;Promise&lt;/code&gt; calls at a time, &lt;code&gt;Promise.all([])&lt;/code&gt; and &lt;code&gt;Promise.race([])&lt;/code&gt;. But those two Promise objects differ based on the use case.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Promise.all([x, y, z])&lt;/code&gt; will invoke all the given Promises parallelly but if anyone is failed then this operation would end up in &lt;code&gt;catch&lt;/code&gt; block of &lt;code&gt;Promise.all([])&lt;/code&gt;. But the resolved input promise would be ignored.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Promise.race([x, y, z])&lt;/code&gt;, this output will be resolved as soon as one of the input promise is resolved.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;NOTE:&lt;/strong&gt; If you're coming from C# background you have already familiar with &lt;code&gt;??&lt;/code&gt; and &lt;code&gt;?.&lt;/code&gt; operators.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Creating Dynamic Rows &amp; Columns with CSS-Grid</title>
      <dc:creator>Srinivasan K K</dc:creator>
      <pubDate>Wed, 18 Mar 2020 05:25:31 +0000</pubDate>
      <link>https://dev.to/srinivasankk/creating-dynamic-rows-columns-with-css-grid-55md</link>
      <guid>https://dev.to/srinivasankk/creating-dynamic-rows-columns-with-css-grid-55md</guid>
      <description>&lt;p&gt;In this blog post, I would like to share on &lt;strong&gt;how to create dynamic rows and columns with CSS-Grid&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;I have created the &lt;strong&gt;Scheduler UI&lt;/strong&gt; template markup to demonstrate further.&lt;/p&gt;

&lt;h2&gt;
  
  
  IDEA
&lt;/h2&gt;

&lt;p&gt;Only learning doesn’t serve any purpose instead building an application will.&lt;/p&gt;

&lt;p&gt;This app comprises Scheduler option input and based on the input will create a container with grid-cell for showing the day but dynamically.&lt;/p&gt;

&lt;h2&gt;
  
  
  Dynamic CSS-Grid Columns &amp;amp; Rows
&lt;/h2&gt;

&lt;p&gt;I cover the bare essential piece from the below code.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"container"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;  
  &lt;span class="nt"&gt;&amp;lt;ul&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"scheduler-options"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;li&amp;gt;&amp;lt;a&lt;/span&gt; &lt;span class="na"&gt;href=&lt;/span&gt;&lt;span class="s"&gt;"javascript:void(0)"&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"optn"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;daily&lt;span class="nt"&gt;&amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;li&amp;gt;&amp;lt;a&lt;/span&gt; &lt;span class="na"&gt;href=&lt;/span&gt;&lt;span class="s"&gt;"javascript:void(0)"&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"optn"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;weekly&lt;span class="nt"&gt;&amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;li&amp;gt;&amp;lt;a&lt;/span&gt; &lt;span class="na"&gt;href=&lt;/span&gt;&lt;span class="s"&gt;"javascript:void(0)"&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"optn"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;monthly&lt;span class="nt"&gt;&amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/ul&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"month-name"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;section&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"slots"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"scheduler-grid daily"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"scheduler-grid weekly"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"scheduler-grid monthly"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/section&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;javascript:void(0)&lt;/code&gt; will restrict redirecting URL.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;.scheduler-grid&lt;/code&gt; element acts as a &lt;em&gt;CSS-Grid&lt;/em&gt; container and based on the &lt;em&gt;scheduler-options&lt;/em&gt; input each grid container will be filled with grid cells.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.scheduler-grid&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;100%&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;margin&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;50px&lt;/span&gt; &lt;span class="m"&gt;25px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;padding&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;5px&lt;/span&gt; &lt;span class="m"&gt;100px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;display&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;grid&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="py"&gt;grid-gap&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;20px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="py"&gt;grid-auto-rows&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;100px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="py"&gt;grid-template-columns&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;repeat&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;auto-fill&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;minmax&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;200px&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="n"&gt;fr&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;grid-auto-rows&lt;/code&gt; &lt;code&gt;grid-template-columns&lt;/code&gt; &lt;code&gt;repeat&lt;/code&gt; &lt;code&gt;minmax&lt;/code&gt; and &lt;code&gt;auto-fill&lt;/code&gt; are the CSS-Grid configuration for dynamic creation of grid-cells.&lt;/p&gt;

&lt;p&gt;The CSS &lt;code&gt;repeat&lt;/code&gt; function will create the grid-cells based on the given min and max width of each cell using &lt;code&gt;minmax&lt;/code&gt; function.&lt;/p&gt;

&lt;p&gt;The &lt;strong&gt;important point&lt;/strong&gt; we should get it here is that, if we use both &lt;code&gt;grid-template-rows&lt;/code&gt; and &lt;code&gt;grid-template-columns&lt;/code&gt; for dynamic creation then rows will get cut at the end of the viewport.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fsrinivasankk.com%2Fwp-content%2Fuploads%2F2020%2F02%2Fimage-1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fsrinivasankk.com%2Fwp-content%2Fuploads%2F2020%2F02%2Fimage-1.png" alt="BrokeRow" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Hence, &lt;strong&gt;to avoid this&lt;/strong&gt; we should set the row height for the dynamically creating rows with the help of &lt;strong&gt;grid-auto-rows&lt;/strong&gt; property.&lt;/p&gt;

&lt;p&gt;After all this, we would end up with the below expected result.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fsrinivasankk.com%2Fwp-content%2Fuploads%2F2020%2F02%2Fimage-6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fsrinivasankk.com%2Fwp-content%2Fuploads%2F2020%2F02%2Fimage-6.png" alt="Scheduler_UI" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>css</category>
      <category>webdev</category>
      <category>design</category>
      <category>javascript</category>
    </item>
    <item>
      <title>How to create Reusable Date Utility in JavaScript</title>
      <dc:creator>Srinivasan K K</dc:creator>
      <pubDate>Tue, 03 Mar 2020 10:06:19 +0000</pubDate>
      <link>https://dev.to/srinivasankk/find-a-specific-date-from-today-s-date-in-javascript-47a3</link>
      <guid>https://dev.to/srinivasankk/find-a-specific-date-from-today-s-date-in-javascript-47a3</guid>
      <description>&lt;p&gt;Every one of us faced a hard time when comes to work on Date with JavaScript. Then I thought of creating the simple utility to get familiar with &lt;code&gt;JavaScript Date API&lt;/code&gt;,&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;to find a specific date from the current date in JavaScript.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;After wrote this utility, I wanted to share the same with other peers so ended up writing this article.&lt;/p&gt;

&lt;h1&gt;
  
  
  Date Constructor
&lt;/h1&gt;

&lt;p&gt;To get the current date we have a Date API from JavaScript, &lt;code&gt;new Date();&lt;/code&gt;&lt;br&gt;
The same can be retrieved by passing &lt;code&gt;date string&lt;/code&gt; as an input to the new Date();&lt;/p&gt;

&lt;p&gt;As most of us haven’t exposed to &lt;code&gt;one more way&lt;/code&gt; of getting date value,&lt;code&gt;new Date(year, month, date, hh, mm, ss);&lt;/code&gt;&lt;/p&gt;
&lt;h1&gt;
  
  
  Find a specific date from today's date in JavaScript
&lt;/h1&gt;

&lt;p&gt;To solve any kind of problem first, we need to list down the required inputs and draw the pseudo-code if required.&lt;/p&gt;

&lt;p&gt;In short, we require the following inputs.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Logic to derive the previous date,&lt;/li&gt;
&lt;li&gt;Day count of the previous month,&lt;/li&gt;
&lt;li&gt;Previous Year&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I created one reusable function named &lt;code&gt;getDateInfo&lt;/code&gt; which gives us all the information about today's date except 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 getDateInfo() {
  // Date Calculation
  const todayDate = new Date();
  const months = ['January','February','March','April','May','June','July','August','September','October','November','December'];
  const dayCount = {
    'January': 31, 
    'February': (todayDate.getFullYear()%4 === 0) ? 29 : 28,
    'March': 31,'April': 30,'May':31,'June':30,'July':31,'August':31,'September':30,'October':31,'November':30,'December':31
  }
  const days = ['Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday'];
  const currentMonth = months[todayDate.getMonth()];
  const currentYear = todayDate.getFullYear();
  const currentDate = todayDate.getDate();
  const currentDay = days[todayDate.getDay()];
  return {
    todayDate, months, dayCount, days, currentMonth, currentYear, currentDate, currentDay
  };
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h1&gt;
  
  
  Utility
&lt;/h1&gt;

&lt;p&gt;I shared the logic part also to give you hindsight and you will find it below.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function findDateFromToday({ howManyDates = 0, type = 'past' }){
  try {
    const { todayDate, months, dayCount, days, currentMonth, currentYear, currentDate, currentDay} = getDateInfo();
    if(type === 'past') {
      const resultDate = currentDate - howManyDates;
      if(resultDate === 0) {
        // Starting date of the current month
        return new Date(currentYear, todayDate.getMonth(),0,0,0);
      } else if(resultDate &amp;gt; 0) {
        // resultDate of the month
        return new Date(currentYear, todayDate.getMonth(), resultDate, 0,0,0);
      } else {
        let prevMonth;
        let prevYear;
        // if negative, then (previous month day count - (negative resultDate))
        if(todayDate.getMonth() !== 0) {
          prevMonth = todayDate.getMonth() - 1;
          const prevDate = dayCount[months[prevMonth]];
          return new Date(currentYear, prevMonth, prevDate +resultDate,0,0,0);
        } else {
          // previous year
          prevYear = currentYear - 1;
          // previous month
          prevMonth = 11; // december
          const prevDate = dayCount[months[prevMonth]];
          return new Date(prevYear, prevMonth, prevDate + (resultDate),0,0,0);
        }
      }
    }
  } catch(error) {
    return error;
  }  
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;howManyDates&lt;/code&gt; parameter is for how many dates from today.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;type&lt;/code&gt; parameter is for identifying a specific date that would fall on either past or future. Here only considered for finding the previous date value. If you're well curious enough then please go ahead do yourself for the future date.&lt;/p&gt;

&lt;h1&gt;
  
  
  Logic - To find the previous date
&lt;/h1&gt;

&lt;p&gt;I sorted out this utility based on the below logic, You can also add if more meaningful for making reusable.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Step 1: Subtract today date from &lt;code&gt;howManyDates&lt;/code&gt;count&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Step 2: If the subtracted value is 0 then the previous month's last date.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Step 3: If the subtracted value is &amp;gt; 0, then the result date of the current month&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Step 4: If the subtracted value is &amp;lt; 0, then will derive by using the previous month and previous year as below code.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;That's it. You can also share your opinion on improving further on this.&lt;/p&gt;

&lt;h3&gt;
  
  
  Originally Published at &lt;a href="https://srinivasankk.com/find-specific-date-from-todays-date-in-javascript/" rel="noopener noreferrer"&gt;Personal Blog&lt;/a&gt;
&lt;/h3&gt;

</description>
      <category>javascript</category>
      <category>productivity</category>
      <category>functional</category>
      <category>webdev</category>
    </item>
  </channel>
</rss>
