<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Nahush Farkande on Medium]]></title>
        <description><![CDATA[Stories by Nahush Farkande on Medium]]></description>
        <link>https://medium.com/@nahush.farkande?source=rss-cfc2cd626232------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*wyDSaz761dG96SKypbksPg.jpeg</url>
            <title>Stories by Nahush Farkande on Medium</title>
            <link>https://medium.com/@nahush.farkande?source=rss-cfc2cd626232------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 17 Nov 2026 16:10:01 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@nahush.farkande/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[5 Design Prompt Generators to sharpen your design skills]]></title>
            <link>https://medium.com/design-bootcamp/10-design-prompt-generators-to-sharpen-your-design-skills-11853259a791?source=rss-cfc2cd626232------2</link>
            <guid isPermaLink="false">https://medium.com/p/11853259a791</guid>
            <category><![CDATA[design-practice]]></category>
            <category><![CDATA[interface-design]]></category>
            <category><![CDATA[ux-design]]></category>
            <category><![CDATA[design]]></category>
            <category><![CDATA[design-challenge]]></category>
            <dc:creator><![CDATA[Nahush Farkande]]></dc:creator>
            <pubDate>Sun, 24 Apr 2022 20:09:36 GMT</pubDate>
            <atom:updated>2022-04-26T05:57:23.325Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/0*KUwFBq8S1YZQxy5T" /></figure><p>One of my favorite aspects of Design is that you don’t need a degree to become a designer or transition to design from another profession. Good design stems from Empathy for the users, A basic understanding of clean graphic design, and most importantly a willingness to solve problems. But just like any other skill, Design skills need to be nurtured by practicing them as often as possible.</p><p>However, The first question that comes to mind when thinking about practicing is “How do I practice?”. This is where Prompt generators come in. They allow you to get past the first and the biggest obstacle in Design — Getting Started.</p><blockquote>You can only design if you have <strong>something to design</strong></blockquote><p>Check out the following Design Prompt Generators to help you get past that first obstacle</p><ol><li><a href="https://designercize.com/"><strong>Designercize</strong></a></li></ol><p>Just choose a difficulty and keep hitting “Reload Challenge”. Plus the UI is kinda cool.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Q3EkVT4Yae0vWcqg_TqxRw.png" /><figcaption>Designercize</figcaption></figure><p><a href="https://sharpen.design/"><strong>2. Sharpen.design</strong></a></p><p>Choose from amongst Branding, Marketing, and UX Challenges. Also includes a “STEM Education” mode, which provides challenges from the non-digital world.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*m3rYoND1ZvIBj4ctpltyYw.png" /><figcaption>Sharpen.design</figcaption></figure><p><a href="https://www.briefz.biz/"><strong>3. Briefz.biz</strong></a></p><p>No-nonsense design briefs. Plus if you have briefs of your own you can submit them on the website and help out other designers in the world.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gHhfbob4Qx0UrQY08oWeDw.png" /><figcaption>Briefz.biz</figcaption></figure><p><a href="https://goodbrief.io/"><strong>4. Goodbrief.io</strong></a></p><p>Choose from Logo, Brand Identity, Illustration, Packaging, Billboard, and Website design prompts. Each prompt comes with a deadline to keep you on your toes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uGG1qMI-_22m7l-cU7gH5w.png" /></figure><p><a href="https://drawerrr.com/challenge"><strong>5. Drawerr.com/challenge</strong></a></p><p>Carefully curated design challenges focusing on the environment</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OkkGmkiaAAqsRDoR2DY_ew.png" /></figure><p>Found this helpful? Let me know your thoughts in the comments below.</p><blockquote>In case y’all have some feedback, just wanna chat or want to talk about your design needs and how I can help out, feel free to check out my <a href="https://www.nahushf.com/">portfolio</a> or <a href="https://www.linkedin.com/in/nahushfarkande/">LinkedIn</a> or hit me up at <strong>nahush.farkande@gmail.com .</strong></blockquote><p>Peace! and Happy Designing :)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=11853259a791" width="1" height="1" alt=""><hr><p><a href="https://medium.com/design-bootcamp/10-design-prompt-generators-to-sharpen-your-design-skills-11853259a791">5 Design Prompt Generators to sharpen your design skills</a> was originally published in <a href="https://medium.com/design-bootcamp">Bootcamp</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Operator Overloading: An approach to Ideation]]></title>
            <link>https://medium.com/@nahush.farkande/operator-overloading-an-approach-to-ideation-7950e274ef90?source=rss-cfc2cd626232------2</link>
            <guid isPermaLink="false">https://medium.com/p/7950e274ef90</guid>
            <category><![CDATA[creativity]]></category>
            <category><![CDATA[ideation]]></category>
            <category><![CDATA[ui-ux-design]]></category>
            <category><![CDATA[brainstorming]]></category>
            <category><![CDATA[whiteboarding]]></category>
            <dc:creator><![CDATA[Nahush Farkande]]></dc:creator>
            <pubDate>Sun, 17 Apr 2022 05:29:53 GMT</pubDate>
            <atom:updated>2022-04-17T22:35:56.050Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/0*Jxpzc0fTCfic__lO" /><figcaption>Photo by <a href="https://unsplash.com/@purzlbaum?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Claudio Schwarz</a> on <a href="https://unsplash.com/s/photos/multiple-hands?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><p>Operator Overloading??… Hmmm. Isn’t this a programming concept?</p><p>True, this term does come from the world of software engineering, and I doubt it shares too much of an overlap with what I’m about to talk about here.</p><p>Regardless this was the most succinct way I could think of to summarize the approach that I’m going to talk about in this blog.</p><p><strong>TLDR;</strong></p><p>Operator Overloading in this context is a <strong>brainstorming approach</strong> when coming up with product ideas(specifically when thinking of ideas along the lines of AR, IoT, and wearable technology). It involves looking at the steps involved in the current process, identifying the body parts or tools(referred to as operators) that are at work in each step of the process, and thinking of ways to improve upon these operators to simplify the process.</p><p>This is something I thought of in a whiteboarding workshop at my university(Be sure to check out the <a href="https://thespot.iupui.edu/organization/design_coterie">Design Coterie</a> student organization at IUPUI). In the workshop participants were given design prompts to ideate upon in short spans of 30–45 mins. I along with a few colleagues of mine tried out this technique to come up with a small set of prospective solutions to the design prompts handed to us.</p><h3>So how does it work?</h3><p>The approach is quite straightforward but often provides a handful of results if done correctly. The steps taken in this approach are as follows:</p><ol><li>Jot Down the steps involved in the current process</li><li>List the operators in each step. An operator can be any object or tool that performs any action or is involved in any capacity in that particular step.</li><li>Make a collection of all the operators from the previous step.</li><li>Try to think of optimizations for each operator.</li></ol><h3>Operator Overloading in action</h3><p>Let&#39;s take a look at some use cases of this technique. The examples below are a dumbed-down version of the technique to illustrate how it works and the results one can expect from it. Ideally, the number of operators involved in any prompt would be far higher and thereby would open the doors to many more concepts.</p><h4><strong>1. Prompt: Design an iPad case for a doctor&#39;s office.</strong></h4><p>— <strong>Operators Involved</strong>: Notebooks, Pens, chairs for patients to sit in, beds for patients to lie on, Flashlights, Stethoscope, etc</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kb3MjpeyPU_Rd2JG6mmOsA.png" /><figcaption>Operators Involved</figcaption></figure><p>— <strong>Optimizing Furniture: </strong>An iPad case with <strong>a magnetic attachment</strong> that would allow easily attaching it to chairs beds, etc</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PRbFWRgTfMPSWvwAVrVDYg.png" /><figcaption>Idea 1: Ipad case which magnetically attaches to other equipment</figcaption></figure><p>—<strong> Optimizing Tools:</strong> Case with <strong>holders to attach commonly used tools</strong> Stethoscopes, thermometers, etc</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dgD_HGoQgJO_GIrbn8f_PA.png" /><figcaption>Idea 2: Ipad case with holders to hold other equipment</figcaption></figure><h4><strong>2. Prompt: Design a better way to remember which page you are on in a book.</strong></h4><p>— <strong>Operators involved:</strong> eyes, books, hands, book covers, highlighters</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Elk0z47Kdi7rbzkUNSJRjQ.png" /><figcaption>Operators Involved</figcaption></figure><p>—<strong> Optimizing eyes:</strong> <strong>Smart glasses, that have an inbuilt camera</strong> that notes down the last page you read</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*i6KX0wXAa4UB7C7zthHm1Q.png" /><figcaption>Idea 1: Glasses with a camera that notes the last read page number</figcaption></figure><p>—<strong> Optimizing Books:</strong> An attachment with a thin bookmark that can easily be moved by the movement of a page. Whenever the reader turns the page, the thin filament <strong>bookmark would automatically be applied to the page</strong> currently being read</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BxmmpQIAn_n1AcBzX5u_4g.png" /><figcaption>Idea 2: Self-adjusting bookmark</figcaption></figure><p>—<strong> Optimizing hands:</strong> Gloves that can detect page number from the <strong>distance between thumb and index finger</strong> when the book is being held.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*irk5iMma3ddJQVt6hjpVFw.png" /><figcaption>Idea 3: Gloves that measure the distance between the thumb and index finger</figcaption></figure><h4><strong>3. Prompt: Design an easier way to carry groceries without a car</strong></h4><p>— <strong>Operators involved:</strong> Hands, Bags, groceries, legs</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nEyNYIrmMIvR3AWZmnPNeg.png" /><figcaption>Operators Involved</figcaption></figure><p>— Optimizing hands: A grip with hooks. The plastic bags cut through the skin disallowing carrying heavy loads. A grip that can be more ergonomic and can be held more easily would allow carrying heavier loads</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nAvxwY8utsoN19uGGFLteQ.png" /><figcaption>Idea 1: Ergonomic grip with hooks</figcaption></figure><p>— <strong>Optimizing legs:</strong> One pain point is the bags bumping against legs which disallow running or walking faster. Or it can just be annoying. A <strong>hip attachment</strong> that <strong>keeps the bags away from the legs</strong> can improve the experience of carrying bags for long distances</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*C-MyUBj36ScN6nNJ1G7s5w.png" /><figcaption>Idea 2: Metal Frame to stop bags from bumping against the legs</figcaption></figure><h3>Final Thoughts</h3><p>In any brainstorming process, it is often a good idea to think of as many ideas as possible in the initial stage. The more the ideas the better. Narrowing down and refining the ideas can take place in the subsequent stages of brainstorming where ideas can be critiqued for their desirability, viability, and feasibility (Check out the <a href="https://idea-sandbox.com/blog/disney-brainstorming-method-dreamer-realist-and-spoiler/">Walt Disney method</a> for brainstorming)</p><p>While the ideas generated using this technique might not always be optimal, they can serve as a good starting point in the initial stages of ideation and can also be built upon to build actual solutions to problems or even to conceptualize some kick-ass solutions in whiteboarding challenges</p><blockquote>What do you guys think? Do you think this would be something you would use in your ideation process? In case y’all have some feedback, just wanna chat or want to talk about your design needs and how I can help out, feel free to check out my <a href="https://www.nahushf.com/">portfolio</a> or <a href="https://www.linkedin.com/in/nahushfarkande/">LinkedIn</a> or hit me up at <strong>nahush.farkande@gmail.com .</strong></blockquote><p>Peace! and Happy Designing :)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7950e274ef90" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The Notorious Safari Navbar]]></title>
            <link>https://medium.com/@nahush.farkande/the-notorious-safari-navbar-a667f9446068?source=rss-cfc2cd626232------2</link>
            <guid isPermaLink="false">https://medium.com/p/a667f9446068</guid>
            <category><![CDATA[css]]></category>
            <category><![CDATA[safari]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[js]]></category>
            <dc:creator><![CDATA[Nahush Farkande]]></dc:creator>
            <pubDate>Fri, 25 Sep 2020 08:05:35 GMT</pubDate>
            <atom:updated>2020-10-06T12:28:07.372Z</atom:updated>
            <content:encoded><![CDATA[<p>It’s funny how all the browsers we have today essentially serve the same purpose but somehow take different paths when it comes to spec implementations. Be it the css-gridor the flexbox, it is not uncommon to come across frustrating issues of layout when testing your websites on different devices and browsers. But such is the world we live in, and adapt we must! This article is about a certain notorious issue I came across when testing my UI on the Safari browser on iOS and my harrowing path to figuring out the solution. Hopefully by the end of this, those of you facing similar issues might find it easier to fix them.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/0*uSaWm_iPTmK2R23N.png" /></figure><p>Now calling a bug notorious and going as far as to dedicate an entire article to it may seem like overkill to some, but let me explain why I am going to such lengths.</p><p>It all began one Tuesday afternoon when I started testing my website on the said browser. I noticed that approximately 40px of my website content was being hidden behind the bottom navbar (see Figure 1).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/710/0*RTgj2jVPEWmWT-cB" /><figcaption>Fig 1. Before: Notice how the blue button is hidden behind the navbar.</figcaption></figure><p>As always, Google came to my rescue and I found myself on <a href="https://stackoverflow.com/questions/33644584/how-might-one-force-show-the-mobile-safari-bottom-nav-bar-to-show-programmatical">this</a> stack overflow thread, where I found that a simple height:100% property on my html container would do the trick. Just like that everything was peachy again, and the bottom content was sitting easy right above the bottom navbar (see Figure 2). Well, problem solved, or so I thought.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/714/0*Zx6LITNuIOgRiROI" /><figcaption>Fig 2. After: The button is floating nicely above the navbar.</figcaption></figure><p>Fast forward to a couple of days later — I noticed that a few of my animations weren’t functioning correctly. Specifically, there was one div that was supposed to expand in height when clicked but wasn’t responding to clicks anymore. Back to debugging mode! However, this time, no combination of css or js could fix the issue. It can be truly nerve-wrecking to get so stumped by a css problem after working with it for over four years. After two grueling days of trying different JS and CSS combinations, reading different blogs and stack overflow threads, and imagining alternate career paths, I figured out that the problem had been absent a few commits earlier. Finally some direction!</p><p>After pin-pointing the exact commit where the problem started occurring, I figured out that the same height:100% was the root of all evil, so I was back to square one. Thankfully, though, this time I came across <a href="https://css-tricks.com/the-trick-to-viewport-units-on-mobile/">this peculiar blog</a> that mentioned an alternate solution to the bottom navbar issue. Now, the technique mentioned in the blog seemed like a sure shot, albeit lengthy, solution, but for me the real savior was this tiny note below one of the codepens.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*94xoS46LZGfYY9bA4STRmQ.png" /></figure><p>I’m not sure how this property differs from height or min-height 100%, and quite frankly I’m not sure if even Google does (at the time of writing, at least). But personally, I found this to be the best solution to the above bugs. It fixed all the bottom navbar and animation issues I was facing and, most importantly, saved me from an embarrassing conversation with my boss.</p><p>Now some of you may be wondering why there is no sample code attached to this post. Well the reason for that is simple enough — it wasn’t something I could reproduce at the time of writing. To be completely honest there is no conclusive proof if it was just an issue with the version of safari running on my iPhone. The fact of the matter is that -webkit-fill-available, in my personal experience, is a much more robust solution than some other solutions I’ve found on the internet.</p><p>As for the reason behind the animation problem and how -webkit-fill-available actually remedied it, that remains a mystery, unless, of course, you know the answer and are willing to share it. In that case, feel free to leave a comment. In the meantime, I hope this post came in handy for someone in a similar predicament. Happy coding :)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a667f9446068" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[A simple code splitting tutorial using react router v3 and webpack]]></title>
            <link>https://medium.com/@nahush.farkande/a-simple-code-splitting-tutorial-using-react-router-v3-and-webpack-7a6b1cf58167?source=rss-cfc2cd626232------2</link>
            <guid isPermaLink="false">https://medium.com/p/7a6b1cf58167</guid>
            <category><![CDATA[code-splitting]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[webpack]]></category>
            <dc:creator><![CDATA[Nahush Farkande]]></dc:creator>
            <pubDate>Thu, 15 Jun 2017 05:08:20 GMT</pubDate>
            <atom:updated>2017-06-15T05:08:20.388Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*J_YL3P5IAFr-CbhQeRn4iw.jpeg" /></figure><p>With the rising popularity of bundlers such as webpack, people are slowly starting to realize the problem that accompanies large bundle sizes and that is the increase in the initial load time.</p><p>For any website, the initial loading time of the website, plays a subtle but important role in the quantity of traffic coming to the website. No one likes a website, which takes forever to load, even if the website is completely fluent in all it’s operations following the initial load. When you are using bundlers, every single file you add, affects the initial load time, because guess what, all those files are gonna be combined into a singular mountain of code.</p><p>Not only is slow loading a bad user experience, it also affects the ranking of your website on google. In a study conducted by <a href="https://www.doubleclickbygoogle.com/">DoubleClick</a>, It was found that websites which took 5 seconds to load as compared to websites which took 15+ seconds observed:</p><ul><li>25% higher ad viewability</li><li>70% longer average sessions</li><li>35% lower bounce rates</li></ul><p>Fortunately webpack comes with a code splitting feature, which is quite gracious in solving this problem. In this article I will try to walk you through the details of this feature and how it can be used with react to hack your code into chunks</p><p>For starters, you need to be familiar with <a href="https://github.com/ReactTraining/react-router/tree/v3/docs">react-router v3</a> and <a href="https://webpack.js.org/">webpack</a> before diving into this tutorial, so if you haven’t already gone through the documentation, jump over right away and have a look.</p><p>Consider, you have the following router setup</p><pre>import {Login} from &#39;./path/to/Login&#39;;<br>import {Home} from &#39;./path/to/Home&#39;;</pre><pre>// Some random code goes here.<br>&lt;Router history={hashHistory} &gt;<br>    &lt;Route<br>        path=&quot;/login&quot;<br>        component={Login}<br>    /&gt;<br>    &lt;Route<br>        path=&quot;/home&quot;<br>        component={Home}<br>    /&gt;<br>&lt;/Router&gt;<br>// Some random code goes here.</pre><p>The setup is pretty obvious. Render the Login component on the /login path and the Home component on the /home path.</p><p>What we are going to do is separate out the Login and Home component codes into their own respective chunks. Now even though this seems to be quite a complicated task(which it probably is at it’s core), webpack abstracts away all the minutiae of the task inside one simple function i.e System.import . This function not only defines a split point in the code(i.e point where the code needs to chunked, Duh..) it also invokes webpack’s code splitting functionality to actually generate a different chunk for the System.import ed code. So all you have to do is call System.import in your code and webpack will handle the rest.</p><p>Take a look at this Router setup. It completely incorporates code splitting into it’s functioning</p><pre>// import {Login} from &#39;./path/to/Login&#39;; // Not needed anymore<br>// import {Home} from &#39;./path/to/Home&#39;; // Not needed anymore</pre><pre>/* Some random code goes here. */<br>&lt;Router history={hashHistory} &gt;<br>    &lt;Route<br>        path=&quot;/login&quot;<br>        getComponent={(location, cb) =&gt; {<br>            System.import(&#39;./path/to/Login&#39;)<br>                .then(module =&gt; cb(null, module.Login));<br>        }}<br>    /&gt;<br>    &lt;Route<br>        path=&quot;/home&quot;<br>        getComponent={(location, cb) =&gt; {<br>            System.import(&#39;./path/to/Home&#39;)<br>                .then(module =&gt; cb(null, module.Home));<br>        }}<br>    /&gt;<br>&lt;/Router&gt;<br>/* Some random code goes here. */</pre><p>Observe how the import statements have now been commented. Instead System.import now import the module and loads it at the specified path. The loading of the module is handled by the second parameter( cb ) passed into the getComponent attribute function. This parameter is a callback function which accepts the module to be loaded in it’s second parameter.</p><p><strong>Note: </strong><strong>System.import imports all the exports of the module found at the module path. So in order to load your module successfully, you need to specify the export name of your component within it’s corresponding module. In the above example </strong><strong>module.Home signifies loading of the export name </strong><strong>Home from the </strong><strong>module.</strong></p><p>Webpack supports another function to perform the above functionality. This function is known as <a href="https://webpack.js.org/guides/code-splitting-async/#require-ensure-">require.ensure</a> . The webpack documentation specifies that this function is a webpack specific alternative to System.import (System.import is an ECMAScript proposal which should hopefully show up in future versions of ECMAScript).</p><p>In order to use require.ensure simply change the following</p><pre>System.import(&#39;./path/to/Login&#39;)<br>    .then(module =&gt; cb(null, module.Login));</pre><p>to</p><pre>require.ensure([], require =&gt; cb(null, require(&#39;./path/to/Login&#39;).Login))</pre><p>And that’s it. Congratulations, you have succesfully managed to slice your bundle into manageable chunks, giving rise to even larger code bases(Don’t know if that’s a good thing or bad thing :P). If this article was of any help, don’t forget to recommend.</p><p>Happy coding :)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7a6b1cf58167" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Creating npm modules written in typescript]]></title>
            <link>https://medium.com/@nahush.farkande/creating-npm-modules-written-in-typescript-8d3cb4e65783?source=rss-cfc2cd626232------2</link>
            <guid isPermaLink="false">https://medium.com/p/8d3cb4e65783</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[npm]]></category>
            <category><![CDATA[typescript]]></category>
            <dc:creator><![CDATA[Nahush Farkande]]></dc:creator>
            <pubDate>Tue, 03 Jan 2017 12:32:52 GMT</pubDate>
            <atom:updated>2017-08-14T06:57:19.833Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*c8km4o36KGwAxVQ2xt_Olw.jpeg" /></figure><p>I have been working with React and Typescript for quite some time now, and to be completely honest it has been quite a roller-coaster. The type system provided by Typescript (despite the fact that it solves a number of problems occurring in ordinary javascript development) can be a little daunting at first. The biggest problem I faced was when I had to create an npm module using typescript. Even with all the resources online, I could not find any solid method of writing modules in typescript. So I decided to write a blog about the method I use to create such modules.</p><p>By the end of this blog, you will be able to create your own npm modules in typescript. However, before going any further I would like to mention that this article assumes that the reader already has a brief idea about how npm and typescript work.</p><p>So without wasting any more time, let’s get to it.</p><p><strong>Our objective here is to build a module which exposes a couple of simple functions. We will then install this module inside another project and try to call those functions inside our project.</strong></p><h4><strong><em>Step 1</em></strong>: Generate Skeleton.</h4><p>I have created a <a href="https://github.com/nahushfcc/react-redux-typescript-boilerplate">repository</a> which provides the boilerplate for a react-redux-typescript project. You can use this repository to get started or construct your own project from scratch. For the sake of brevity, I am going to go ahead assuming you are using this repository. We are going to call this module of ours testModule. The typescript configuration is as follows. The thing to note here are the rootDir and outDir as we are going to refer to them in the subsequent points</p><pre>{<br>    &quot;compilerOptions&quot;: {<br>        &quot;module&quot;: &quot;commonjs&quot;,<br>        &quot;target&quot;: &quot;es5&quot;,<br>        &quot;rootDir&quot;: &quot;src&quot;,<br>        &quot;outDir&quot;: &quot;out&quot;,<br>        &quot;declaration&quot;: true<br>    },<br>    &quot;exclude&quot;: [<br>        &quot;node_modules&quot;<br>    ]<br>}</pre><p><em>Note: If you are using this repository, the webpack configuration is not required since this module will not run on its own.</em></p><h4><strong><em>Step 2</em></strong>: Add module functions</h4><p>Inside you rootDir. Create the files printAdd.ts and printSubtract.ts. These files will contain the functions you will want to expose from this module. I am going add the following content inside these files.</p><pre>// printAdd.ts</pre><pre>export function printAdd(...numbers: number[]) {<br>    alert(`Adding the numbers: ${numbers.join(&#39;, &#39;)}`);<br>}</pre><pre>// printSubtract.ts</pre><pre>export function printSubtract(...numbers: number[]) {<br>    alert(`Subtracting the numbers: ${numbers.join(&#39;, &#39;)}`);<br>}</pre><p>The content of the functions is irrelevant. You can go ahead and add as many files and functions you want. All you need to keep in mind is to export the functions you want to expose.</p><h4><strong><em>Step 3</em></strong>: Add index</h4><p>Add another file index.ts to your rootDir. Add the following content to this file.</p><pre>export * from &#39;./printAdd&#39;;<br>export * from &#39;./printSubtract&#39;;</pre><p>At this point, it is normal if you have any doubts or questions regarding the purpose of this file. But for now just bear with me, I will explain the entire functioning of this module once it is ready.</p><h4><strong><em>Step 4</em></strong>: Configure package.json.</h4><p>Now this is the most important step of all. Inside your package.json add the main and typings fields as follows.</p><pre>// package.json<br>&quot;main&quot;: &quot;out/index.js&quot;,<br>&quot;typings&quot;: &quot;out/index.d.ts&quot;</pre><p>In case you don’t know how the node module resolution works, these fields tell where the contents and the types of the module are located.</p><p><em>Note: </em><em>out here is the </em><em>outDir as mentioned in the </em><em>tsconfig.json . Also if you will notice that the files end with </em><em>js and </em><em>d.ts and not </em><em>ts. By doing this we are wiring the module not to look at the typescript files but at the generated javascript and typescript definition when searching for a function or any entity we have exposed from the module. This is so that our resultant module can work with typescript as well as javascript projects.</em></p><h4>Step 5: Add npm scripts.</h4><p>Add the following npm scripts to your package.json</p><pre>&quot;scripts&quot;: {<br>    &quot;compile&quot;: &quot;rimraf out &amp;&amp; tsc&quot;,<br>    &quot;preinstall&quot;: &quot;npm run compile&quot;<br>}</pre><p>These scripts will come in handy while developing the module. Once you try to install the module inline, it will remove the previously generated typescript output and recompile the module to generate the js and d.ts files.</p><h4>Step 6: Create the installing project.</h4><p>Using the boilerplate create another project. We will call this project moduleConsumer.However, this time keep the webpack configuration as this project will be running on it’s own server. All you have to do now is to install your module in this project. While developing a module it is preferable to install the module inline. So assuming your module is in the same directory as moduleConsumer run npm install ../testModule inside your project directory. Now again in your rootDir, simply add an index.ts with the following content</p><pre>import {printAdd, printSubtract} from &#39;testModule&#39;;</pre><pre>printAdd(1, 2);<br>printSubtract(2, 1);</pre><p>This file should be pretty self-explanatory. We are importing the two functions we had defined in testModule and executing them.</p><p>Now if you run npm start in this directory the server should go live. And if you go to localhost:8080 surely you will get two alerts saying Adding the numbers: 1, 2 and Subtracting the numbers 1, 2.</p><h3>How it works</h3><ul><li>When we import the functions printAdd and printsSubtract from testModule, First of all, node will look for the testModule inside your node_modules directory.</li><li>Once it finds the module, it will then look for the main field inside the package.json file. This field tells node where to look for the entry point to your module. In other words, it tells node where to look for the requested content.</li><li>If you recall correctly, you will remember that we had added an index.ts file in our root and specified the corresponding js file in the main field. All we had done in this file was export the contents of other files. So now on encountering the import statement, node will look for printAdd and printSubtract inside index.js. Once it finds it, it will simply return the corresponding function.</li><li>Another important thing to understand here is the typings field in package.json. Similar to the main field the typings field simply specifies the location of the d.ts file which will contain the types of all the entities exposed by the module.</li></ul><h3>Publishing the module</h3><p>As a rule of thumb, we usually do not publish the ts files to npm when constructing an npm module. The reason being that they would only allow the module to be used in a typescript project. Instead, we publish the js and d.ts files generated by typescript. You can do this by adding a .npmignore file to your project. Npm usually refers to this file in case you do not want to publish any files to the npm registry. You will also have to add a `prepublish` hook in the package.json scripts section, which compiles the code to generate the .js and .d.ts files. You could simply rename the preinstall hook(mentioned in step 5: Adding npm scripts) to ‘prepublish’.</p><pre>//.npmignore<br>src</pre><pre>// package.json<br>&quot;scripts&quot;: {<br>    ...<br>    &quot;prepublish&quot;: &quot;npm run compile&quot;<br>    ...<br>}</pre><p><em>Note: </em><em>npm run compile runs the </em><em>compile script we created in step no 5.</em></p><p>When committing the module to a git repository, however, we do the exact opposite i.e we commit the ts files and omit the js and d.ts files. This is because, we usually clone the git repo only when we are developing the module, and quite obviously the development will only be done in typescript.</p><h3>Conclusion</h3><p>Congratulations you just created your own typescript/npm module!</p><p>You can find the entire code we have constructed above, <a href="https://github.com/nahushfcc/typescript-module-demo">here</a>.</p><p>If you have any queries or concerns regarding this article, Please feel free to leave a comment or fire up an email at farkande.nahush@gmail.com .</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8d3cb4e65783" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>