<?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"><channel><title><![CDATA[CodeCogniz]]></title><description><![CDATA[Technology / Software Engineering / Designing / Research]]></description><link>https://codecogniz.com</link><generator>RSS for Node</generator><lastBuildDate>Fri, 17 Apr 2026 10:58:53 GMT</lastBuildDate><atom:link href="https://codecogniz.com/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[Quantum Chips - A Bridge to the Quantum Realm]]></title><description><![CDATA[Scientists around the world say that the 19th century was the Age of Machines, 20th century was the Age of Information and the 21st century is the Age of Quantum. This age of quantum is a spectator of new technology evolution that existed never befor...]]></description><link>https://codecogniz.com/quantum-chips-a-bridge-to-the-quantum-realm</link><guid isPermaLink="true">https://codecogniz.com/quantum-chips-a-bridge-to-the-quantum-realm</guid><category><![CDATA[quantum computing]]></category><category><![CDATA[Quantum Mechanics]]></category><category><![CDATA[Quantum]]></category><category><![CDATA[Quantum Algorithms]]></category><category><![CDATA[Quantum Machine Learning]]></category><dc:creator><![CDATA[Rajesh Tatavarthy]]></dc:creator><pubDate>Mon, 03 Feb 2025 22:40:10 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1738621656613/4d436c7b-5148-4610-9c71-8ca2172e8e43.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Scientists around the world say that the 19th century was the <strong><em>Age of Machines</em></strong>, 20th century was the <strong><em>Age of Information</em></strong> and the 21st century is the <strong><em>Age of Quantum</em></strong>. This age of quantum is a spectator of new technology evolution that existed never before. Fields like Quantum Mechanics and Quantum computing are still in their early stages of development. To perceive it let us explore the core…</p>
<h2 id="heading-willow-a-state-of-the-art-quantum-chip">Willow, a ‘state of the art’ quantum chip</h2>
<p>In the month of December 2024, Google announced it’s new hardware called Willow, a Quantum Chip. Google claims its abilities as the state-of-art performant across a number of metrics, which means that it is the most advanced technology till today (by the end of 2024).</p>
<p>Google says, Willow outperforms and excels at 2 major achievements:</p>
<ul>
<li><h3 id="heading-quantum-error-correction">Quantum error correction</h3>
<ul>
<li>Quantum error correction is a foundational concept in field of ‘Quantum Information’. In quantum computers, error correction is very crucial because efficient quantum algorithms make use of large scale quantum interference. It is fragile and may lead to lack of accuracy in the computer performance and it eventually leads to unwanted blend between the computer and the rest of the world.</li>
</ul>
</li>
</ul>
<ul>
<li><h3 id="heading-sets-new-standards-of-computation-speed">Sets new standards of computation speed</h3>
<p>  * Willow claims it's benchmark computation speed that would defeat one of the today’s fastest supercomputers. Willow could perform a complex computation in under five minutes which require 10 Septillion years for supercomputers like ‘<strong>ORNL’s exascale supercomputer’</strong>.</p>
<p>  One Septillion = 10<sup>24</sup></p>
<p>  It means 10 Septillion years means 10<sup>25</sup> <strong>years of time.</strong></p>
<p>  <strong>Exascale supercomputer’s approximate computing speed is estimated to be one Quintillion operations per second.</strong></p>
<p>  One Quintillion = 10<sup>18</sup></p>
</li>
</ul>
<p><em>To get a better understanding of the word "Quantum" let’s dive a bit deeper to its core…</em></p>
<h2 id="heading-what-is-quantum-and-a-quantum-particle">What is Quantum and a quantum particle?</h2>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1738562444237/273c26a1-4720-489f-b6f4-68ce2e48883f.jpeg" alt class="image--center mx-auto" /></p>
<p>A Nobel laureate, Germany Physicist Max Planck proposed a theory that explains Black body radiation and energy particles called Quanta. He won Noble prize in 1918 for his remarkable work in theoretical physics. Max Planck’s Quantum Field theory defies the laws of Physics which lead to a discussion in science communities around the world and today’s world remembered him as “The Father of Quantum Theory” and also revered him as one of the founders of “Modern Physics”.</p>
<p>In the early days of the 20th Century, different scientists around the world attempted to explain Black Body radiation but it did not bridge the gap between the theory and practical aspects of it.</p>
<p>On the 19th October, 1900 Max Planck presented a new radiation principle that describes the energy distribution of thermal radiation and it stood incompatible with classical physics. Max Planck’s radiation principle explains radiation in the form of energy particles called { <strong><em><mark>Quanta</mark></em></strong> } and each particle is called { <strong><em><mark>Quantum</mark></em></strong> }</p>
<p>When he proposed this revolutionary concept, it was unnoticed at that time. But subsequently slowly it grabbed the attention of the scientists around the world.</p>
<p>when the temperature of a black body increases, it emits or absorbs energy in the form of <mark>quantized </mark> (chunks) electromagnetic waves rather than continuous flow. Energy gain or loss happens in the form of multiple small energy packets. This smallest energy particle is called <strong><mark>Quantum</mark></strong>.</p>
<p>Max Planck’s energy quantization explained with the help an equation:</p>
<h2 id="heading-e-hv"><strong><em>E = hv</em></strong></h2>
<p>where ‘h’ denotes Planck’s Constant whose value is equal to 6.62607015X10^(-34) Joule Sec,</p>
<p>and ‘v’ denotes the frequency and ‘E’ denotes the Energy of the photon (light) particle.</p>
<p>This equation solves ultraviolet catastrophe and it clearly states that:</p>
<p>When assuming the energy emission happens only in the integral multiples (hv) from an object (like black body), the frequency of that electromagnetic radiation is directly proportional to the magnitude of the radiating energy.</p>
<p>In simple terms, Energy of a particle is directly proportional to its frequency.</p>
<p>Max Planck named such energy particle as { <strong><em><mark>Quantum</mark></em></strong> }</p>
<p>Max Planck’s constant plays a crucial role in understanding the motion of atoms, subatomic particles which shows a way to study the functioning of computer chips, solar panels, lasers… etc.</p>
<p>And this resulted the new branches of Physics to emerge like “Quantum Mechanics” and “ Modern Electronics”, “Quantum Optics” and others. Quantum Mechanics plays a crucial role in explaining and creating many things in today’s world like,</p>
<ul>
<li><p>Flash memory drives in USB apply quantum tunnelling to erase memory cells.</p>
</li>
<li><p>GPS (Global Positioning System) works on atomic clocks that work on quantum mechanics principles.</p>
</li>
<li><p>Electron microscope works on the quantum tunnelling concept and it can magnify objects to millions of times to their original size.</p>
</li>
<li><p>MRI (Magnetic Resonance Imaging) is used to study tissues in organic matter like human body and it works on nuclear magnetic resonance, which is a combination of quantum mechanics and classical electrodynamics. During MRI scanning, hydrogen atom is used to generate high resolution images of the tissues.</p>
</li>
<li><p>Quantum mechanics is used to study the evolution of starts and their existence which helps scientists to study and explore solar systems and the universe.</p>
</li>
<li><p>Quantum cryptography, Lasers,….. and so on.</p>
</li>
</ul>
<p><strong>{ <em><mark>To be acquainted with topics mentioned in this article like Quantum Theory and its applications need a lot of explanation and discussion which is out of scope in this article….</mark></em> }</strong></p>
<h2 id="heading-wave-particle-duality">Wave - Particle Duality</h2>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1738579070865/0a711db9-f428-47f0-b1ff-b768664c63b5.jpeg" alt class="image--center mx-auto" /></p>
<p>Debate about the nature of atomic particles among the scientists around the world dates back 17th century. At that time, Isaac Newton proposed the nature of light as corpuscular where as another scientist Christiaan Huygens stated it as wave nature and both of these theories contradict each other. Later, Isaac Newton appeased both the theories and proposed a new theory called wave-particle duality of a light.</p>
<p>In the 18th century, Thomas Young’s double slit experiment proved that the photon particles have wave nature as a result of diffraction of the particles emitted from the source which created light and dark spot patterns on the receiver. Scientists further studied this behaviour and they found that when a detector (observer) is placed on the photon beam, particle nature of the photons is observed otherwise they exhibit wave nature. From there onwards the concept of wave - particle duality was widely discussed among the scientists of that time including Einstein, Heisenberg and others.</p>
<h2 id="heading-how-wave-particle-duality-is-related-to-computers-in-2024-25">How wave particle duality is related to computers in 2024-25?</h2>
<p>Quantum computers solve mathematical problems at an exponential speed which is unattainable or a tedious task even for super computers that exist today.</p>
<p>In today’s classical computers, Bits are fundamental units of data. To process any kind of operations inside a computer, a Bit can handle a state of either 0 or 1 at a time which limits the speed of calculations and computations of more complex problems whose out come is based on exceedingly high precision values.</p>
<p>In quantum computers, the fundamental unit of data is a <strong><mark>Qubit</mark></strong>. A Qubit at a time can exist in a state of either 0 or 1 or both which is a Superposition of both the states. It means a Qubit can handle a binary nature of a Bit at a time which simulates the <mark>wave-particle duality</mark>. When Qubits entangle to each other, one can influence the state of another, even though they are far away from one another. It leads to something called <mark>Quantum Parallelism</mark>. This condition of qubits creates the powerful correlation between them and adds exponential calculating power of the computer. Different Quantum algorithms in quantum computers work on the principles like Superposition, Entanglement and Interference to get the accurate results of more complex problems with faster computation speed.</p>
<p>When we observe all of these topics of Quantum mechanics and computing, we may have a feeling of a different reality / dimension. And we can call it as ‘realm’, a <mark>Quantum Realm</mark>.</p>
<h2 id="heading-does-quantum-realm-really-exist">Does Quantum Realm really exist?</h2>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1738580134381/0c9a3efc-aed2-4f58-a88a-9d90965598c8.jpeg" alt class="image--center mx-auto" /></p>
<p><mark>May be, yes…!</mark></p>
<p>The existential dimensions of subatomic particles and Boson particles like Photons at which they exhibit their behaviour can be termed and visualized as <strong><mark>Quantum Realm</mark></strong>. Scientists, Mathematicians and Technologists around the world are still working on the concept of quantum realm to decipher and manifest it to the human scale. Once they find a way, it is expected to solve hidden mysteries in the nature.</p>
<h2 id="heading-tech-giants-and-quantum-computers-in-todays-world-2025"><strong>Tech giants and Quantum Computers in today’s world (…2025) !</strong></h2>
<p>Big players around the world have been working on the research and development of AI Accelerated Chips which could work on Quantum Computing principles.</p>
<h3 id="heading-ibm">IBM</h3>
<p>IBM has quantum exploration facilities such as <strong><em>Quantum Composer</em></strong> and <strong><em>Quantum Lab</em></strong>. In the year 2025, IBM is aiming to release the largest quantum computer ever, by combining many quantum chips in parallel.</p>
<h3 id="heading-google">Google</h3>
<p>Google Quantum AI is a actively working on faster ever - computing abilities. The Quantum Artificial Intelligence Lab is a collaborative research facility undertaken by Google, NASA and The Universities Space Research association.</p>
<h3 id="heading-nvidia">NVidia</h3>
<p>NVidia’s CUDA-Q is a platform that enables services on CPU,GPU and QPU. This platform offers GPU simulations when adequate QPU resources are not available. In early 2025, NVidia’s Blackwell architecture was announced for AI Accelerated chips, which can simulate Quantum Computing and hybrid application development procedures. And NVidia also announced it’s next release ‘Rubin’ a superchip successor of Blackwell in 2026.</p>
<h3 id="heading-amazon">Amazon</h3>
<p>Amazon Bracket service is an accelerated quantum computing research facility on Amazon cloud. It allows the users to connect multiple quantum computers.</p>
<h3 id="heading-ionq">IonQ</h3>
<p>IonQ offers quantum services for customers of various needs. And it uses CUDA-Q platform.</p>
<p><em>Many other players around the world are in the race of</em> <strong><em><mark>Quantum and AI supremacy</mark>*</em></strong>.*</p>
<h2 id="heading-what-the-future-holds"><strong>What the future holds..!</strong></h2>
<p><strong><em><mark>Exciting and Unknown….!</mark></em></strong></p>
<p><strong><em><mark>I conclude here, as the topics discussed in this article are just a glimpse of quantum mechanics and its applications in the field of computing. However, each one of them has a potential of individual study and research allowing an in-depth exploration of the subject.</mark></em></strong></p>
]]></content:encoded></item><item><title><![CDATA[JavaScript - Tidbits]]></title><description><![CDATA[Like sets and relations in mathematics, JavaScript has built-in objects to demonstrate such logics and make developers’ life more logical, easy going and fun.
JavaScript has a special object called ‘Set’. A Set() is a constructor that creates a set o...]]></description><link>https://codecogniz.com/javascript-tidbits</link><guid isPermaLink="true">https://codecogniz.com/javascript-tidbits</guid><category><![CDATA[JavaScript]]></category><category><![CDATA[Sets]]></category><category><![CDATA[sets in js]]></category><category><![CDATA[Sets in JavaScript]]></category><category><![CDATA[sets relationships]]></category><dc:creator><![CDATA[Rajesh Tatavarthy]]></dc:creator><pubDate>Mon, 14 Oct 2024 05:28:33 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1723008193096/dd71d784-ef23-4881-89b1-ba36cd75016d.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Like <em>sets and relations</em> in mathematics, JavaScript has built-in objects to demonstrate such logics and make developers’ life more logical, easy going and fun.</p>
<p>JavaScript has a special object called ‘Set’. A Set() is a constructor that creates a set object and holds a few methods as explained here and with help of those methods it can perform different operations of sets like union, intersection, difference etc.</p>
<p><strong>Syntax:</strong><br /><code>&lt;declaration&gt; &lt;identifier&gt; = new Set()</code><br /><strong>or</strong><br /><code>&lt;declaration&gt; &lt;identifier&gt; = new Set(&lt;array&gt;)</code></p>
<p><strong>Eg:</strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> a = <span class="hljs-keyword">new</span> <span class="hljs-built_in">Set</span>([<span class="hljs-number">1</span>,<span class="hljs-number">2</span>,<span class="hljs-number">3</span>,<span class="hljs-number">4</span>,<span class="hljs-number">5</span>])
</code></pre>
<p>A Set in JavaScript is a constructor which can only be initialized with <code>new</code> operator. An empty set can also be created and utilized later to add, modify or delete some data with the help of its instance methods.</p>
<p>Like other objects in JavaScript (such as Map), Set has generic properties and methods such as <code>size</code>, <code>has()</code>, <code>keys()</code>, <code>values()</code>.</p>
<p>For example, let's consider a new set:</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> setSample = <span class="hljs-keyword">new</span> <span class="hljs-built_in">Set</span>([<span class="hljs-number">0.1</span>,<span class="hljs-number">22</span>,<span class="hljs-number">3</span>,<span class="hljs-number">43</span>,<span class="hljs-number">54</span>,<span class="hljs-number">0.5</span>,<span class="hljs-number">101</span>,<span class="hljs-number">121</span>,<span class="hljs-number">200</span>])
setSample.size    <span class="hljs-comment">// returns: 9</span>
setSample.has(<span class="hljs-number">200</span>)  <span class="hljs-comment">// returns: true</span>
setSample.has(<span class="hljs-number">2010</span>)  <span class="hljs-comment">// returns: false</span>
setSample.keys() <span class="hljs-comment">// returns set Iterator</span>
setSample.values() <span class="hljs-comment">// returns set Iterator</span>
</code></pre>
<p>Every Set by default contains a special instance methods like <code>keys()</code> and <code>values()</code> which in return creates an iterator object.</p>
<ul>
<li><h4 id="heading-in-javascript-all-built-in-iterators-inherit-from-iterator-class">In JavaScript all built-in iterators inherit from Iterator class</h4>
</li>
</ul>
<p>Consider 2 sets A and B and lets go through some basic math:<br /><strong><mark>Union:</mark></strong> <mark>A∪B</mark><br /><strong><mark>Intersection:</mark></strong> <mark>A∩B</mark><br /><strong><mark>Difference:</mark></strong> <mark>A - B ≣ A \ B</mark><br /><strong><mark>SymmetricDifference:</mark></strong> <mark>(A \ B) ∪ (B \ A)</mark><br /><strong><mark>isSubsetOf:</mark></strong> <mark>A⊆B</mark><br /><strong><mark>isSupersetOf:</mark></strong> <mark>A⊇B</mark><br /><strong><mark>isDisjointFrom:</mark></strong> <mark>A∩B = ∅</mark></p>
<p>A Set constructor holds a collection of instance methods which are used to handle these mathematical operations in JavaScript efficiently.</p>
<p>Let's consider 2 arrays namely ‘arrayA’ and ‘arrayB’ and thier sets ‘setA’ and ‘setB’ respectively:</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1728568126696/e916f61e-9e11-4809-bd8a-19e9d1039064.png" alt class="image--center mx-auto" /></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">let</span> arrayA = [<span class="hljs-number">0</span>,<span class="hljs-number">2</span>,<span class="hljs-number">5</span>,<span class="hljs-number">7</span>,<span class="hljs-number">8</span>,<span class="hljs-number">4</span>,<span class="hljs-number">6</span>,<span class="hljs-number">1</span>], arrayB = [<span class="hljs-number">3</span>,<span class="hljs-number">9</span>,<span class="hljs-number">10</span>,<span class="hljs-number">1</span>,<span class="hljs-number">12</span>,<span class="hljs-number">21</span>,<span class="hljs-number">33</span>,<span class="hljs-number">42</span>,<span class="hljs-number">2</span>];
</code></pre>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1728569169877/40072254-62bb-4b3a-b34b-9bd33e20d8b2.png" alt class="image--center mx-auto" /></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> setA = <span class="hljs-keyword">new</span> <span class="hljs-built_in">Set</span>(arrayA), setB = <span class="hljs-keyword">new</span> <span class="hljs-built_in">Set</span>(arrayB);
</code></pre>
<h3 id="heading-union-of-sets">Union of Sets</h3>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1728646888117/150c9237-851c-4d34-922b-56c21383c9c5.png" alt class="image--center mx-auto" /></p>
<p><strong><mark>Use: </mark></strong> <mark>To find unique features among set-like data entities.</mark></p>
<p>Syntax: <code>&lt;set A&gt;.union(&lt;set B&gt;)</code></p>
<p>Eg:</p>
<pre><code class="lang-javascript">setA.union(setB);
<span class="hljs-comment">// results in:  Set(15) {0,2,5,7,8,4,6,1,3,9,10,12,21,33,42}</span>
</code></pre>
<p>It ignores the duplicates elements and makes a set of unique elements.</p>
<h4 id="heading-intersection-of-sets">Intersection of Sets:</h4>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1728646473901/713947be-6b60-47b3-b511-66d2b75ea322.png" alt class="image--center mx-auto" /></p>
<p><strong><mark>Use: </mark></strong> <mark>To identify similarities between two set-like data entities.</mark></p>
<p>Syntax: <code>&lt;set A&gt;.intersection(&lt;set B&gt;)</code></p>
<p>Eg:</p>
<pre><code class="lang-javascript">setA.intersection(setB);
<span class="hljs-comment">// results in:  Set(2) {2,1}</span>
</code></pre>
<p>It gets the common elements among them and ignores the rest of the elements.</p>
<h4 id="heading-difference-of-sets">Difference of Sets:</h4>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1728647628475/dffefe6f-10d1-4e40-a689-084ef32bda44.png" alt class="image--center mx-auto" /></p>
<p><strong><mark>Use:</mark></strong> <mark>To find the features that are present only in the first one among the two set-like data entities.</mark></p>
<p>Syntax: <code>&lt;set A&gt;.difference(&lt;set B&gt;)</code></p>
<p>Eg:</p>
<pre><code class="lang-javascript">setA.difference(setB);
<span class="hljs-comment">// results in:  Set(6) {0,5,7,8,4,6}</span>

setB.difference(setA);
<span class="hljs-comment">// results in:  Set(7) {3,9,10,12,21,33,42}</span>

setA.difference(setA);
<span class="hljs-comment">// results in:  Set(0) {}</span>
</code></pre>
<h4 id="heading-symmetric-difference-of-sets">Symmetric Difference of Sets:</h4>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1728647638666/f53afefa-322f-4c6f-8314-58721c57c331.png" alt class="image--center mx-auto" /></p>
<p><strong><mark>Use:</mark></strong> <mark>To get rid of the common features among the two data entities. In other words, it is quiet opposite to Intersection.</mark></p>
<p>Syntax: <code>&lt;set A&gt;.symmetricDifference(&lt;set B&gt;)</code></p>
<p>Eg:</p>
<pre><code class="lang-javascript">setA.symmetricDifference(setB);
<span class="hljs-comment">// results in Set(13) {0,5,7,8,4,6,3,9,10,12,21,33,42}</span>

setB.symmetricDifference(setA)
<span class="hljs-comment">// results in Set(13) {3,9,10,12,21,33,42,0,5,7,8,4,6}</span>
</code></pre>
<h4 id="heading-disjoint-sets">Disjoint Sets:</h4>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1728647835505/ac7b0d13-ee25-4f60-8ded-3f363c906330.png" alt class="image--center mx-auto" /></p>
<p><strong><mark>Use:</mark></strong> <mark>To verity if both of them do not match each other.</mark></p>
<p>Syntax: <code>&lt;set A&gt;.isDisjointFrom(&lt;set B&gt;)</code></p>
<p>Eg:</p>
<pre><code class="lang-javascript">setA.isDisjointFrom(setB);
<span class="hljs-comment">// results in Set() {}</span>
</code></pre>
<h4 id="heading-subset-of-sets">Subset of Sets:</h4>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1728648255962/9c0e23d8-22d5-49cd-9a51-31cf96bd4ef7.png" alt class="image--center mx-auto" /></p>
<p><strong><mark>Use:</mark></strong> <mark>To verify if the first data entity is a part of the second one.</mark></p>
<p>Syntax: <code>&lt;set A&gt;.isSubsetOf(&lt;set B&gt;)</code></p>
<p>Eg:</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">let</span> arrayA = [<span class="hljs-number">9</span>,<span class="hljs-number">10</span>,<span class="hljs-number">1</span>,<span class="hljs-number">21</span>], arrayB = [<span class="hljs-number">3</span>,<span class="hljs-number">9</span>,<span class="hljs-number">10</span>,<span class="hljs-number">1</span>,<span class="hljs-number">12</span>,<span class="hljs-number">21</span>,<span class="hljs-number">33</span>,<span class="hljs-number">42</span>,<span class="hljs-number">2</span>];
<span class="hljs-keyword">const</span> setA = <span class="hljs-keyword">new</span> <span class="hljs-built_in">Set</span>(arrayA), setB = <span class="hljs-keyword">new</span> <span class="hljs-built_in">Set</span>(arrayB);
setA.isSubsetOf(setB);
<span class="hljs-comment">// result is true</span>

setA.isSubsetOf(setA);
<span class="hljs-comment">// result is true</span>
</code></pre>
<h4 id="heading-superset-of-sets">Superset of Sets:</h4>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1728648274766/01fe758e-835c-4661-90e1-2389c9df6036.png" alt class="image--center mx-auto" /></p>
<p><strong><mark>Use:</mark></strong> <mark>To verify if the first data entity has the second one as a part of it.</mark></p>
<p>Syntax: <code>&lt;set A&gt;.isSupersetOf(&lt;set B&gt;)</code></p>
<p>Eg:</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">let</span> arrayA = [<span class="hljs-number">9</span>,<span class="hljs-number">10</span>,<span class="hljs-number">1</span>,<span class="hljs-number">21</span>], arrayB = [<span class="hljs-number">3</span>,<span class="hljs-number">9</span>,<span class="hljs-number">10</span>,<span class="hljs-number">1</span>,<span class="hljs-number">12</span>,<span class="hljs-number">21</span>,<span class="hljs-number">33</span>,<span class="hljs-number">42</span>,<span class="hljs-number">2</span>];
<span class="hljs-keyword">const</span> setA = <span class="hljs-keyword">new</span> <span class="hljs-built_in">Set</span>(arrayA), setB = <span class="hljs-keyword">new</span> <span class="hljs-built_in">Set</span>(arrayB);
setB.isSupersetOf(setA);
<span class="hljs-comment">// result is true</span>

setB.isSupersetOf(setB);
<span class="hljs-comment">// result is true</span>
</code></pre>
<p>Besides these regular math operations, Set constructor also holds other instance methods to operations like CRUD, iterations etc.</p>
<p><code>add() delete() clear() size() has() entries() keys() values() forEach() Symbol.iterator next()</code></p>
<p>Examples of these operations:<br />Let’s consider arrays p1,p2,p3,p4 and p5.</p>
<pre><code class="lang-plaintext">let p1 = ['ravi',25,'Indian', 'graduate','techie']
let p2 = ['Ravi',32,'Indian', 'graduate','no-techie']
let p3 = ['Ronald',23,'American','highSchool','techie']
let p4 = ['Arun',32,'Indian','graduation','techie']
let p5 = ['Dennis',40,'American', 'under-graduate','non-techie']
</code></pre>
<p>Using a Set constructor we can create different sets out of each and every array as shown here:</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> setP1 = <span class="hljs-keyword">new</span> <span class="hljs-built_in">Set</span>(p1) 
<span class="hljs-keyword">const</span> setP2 = <span class="hljs-keyword">new</span> <span class="hljs-built_in">Set</span>(p2) 
<span class="hljs-keyword">const</span> setP3 = <span class="hljs-keyword">new</span> <span class="hljs-built_in">Set</span>(p3) 
<span class="hljs-keyword">const</span> setP4 = <span class="hljs-keyword">new</span> <span class="hljs-built_in">Set</span>(p4) 
<span class="hljs-keyword">const</span> setP5 = <span class="hljs-keyword">new</span> <span class="hljs-built_in">Set</span>(p5)
</code></pre>
<pre><code class="lang-javascript"><span class="hljs-keyword">let</span> countryCriteria = [<span class="hljs-string">'Indian'</span>, <span class="hljs-string">'American'</span>,<span class="hljs-string">'European'</span>]
<span class="hljs-keyword">let</span> ageCriteria = [<span class="hljs-number">23</span>,<span class="hljs-number">25</span>,<span class="hljs-number">32</span>,<span class="hljs-number">40</span>]
<span class="hljs-keyword">const</span> setCC = <span class="hljs-keyword">new</span> <span class="hljs-built_in">Set</span>(countryCriteria)
<span class="hljs-keyword">const</span> setAC = <span class="hljs-keyword">new</span> <span class="hljs-built_in">Set</span>(ageCriteria)
</code></pre>
<h3 id="heading-advantages-of-sets">Advantages of Sets</h3>
<ul>
<li><p>Sets avoid unnecessary iterations through arrays' or objects' data.</p>
</li>
<li><p>They do not modify original array of data.</p>
</li>
</ul>
<h3 id="heading-real-time-scenarios">Real-time scenarios</h3>
<p>There are some real-time scenarios where Sets make developers' life easy such as when any two data entities (sets) are considered:</p>
<ul>
<li><p>Useful to find unique entries in a data collection like stores, books, etc.</p>
</li>
<li><p>Missing entries from a large data sets (like Censuses in a city) can be found easily with minimal coding efforts.</p>
</li>
<li><p>Find out if an existing user is entering / leaving the chat rooms or from online meeting areas.</p>
</li>
<li><p>In a large scalable applications, compare and filter the datasets based on certain predefined features and restrict their access to a particular domain routes in that application.</p>
</li>
<li><p>Identify similar molecular structures in various chemical composition data.</p>
</li>
<li><p>Identify and keep track of similar cyber attacks that happen frequently on a large scale of networking pipelines.</p>
</li>
</ul>
<h3 id="heading-order-of-complexity">Order of Complexity</h3>
<p>Iterators use index numbers to locate their elements where as Sets use <mark>Hash tables</mark>. Hash table is a data structure and it is a generalization of an ordinary array whose expected time of search reasonably is O(n) where an average value of n=1.</p>
<p>Hash tables are more performant while executing operations like data searching and sorting etc on large data sets. They work on key-index combinations instead of iterating through an entire array of elements.</p>
<p>Order of Complexity of sets can be represented as O(log N), sometimes O(N). It depends on the complexity of the logic written.</p>
<p>Let’s take an example of 2 arrays, find common elements in both of them and remove similar ones from the resultant array. Perform this operation in 2 ways:</p>
<ul>
<li><p>Without using Sets</p>
</li>
<li><p>Using Sets</p>
</li>
</ul>
<pre><code class="lang-javascript"> <span class="hljs-keyword">let</span> arrResult=[];
 <span class="hljs-keyword">let</span> arr1 = [<span class="hljs-number">1</span>,<span class="hljs-number">2</span>,<span class="hljs-number">3</span>,<span class="hljs-number">4</span>,<span class="hljs-number">5</span>,<span class="hljs-number">6</span>,<span class="hljs-number">7</span>,<span class="hljs-number">8</span>,<span class="hljs-number">9</span>,<span class="hljs-number">10</span>,<span class="hljs-number">1</span>,<span class="hljs-number">2</span>,<span class="hljs-number">3</span>,<span class="hljs-number">4</span>,<span class="hljs-number">5</span>,<span class="hljs-number">6</span>,<span class="hljs-number">7</span>,<span class="hljs-number">8</span>,<span class="hljs-number">9</span>,<span class="hljs-number">20</span>,<span class="hljs-number">1</span>,<span class="hljs-number">2</span>,<span class="hljs-number">3</span>,<span class="hljs-number">4</span>,<span class="hljs-number">5</span>,<span class="hljs-number">6</span>,<span class="hljs-number">7</span>,<span class="hljs-number">8</span>,<span class="hljs-number">9</span>,<span class="hljs-number">30</span>,<span class="hljs-number">1</span>,<span class="hljs-number">2</span>,<span class="hljs-number">3</span>,<span class="hljs-number">4</span>,<span class="hljs-number">5</span>,<span class="hljs-number">6</span>,<span class="hljs-number">7</span>,<span class="hljs-number">8</span>,<span class="hljs-number">9</span>,<span class="hljs-number">40</span>,<span class="hljs-number">1</span>,<span class="hljs-number">2</span>,<span class="hljs-number">3</span>,<span class="hljs-number">4</span>,<span class="hljs-number">5</span>,<span class="hljs-number">6</span>,<span class="hljs-number">7</span>,<span class="hljs-number">8</span>,<span class="hljs-number">9</span>,<span class="hljs-number">50</span>,<span class="hljs-number">1</span>,<span class="hljs-number">2</span>,<span class="hljs-number">3</span>,<span class="hljs-number">4</span>,<span class="hljs-number">5</span>,<span class="hljs-number">6</span>,<span class="hljs-number">7</span>,<span class="hljs-number">8</span>,<span class="hljs-number">9</span>,<span class="hljs-number">60</span>,<span class="hljs-number">1</span>,<span class="hljs-number">2</span>,<span class="hljs-number">3</span>,<span class="hljs-number">4</span>,<span class="hljs-number">5</span>,<span class="hljs-number">6</span>,<span class="hljs-number">7</span>,<span class="hljs-number">8</span>,<span class="hljs-number">9</span>,<span class="hljs-number">70</span>,<span class="hljs-number">1</span>,<span class="hljs-number">2</span>,<span class="hljs-number">3</span>,<span class="hljs-number">4</span>,<span class="hljs-number">5</span>,<span class="hljs-number">6</span>,<span class="hljs-number">7</span>,<span class="hljs-number">8</span>,<span class="hljs-number">9</span>,<span class="hljs-number">80</span>,<span class="hljs-number">1</span>,<span class="hljs-number">2</span>,<span class="hljs-number">3</span>,<span class="hljs-number">4</span>,<span class="hljs-number">5</span>,<span class="hljs-number">6</span>,<span class="hljs-number">7</span>,<span class="hljs-number">8</span>,<span class="hljs-number">9</span>,<span class="hljs-number">90</span>,<span class="hljs-number">1</span>,<span class="hljs-number">2</span>,<span class="hljs-number">3</span>,<span class="hljs-number">4</span>,<span class="hljs-number">5</span>,<span class="hljs-number">6</span>,<span class="hljs-number">7</span>,<span class="hljs-number">8</span>,<span class="hljs-number">9</span>,<span class="hljs-number">100</span>,<span class="hljs-number">1</span>,<span class="hljs-number">2</span>,<span class="hljs-number">3</span>,<span class="hljs-number">4</span>,<span class="hljs-number">5</span>,<span class="hljs-number">6</span>,<span class="hljs-number">7</span>,<span class="hljs-number">8</span>,<span class="hljs-number">9</span>,<span class="hljs-number">110</span>,<span class="hljs-number">1</span>,<span class="hljs-number">2</span>,<span class="hljs-number">3</span>,<span class="hljs-number">4</span>,<span class="hljs-number">5</span>,<span class="hljs-number">6</span>,<span class="hljs-number">7</span>,<span class="hljs-number">8</span>,<span class="hljs-number">9</span>,<span class="hljs-number">120</span>,<span class="hljs-number">1</span>,<span class="hljs-number">2</span>,<span class="hljs-number">3</span>,<span class="hljs-number">4</span>,<span class="hljs-number">5</span>,<span class="hljs-number">6</span>,<span class="hljs-number">7</span>,<span class="hljs-number">8</span>,<span class="hljs-number">9</span>,<span class="hljs-number">130</span>,<span class="hljs-number">1</span>,<span class="hljs-number">2</span>,<span class="hljs-number">3</span>,<span class="hljs-number">4</span>,<span class="hljs-number">5</span>,<span class="hljs-number">6</span>,<span class="hljs-number">7</span>,<span class="hljs-number">8</span>,<span class="hljs-number">9</span>,<span class="hljs-number">140</span>,<span class="hljs-number">1</span>,<span class="hljs-number">2</span>,<span class="hljs-number">3</span>,<span class="hljs-number">4</span>,<span class="hljs-number">5</span>,<span class="hljs-number">6</span>,<span class="hljs-number">7</span>,<span class="hljs-number">8</span>,<span class="hljs-number">9</span>,<span class="hljs-number">150</span>,<span class="hljs-number">1</span>,<span class="hljs-number">2</span>,<span class="hljs-number">3</span>,<span class="hljs-number">4</span>,<span class="hljs-number">5</span>,<span class="hljs-number">6</span>,<span class="hljs-number">7</span>,<span class="hljs-number">8</span>,<span class="hljs-number">9</span>,<span class="hljs-number">160</span>,<span class="hljs-number">1</span>,<span class="hljs-number">2</span>,<span class="hljs-number">3</span>,<span class="hljs-number">4</span>,<span class="hljs-number">5</span>,<span class="hljs-number">6</span>,<span class="hljs-number">7</span>,<span class="hljs-number">8</span>,<span class="hljs-number">9</span>,<span class="hljs-number">170</span>,<span class="hljs-number">1</span>,<span class="hljs-number">2</span>,<span class="hljs-number">3</span>,<span class="hljs-number">4</span>,<span class="hljs-number">5</span>,<span class="hljs-number">6</span>,<span class="hljs-number">7</span>,<span class="hljs-number">8</span>,<span class="hljs-number">9</span>,<span class="hljs-number">180</span>,<span class="hljs-number">1</span>,<span class="hljs-number">2</span>,<span class="hljs-number">3</span>,<span class="hljs-number">4</span>,<span class="hljs-number">5</span>,<span class="hljs-number">6</span>,<span class="hljs-number">7</span>,<span class="hljs-number">8</span>,<span class="hljs-number">9</span>,<span class="hljs-number">190</span>,<span class="hljs-number">1</span>,<span class="hljs-number">2</span>,<span class="hljs-number">3</span>,<span class="hljs-number">4</span>,<span class="hljs-number">5</span>,<span class="hljs-number">6</span>,<span class="hljs-number">7</span>,<span class="hljs-number">8</span>,<span class="hljs-number">9</span>,<span class="hljs-number">200</span>];
 <span class="hljs-comment">// Lenght of arr1 is 200;</span>
 <span class="hljs-keyword">let</span> arr2 = [<span class="hljs-number">1</span>,<span class="hljs-number">2</span>,<span class="hljs-number">3</span>,<span class="hljs-number">4</span>,<span class="hljs-number">5</span>,<span class="hljs-number">6</span>,<span class="hljs-number">7</span>,<span class="hljs-number">8</span>,<span class="hljs-number">9</span>,<span class="hljs-number">10</span>,<span class="hljs-number">1</span>,<span class="hljs-number">2</span>,<span class="hljs-number">3</span>,<span class="hljs-number">4</span>,<span class="hljs-number">5</span>,<span class="hljs-number">6</span>,<span class="hljs-number">7</span>,<span class="hljs-number">8</span>,<span class="hljs-number">9</span>,<span class="hljs-number">20</span>,<span class="hljs-number">1</span>,<span class="hljs-number">2</span>,<span class="hljs-number">3</span>,<span class="hljs-number">4</span>,<span class="hljs-number">5</span>,<span class="hljs-number">6</span>,<span class="hljs-number">7</span>,<span class="hljs-number">8</span>,<span class="hljs-number">9</span>,<span class="hljs-number">30</span>,<span class="hljs-number">1</span>,<span class="hljs-number">2</span>,<span class="hljs-number">3</span>,<span class="hljs-number">4</span>,<span class="hljs-number">5</span>,<span class="hljs-number">6</span>,<span class="hljs-number">7</span>,<span class="hljs-number">8</span>,<span class="hljs-number">9</span>,<span class="hljs-number">40</span>,<span class="hljs-number">1</span>,<span class="hljs-number">2</span>,<span class="hljs-number">3</span>,<span class="hljs-number">4</span>,<span class="hljs-number">5</span>,<span class="hljs-number">6</span>,<span class="hljs-number">7</span>,<span class="hljs-number">8</span>,<span class="hljs-number">9</span>,<span class="hljs-number">50</span>,<span class="hljs-number">1</span>,<span class="hljs-number">2</span>,<span class="hljs-number">3</span>,<span class="hljs-number">4</span>,<span class="hljs-number">5</span>,<span class="hljs-number">6</span>,<span class="hljs-number">7</span>,<span class="hljs-number">8</span>,<span class="hljs-number">9</span>,<span class="hljs-number">60</span>,<span class="hljs-number">1</span>,<span class="hljs-number">2</span>,<span class="hljs-number">3</span>,<span class="hljs-number">4</span>,<span class="hljs-number">5</span>,<span class="hljs-number">6</span>,<span class="hljs-number">7</span>,<span class="hljs-number">8</span>,<span class="hljs-number">9</span>,<span class="hljs-number">70</span>,<span class="hljs-number">1</span>,<span class="hljs-number">2</span>,<span class="hljs-number">3</span>,<span class="hljs-number">4</span>,<span class="hljs-number">5</span>,<span class="hljs-number">6</span>,<span class="hljs-number">7</span>,<span class="hljs-number">8</span>,<span class="hljs-number">9</span>,<span class="hljs-number">80</span>,<span class="hljs-number">1</span>,<span class="hljs-number">2</span>,<span class="hljs-number">3</span>,<span class="hljs-number">4</span>,<span class="hljs-number">5</span>,<span class="hljs-number">6</span>,<span class="hljs-number">7</span>,<span class="hljs-number">8</span>,<span class="hljs-number">9</span>,<span class="hljs-number">90</span>,<span class="hljs-number">1</span>,<span class="hljs-number">2</span>,<span class="hljs-number">3</span>,<span class="hljs-number">4</span>,<span class="hljs-number">5</span>,<span class="hljs-number">6</span>,<span class="hljs-number">7</span>,<span class="hljs-number">8</span>,<span class="hljs-number">9</span>,<span class="hljs-number">100</span>];
 <span class="hljs-comment">// Lenght of arr1 is 100;</span>
</code></pre>
<p><strong>Let <mark>arr1</mark></strong> and <strong><mark>arr2</mark></strong> are two different arrays (as shown above) with lengths 200 and 100 respectively.</p>
<p><strong><mark>arrResult</mark></strong> is an empty array to store the common elements in both the arrays after removing the duplicates.</p>
<h3 id="heading-without-using-sets"><strong>Without using Sets:</strong></h3>
<pre><code class="lang-javascript">arr1.filter(<span class="hljs-function"><span class="hljs-params">e</span>=&gt;</span>arr2.includes(e) ? !arrResult.includes(e) ? arrResult.push(e):<span class="hljs-string">''</span>:<span class="hljs-string">''</span>)
<span class="hljs-built_in">console</span>.log(arrResult);
</code></pre>
<p><em><mark>In this method, the browser takes 0.6000000238418579 milli seconds to execute the logic.</mark></em></p>
<h3 id="heading-using-sets">Using Sets</h3>
<pre><code class="lang-javascript"><span class="hljs-keyword">let</span> setArr1 = <span class="hljs-keyword">new</span> <span class="hljs-built_in">Set</span>(arr1); 
<span class="hljs-keyword">let</span> setArr2 = <span class="hljs-keyword">new</span> <span class="hljs-built_in">Set</span>(arr2);
arrResult = [...setArr1.intersection(setArr2)]
<span class="hljs-built_in">console</span>.log(arrResult);
</code></pre>
<p><em><mark>In this method, the browser takes 0.3999999761581421 milli seconds to execute the logic.</mark></em></p>
<h3 id="heading-in-this-case-using-sets-is-66-more-performant-than-the-previous-method">In this case, using sets is 66(+)% more performant than the previous method.</h3>
]]></content:encoded></item><item><title><![CDATA[Package Managers]]></title><description><![CDATA[Package Managers
Sometimes…, Front End engineering seems more complicated but there is alot to explore besides ever changing technologies. Moreover, it is not dependent on any technology or platform as it is a methodology.
If one can imagine, besides...]]></description><link>https://codecogniz.com/package-managers</link><guid isPermaLink="true">https://codecogniz.com/package-managers</guid><category><![CDATA[package manager]]></category><category><![CDATA[yum]]></category><category><![CDATA[npm]]></category><category><![CDATA[Yarn]]></category><category><![CDATA[Package Managers]]></category><dc:creator><![CDATA[Rajesh Tatavarthy]]></dc:creator><pubDate>Sat, 27 Aug 2022 07:52:43 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1661714064232/9U0P5y0Aj.jpg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h1 id="heading-package-managers"><p>Package Managers</p></h1>
<p><em><code>Sometimes…, Front End engineering seems more complicated but there is alot to explore besides ever changing technologies. Moreover, it is not dependent on any technology or platform as it is a methodology.</code></em></p>
<p>If one can imagine, besides traditional technologies, JavaScript has been in existence and evolving like a parallel world. It is everywhere and still unfolding day by day.</p>
<p>Nowadays, the words like packages, dependencies, modules, bundles are very popular in modern javascript. To understand these terms, we have to look at modules first. What are they about…! </p>
<h3 id="heading-modules">Modules</h3>
<p>Simply saying, a module is a discrete block of code that can be exported from one file and imported in another file. Every item in a module like variables, functions, objects etc can be exported individually. This approach gives more control over complex functionality. In other words, it is called <em> modular programming </em> .</p>
<p><em> <code>A well defined module comprises of a properly encapsulated unified structure which can have a clear functionality written that supports the overall application or a part of it.</code> </em></p>
<p>Those who are working with modern JavaScript technologies like React, Angular, Vue, NodeJS etc., use modules knowingly or unknowingly. As mentioned, modules can be exported with a built-in keyword in javascript called <em> <code>export</code> </em>.</p>
<p>They can be imported in 2 different ways:<br />
ES5 standard</p>
<pre><code><span class="hljs-built_in">require</span>(‘......’);
</code></pre><p>ES6 standard</p>
<pre><code><span class="hljs-keyword">import</span> <span class="hljs-operator">&lt;</span> <span class="hljs-title">___</span> <span class="hljs-operator">&gt;</span> <span class="hljs-title"><span class="hljs-keyword">from</span></span> ‘ .<span class="hljs-operator">/</span><span class="hljs-operator">&lt;</span> <span class="hljs-title">___</span> <span class="hljs-operator">&gt;</span> ’ ;
</code></pre><iframe src="https://codesandbox.io/embed/thirsty-frog-hmi382?fontsize=14&amp;hidenavigation=1&amp;theme=dark" style="width:100%;height:500px;border:0;border-radius:4px;overflow:hidden" sandbox="allow-forms allow-modals allow-popups allow-presentation allow-same-origin allow-scripts"></iframe>

<h3 id="heading-early-days">Early days</h3>
<p>Now, to have a clear idea of Package Managers, first we have to know why they are important in today’s world. When we go through the backstory of package managers, it seems that they are not new. During the early days of Linux and Unix, software downloading and installation was held using FTP or through some kind of data source. To get rid of this process further, Linux and Unix operating systems first introduced the practice of Centralised Systems like those we are using in these modern days, for example npm. That centralised system is completely based on GNU. </p>
<p>GNU means ‘GNU is not Unix’. It is a recursive acronym. It means, it refers to itself, where ‘G’ is silent. 
GNU consists of many tools and services used for different purposes with broad usage in the field of software. It holds different components of toolchains which are often used to develop applications and to write operating systems. And often GNU is referred to as “an Operating System that is free software “. </p>
<p>In fact, the Linux operating system is a combination of GNU software and Linux kernel. That’s why they call it GNU/Linux. Ofcourse, there are different flavours of Linux intended for varying purposes.</p>
<p>With the practice of centralised systems, tar files were used to pack the software setup files and to distribute them. In fact, the first versions of tar files are not compressed files or folders. They are just like a collection of files together. In other words, a tar file is an archive of files. Those files can be unarchived / untar to extract the necessary files. ‘Configure’ scripts can be initialised using GCC (GNU Compiler Collection) or with some variant of C compilers. Those scripts (./configure) will set up the software besides inspecting the application for dependencies. If any required dependencies are missing, the script would not allow the installation process to proceed further until those requirements are fulfilled. </p>
<h3 id="heading-dll-hell">dll Hell</h3>
<p>On the other hand, once the process is done successfully it creates a file called ‘makefile’. This file can be accessed with the help of ‘make’ command which actually instals the software. ‘Make’ is a utility tool which maintains and manages various components of system programs. When the make command is used in the terminal, it reads instructions inside Makefile where different rules for dependency, macros etc., were defined. And it automates complex tasks like software builds, dependencies to execute in the shell etc.</p>
<p>This process results in creating binary files which is crucial in order to maintain hardware compatibility with the upcoming software requirements. But this whole process is annoying, troublesome and takes a lot of time to complete. Imagine how tedious it is to update an installed software in a system. In operating systems like Windows, this kind of complexity was termed as <em>DLL (Dynamic Link Library) HELL</em>.</p>
<h3 id="heading-inception-of-package-managers">Inception of Package Managers</h3>
<p>This is where the Package Management System comes into play to overcome such complexities of early days software installation and development. </p>
<p>A Package consists of:</p>
<ul>
<li><p>Compressed files </p>
</li>
<li><p>Precompiled binary files</p>
</li>
<li><p>Metadata ( <em> like author’s name, description, version number, licence, vendor, cryptographic information etc </em> )</p>
</li>
<li><p>List of dependencies (used to install the software without any hurdles)</p>
</li>
</ul>
<p>By the way, a package is not responsible for maintaining those dependencies. </p>
<p>Package managers are widely accepted throughout the world consistently and have improved a lot.
With the help of a package, it is easy to install, configure, update or remove software. Now such tasks have become as simple and fun as eating peanuts. This system of package managers eliminates manual installation processes and complexities like <em>DLL HELL</em> .</p>
<h3 id="heading-in-existence">In Existence</h3>
<p>Have a look at different package managers from various platforms:</p>
<p>Most of the following package managers are command-line utilities. Even though the purpose of their usage is the same, they differ in their features that are based on the platform they work with.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1661720067020/XS_KP2HjM.png" alt="rpm-logo.png" /></p>
<h4 id="heading-redhat-package-manager"><em> RedHat Package Manager</em> <br /></h4>
<ul>
<li>It is intended for Linux distributions.</li>
<li>It has its own database of packages’ information.</li>
<li>It has file formats with .rpm extension.</li>
</ul>
<blockquote>
<p><em> Syntax: </em></p>
<pre><code><span class="hljs-selector-tag">rpm</span> <span class="hljs-selector-attr">[option]</span> <span class="hljs-selector-attr">[package_name]</span>
</code></pre><p>  <em> Eg: </em></p>
<pre><code><span class="hljs-attribute">rpm</span> -ivh thunderbird-<span class="hljs-number">78</span>.<span class="hljs-number">6</span>.<span class="hljs-number">1</span>-<span class="hljs-number">1</span>.el<span class="hljs-number">7</span>.centos.x<span class="hljs-number">86</span>_<span class="hljs-number">64</span>.rpm
<span class="hljs-attribute">rpm</span> -qa
<span class="hljs-attribute">rpm</span> –help
</code></pre></blockquote>
<hr />
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1661720163012/iT23OFSKs.png" alt="yumpm-logo.png" /></p>
<h4 id="heading-yellowdog-updater-modified"><em> Yellowdog Updater Modified </em></h4>
<ul>
<li>It works on Linux.</li>
<li>It is a front-end utility package manager that works on RPM.</li>
<li>It has its own database of packages’ information.</li>
</ul>
<blockquote>
<p> <em> Syntax: </em></p>
<pre><code><span class="hljs-selector-tag">yum</span> <span class="hljs-selector-attr">[options]</span> <span class="hljs-selector-attr">[command]</span> <span class="hljs-selector-attr">[package]</span>
</code></pre><p> <em> Eg: </em></p>
<pre><code>yum -y <span class="hljs-keyword">install</span> thunderbird
yum -y remove thunderbird
yum <span class="hljs-keyword">install</span> dos2unix
yum <span class="hljs-keyword">search</span> <span class="hljs-keyword">all</span>
yum <span class="hljs-keyword">list</span> <span class="hljs-keyword">all</span>
yum <span class="hljs-keyword">help</span>
</code></pre></blockquote>
<hr />
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1661720203819/VbZVnVMVH.png" alt="npm-logo.png" /></p>
<h4 id="heading-node-package-manager"><em> Node Package Manager </em></h4>
<blockquote>
<p>It works on the NodeJS runtime environment.
It is the world’s largest registry with over 1 million packages and 11 million developers worldwide.</p>
<p> <em> Syntax: </em></p>
<pre><code><span class="hljs-selector-tag">npm</span> <span class="hljs-selector-attr">[options]</span> <span class="hljs-selector-attr">[command]</span> <span class="hljs-selector-attr">[package]</span>
</code></pre><p> <em> Eg: </em></p>
<pre><code>npm install create<span class="hljs-operator">-</span>react<span class="hljs-operator">-</span>app
npm install axios
npm i react<span class="hljs-operator">-</span>router<span class="hljs-operator">-</span>dom@<span class="hljs-number">6</span>
npm audit fix
npm <span class="hljs-operator">-</span><span class="hljs-operator">-</span>version
</code></pre></blockquote>
<hr />
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1661720245188/RS5lBc_Sb.png" alt="yarn-logo.png" /></p>
<h4 id="heading-it-is-just-a-brand-name"><em> It is just a brand name.  </em></h4>
<p>The developer of YARN stated that he thought of its name as KPM (Kittens Package Manager).</p>
<ul>
<li>But they named it so to create a unique brand.</li>
<li>It has Caching mechanism, Checksum of packages, Workspaces which aims at Monorepos.</li>
</ul>
<p><em> <code>NPM and YARN are widely used in NodeJS Environments</code> </em></p>
<blockquote>
<p> <em> Syntax: </em></p>
<pre><code><span class="hljs-selector-tag">yarn</span> <span class="hljs-selector-attr">[options]</span> <span class="hljs-selector-attr">[command]</span> <span class="hljs-selector-attr">[package]</span>
</code></pre><p> <em> Eg: </em></p>
<pre><code>yarn add <span class="hljs-keyword">create</span>-react-app
yarn <span class="hljs-keyword">add</span> axios
yarn <span class="hljs-keyword">add</span> react-router-dom@<span class="hljs-number">6</span>
yarn <span class="hljs-keyword">audit</span> –<span class="hljs-keyword">groups</span> dependencies
yarn <span class="hljs-keyword">help</span>
yarn <span class="hljs-keyword">version</span>
</code></pre></blockquote>
<hr />
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1661720405970/uJpXDuWat.jpg" alt="pnpm-logo.jpg" /></p>
<h3 id="heading-pnpm">pnpm</h3>
<h4 id="heading-performant-node-package-manager"><em> Performant Node Package Manager </em></h4>
<ul>
<li>It has monorepo support.</li>
<li>It creates hard links in the global space of the system with reference to every package in the node_modules folder of the project’s local space. Hard links are references of a file like pointers. They do not occupy extra space in the system’s memory unlike files and folders do.</li>
<li>In the case of Windows Operating System, pnpm uses junctions (soft links) to create a dependency tree of the packages.</li>
</ul>
<blockquote>
<p> <em> Syntax: </em></p>
<pre><code><span class="hljs-selector-tag">pnpm</span> <span class="hljs-selector-attr">[command]</span> <span class="hljs-selector-attr">[option]</span> <span class="hljs-selector-attr">[package]</span>
</code></pre><p> <em> Eg: </em></p>
<pre><code>pnpm <span class="hljs-keyword">create</span> react-app
pnpm <span class="hljs-keyword">link</span> <span class="hljs-comment">--global</span>
pnpm <span class="hljs-keyword">link</span> <span class="hljs-comment">--global dependencies</span>
pnpm exec jest
</code></pre></blockquote>
<p><em> <code>Both NPM and PNPM deal with Dependency Tree Structures.</code> </em></p>
<hr />
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1661720563294/8CT5cKHwE.png" alt="homebrew-logo.png" /></p>
<h3 id="heading-homebrew">HOMEBREW</h3>
<h4 id="heading-macos-and-linux-based-package-manager"><em> macOS and Linux based package manager </em></h4>
<ul>
<li>First, It instals packages and it symlinks them to /usr/local directory on macOS.</li>
<li>Here, in cli formulae are used which are nothing but packages and scripts.</li>
</ul>
<blockquote>
<p> <em> Syntax: </em></p>
<pre><code>brew <span class="hljs-operator">&lt;</span>command<span class="hljs-operator">&gt;</span> [<span class="hljs-operator">-</span><span class="hljs-operator">-</span>verbose<span class="hljs-operator">|</span><span class="hljs-operator">-</span>v] [options] [formula]
</code></pre><p> <em> Eg: </em></p>
<pre><code>brew <span class="hljs-keyword">install</span> node
brew <span class="hljs-keyword">list</span>
brew doctor
brew <span class="hljs-keyword">help</span>
brew <span class="hljs-comment">--version</span>
</code></pre></blockquote>
<hr />
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1661720751247/J4XEnEMU7.jpg" alt="chocolatey-logo.jpg" /></p>
<h4 id="heading-windows-based-package-manager"><em> Windows based package manager </em></h4>
<ul>
<li>It works with powershell.</li>
<li>Here, packages encapsulate all necessary files into a single unit of artefact that is suitable for deployment.</li>
<li>Such a collection consists of installers, executable files, zipped / compressed files and scripts compiled into a package.</li>
<li>Compiled packages have an automatic virus scanning system to strictly block malicious and pirated software or attacks.</li>
</ul>
<blockquote>
<p> <em> Syntax: </em></p>
<pre><code><span class="hljs-selector-tag">choco</span> &lt;<span class="hljs-selector-tag">command</span>&gt; <span class="hljs-selector-attr">[package]</span> <span class="hljs-selector-attr">[options]</span>
</code></pre><p> <em> Eg: </em></p>
<pre><code>choco <span class="hljs-keyword">install</span> nodejs -y
choco <span class="hljs-keyword">install</span> sysinternals
choco <span class="hljs-keyword">install</span> ruby
choco <span class="hljs-keyword">uninstall</span> ruby
choco <span class="hljs-keyword">help</span>
choco -?
</code></pre><p><code>choco -?</code>  <em> It is a general help command, same as choco -help. </em></p>
</blockquote>
<hr />
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1661720872189/9vwUF46K9.jpg" alt="pip-logo.jpg" /></p>
<h3 id="heading-pip">PIP</h3>
<h4 id="heading-pip-installs-packages-it-is-an-acronym"><em> Pip Installs Packages. It is an acronym. </em></h4>
<ul>
<li>It works in a Python environment. And it is independent of system interpreter.</li>
</ul>
<blockquote>
<p> <em> Syntax: </em></p>
<pre><code><span class="hljs-selector-tag">pip</span> &lt;<span class="hljs-selector-tag">command</span>&gt; <span class="hljs-selector-attr">[package]</span> <span class="hljs-selector-attr">[options]</span>
</code></pre><p> <em> Eg: </em></p>
<pre><code>pip <span class="hljs-keyword">install</span> Django
pip <span class="hljs-keyword">install</span> flask-bootstrap
pip <span class="hljs-keyword">list</span>
pip <span class="hljs-comment">--version</span>
</code></pre></blockquote>
<hr />
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1661720906761/0xg77Rk8y.png" alt="gradle-logo.png" /></p>
<h3 id="heading-gradle">Gradle</h3>
<h4 id="heading-works-on-different-platforms"><em> Works on different platforms </em></h4>
<ul>
<li>It is used for build automation.</li>
<li>It is highly customizable and powerful with a rich ecosystem of APIs and plugins.</li>
</ul>
<blockquote>
<p> <em> Syntax: </em></p>
<pre><code>gradle [taskName...] [<span class="hljs-operator">-</span><span class="hljs-operator">-</span>option<span class="hljs-operator">-</span>name...]
</code></pre><p> <em> Eg: </em></p>
<pre><code>gradle test deploy
gradle dist <span class="hljs-operator">-</span><span class="hljs-operator">-</span>exclude<span class="hljs-operator">-</span>task test
gradle tasks <span class="hljs-operator">-</span><span class="hljs-operator">-</span>group<span class="hljs-operator">=</span><span class="hljs-string">"build setup"</span>
gradle <span class="hljs-operator">-</span>q help –task libs
gradle <span class="hljs-operator">-</span><span class="hljs-operator">-</span>help
</code></pre></blockquote>
<hr />
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1661720945024/LyaOVz5ABr.png" alt="maven-logo.png" /></p>
<h4 id="heading-apache-maven"><em> Apache Maven </em></h4>
<ul>
<li>It is used for Java Projects to deal with build automation processes.</li>
<li>It deals with project builds, reporting and documentation from its centralised ecosystem.</li>
</ul>
<blockquote>
<p> <em> Syntax: </em></p>
<pre><code><span class="hljs-selector-tag">mvn</span> <span class="hljs-selector-attr">[options]</span>:&lt;<span class="hljs-selector-tag">command</span>&gt; <span class="hljs-selector-attr">[options]</span> <span class="hljs-selector-attr">[options]</span>...
</code></pre><p> <em> Eg: </em></p>
<pre><code>mvn <span class="hljs-keyword">install</span>
mvn <span class="hljs-keyword">package</span>
mvn compiler:compile
mvn dependency:tree
mvn deploy
mvn clean
mvn <span class="hljs-keyword">verify</span>
mvn archetype:generate
mvn <span class="hljs-comment">--version</span>
</code></pre></blockquote>
<hr />
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1661721030200/t1TNiJ67y.jpg" alt="nuget-logo.jpg" /></p>
<h4 id="heading-used-to-create-net-apps"><em> Used to create .NET Apps </em></h4>
<ul>
<li>It distributes .NET libraries and these libraries are called packages.</li>
<li>It has more than 297,210 packages as of today.</li>
</ul>
<blockquote>
<p> <em> Syntax: </em></p>
<pre><code>nuget sources <span class="hljs-operator">&lt;</span>operation<span class="hljs-operator">&gt;</span> <span class="hljs-operator">-</span>Name <span class="hljs-operator">&lt;</span>name<span class="hljs-operator">&gt;</span> <span class="hljs-operator">-</span>Source <span class="hljs-operator">&lt;</span>source<span class="hljs-operator">&gt;</span>
</code></pre><p> <em> Eg: </em></p>
<pre><code>nuget install packages.config
nuget config <span class="hljs-operator">-</span>Set repositoryPath<span class="hljs-operator">=</span>c:\packages <span class="hljs-operator">-</span>configfile c:\my.config
nuget list
nuget <span class="hljs-operator">-</span>help
</code></pre></blockquote>
<hr />
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1661721199437/cUBwMgKN5.png" alt="Debian-logo.png" /></p>
<h3 id="heading-apt">APT</h3>
<h4 id="heading-advanced-packaging-tool"><em> Advanced Packaging Tool </em></h4>
<ul>
<li>It is Ubuntu’s package management system.</li>
<li>Based on Debian GNU-Linux distribution.</li>
</ul>
<blockquote>
<p> <em> Syntax: </em></p>
<pre><code><span class="hljs-selector-tag">apt</span> &lt;<span class="hljs-selector-tag">command</span>&gt; <span class="hljs-selector-attr">[package_name]</span> <span class="hljs-selector-attr">[options]</span>
</code></pre><p> <em> Eg: </em></p>
<pre><code>sudo apt install vim
sudo apt install <span class="hljs-operator">/</span>full<span class="hljs-operator">/</span>path<span class="hljs-operator">/</span>file.deb
sudo apt list
sudo apt <span class="hljs-operator">-</span><span class="hljs-operator">-</span>help
</code></pre></blockquote>
<hr />
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1661721280802/RasbwKbOF.jpg" alt="Steam-logo.jpg" /></p>
<h3 id="heading-steam">Steam</h3>
<h4 id="heading-based-on-debian-distribution"><em> Based on Debian distribution </em></h4>
<ul>
<li>It has official support from GNU/Linux.</li>
<li>It is widely used as an application launcher for Video Games and other creative tools / assets.</li>
</ul>
<blockquote>
<p> <em> Syntax: </em></p>
<pre><code>steam [-<span class="hljs-keyword">options</span>]
</code></pre><p> <em> Eg: </em></p>
<pre><code>steam <span class="hljs-operator">-</span>console
steam <span class="hljs-operator">-</span>tenfoot
steam steam:<span class="hljs-comment">//open/console</span>
steam <span class="hljs-operator">-</span>shutdown
</code></pre></blockquote>
<hr />
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1661721458049/Ubl1bWPuP.png" alt="winehq-logo.png" /></p>
<h3 id="heading-wine">Wine</h3>
<h4 id="heading-wine-is-not-an-emulator-it-is-an-acronym"><em> Wine is not an Emulator - it is an acronym </em></h4>
<ul>
<li>It runs on operating systems that support POSIX (Portable Operating System Interface)</li>
<li>It converts API calls into POSIX calls to run Windows Applications efficiently in the Desktop.</li>
</ul>
<blockquote>
<p> <em> Syntax: </em></p>
<pre><code><span class="hljs-selector-tag">wine</span> <span class="hljs-selector-tag">program</span> <span class="hljs-selector-attr">[argument1]</span> <span class="hljs-selector-attr">[argument2]</span> ……
</code></pre><p> <em> Eg: </em></p>
<pre><code>wine winecfg
wine [ipconfig] [<span class="hljs-operator">/</span>all]
wine msiexec <span class="hljs-operator">/</span>i <span class="hljs-operator">&lt;</span>filename<span class="hljs-operator">&gt;</span>.msi
wine <span class="hljs-operator">-</span><span class="hljs-operator">-</span>help
wine <span class="hljs-operator">-</span><span class="hljs-operator">-</span>version
</code></pre></blockquote>
<p><em> Package Managers have been gradually improved since their inception. Nowadays, they are used to automate different processes in the project pipeline. </em></p>
<h4 id="heading-this-is-a-brief-introduction-about-package-managers">This is a brief introduction about Package Managers</h4>
<p><em> …keep an eye for the next article on Webpack. </em></p>
]]></content:encoded></item><item><title><![CDATA[Styled Components]]></title><description><![CDATA[STYLED COMPONENTS
A lot happens with the modern CSS and JS 
A Styled Component is the combination of a DOM element and the rules that can style it.

In today’s JavaScript era, words like modules, components, functions, bundlers, transpliers, etc., ar...]]></description><link>https://codecogniz.com/styled-components</link><guid isPermaLink="true">https://codecogniz.com/styled-components</guid><category><![CDATA[styled-components]]></category><category><![CDATA[CSS]]></category><category><![CDATA[CSS in JS]]></category><category><![CDATA[components]]></category><category><![CDATA[dynamic css]]></category><dc:creator><![CDATA[Rajesh Tatavarthy]]></dc:creator><pubDate>Sat, 13 Aug 2022 05:38:16 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1660411978797/KYhoFmBfm.jpg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h1 id="heading-styled-components"><p>STYLED COMPONENTS</p></h1>
<h6 id="heading-a-lot-happens-with-the-modern-css-and-js"><em><p>A lot happens with the modern CSS and JS </p></em></h6>
<p><code>A Styled Component is the combination of a DOM element and the rules that can style it.</code>
<br /><br />
In today’s JavaScript era, words like modules, components, functions, bundlers, transpliers, etc., are very popular and used widely. Components are very useful to develop scalable systems. An interesting feature that makes Styled Components more powerful is, CSS styles can be maintained as Components that can be reused at ease.</p>
<h3 id="heading-a-component">A Component</h3>
<p>A Component is a popular term in the JavaScript World. 
Developers love to reuse their code whenever necessary instead of taking all pain to write it again. Component based Architectures are the robust way to solve a lot of issues in front-end engineering. Like native web components, a user defined css component is also possible but with a slightly different approach and with JavaScript/ES6 combination makes it possible.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1660383799098/JmTNYJNbL.jpg" alt="1-Components-updated.jpg" /></p>
<p>Usually, a Component is a file with .js extension. A Class or a Function that can return something can behave like a component. </p>
<p>Now-a-days, CSSinJS is a popular term for components styling web elements and also for various other useful features.</p>
<h3 id="heading-styled-components">Styled-Components</h3>
<p>Styled-components is a library that makes the best use of CSS to style the Component based systems like React / ReactNative. ES6 standards play an important role in this aspect.
The best part is we can use transpilers like Babel to make efficient use of this library.
On the other hand, styled-components can be used easily along with other libraries. </p>
<h3 id="heading-easy-of-use-installation">Easy of use - Installation</h3>
<p>First of all, like any other node based library or a framework, styled-components can be installed using npm or yarn. Use the following command in your terminal or CLI :</p>
<pre><code>npm install <span class="hljs-operator">-</span><span class="hljs-operator">-</span>save styled<span class="hljs-operator">-</span>components
</code></pre><pre><code>yarn <span class="hljs-keyword">add</span> styled-components
</code></pre><h3 id="heading-css-components-the-basics">CSS Components - the Basics</h3>
<p>A Component is a code block that is wrapped with a reference name and can be reused. A CSS Component is a block of styles defined and can be reused in the form of a component which is a very flexible way to reduce the number of lines of css code.</p>
<h3 id="heading-building-design-systems">Building Design Systems</h3>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1660383870745/fbgc1hV9y.jpg" alt="2-DesignSystems-updated.jpg" />
Building a design system is one of the sophisticated approaches to foresee and solve many problems in the Front End Architecture of a Scalable System. Such design systems can easily be used among various groups of designers and developers at no extra effort. A Design System plays a vital role in creating a better user experience and Styled Components comprise of many distinct features to create such a sophisticated system.</p>
<h3 id="heading-cssinjs">CSSinJS</h3>
<p>The way of css styling web elements with JavaScript/es6 support takes css standards to the next level. This approach is very feasible for developers to use and to implement it in scalable products. </p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1660383880875/F9dfbwI1UD.jpg" alt="3-CSSinJS-updated.jpg" /></p>
<p>In general, CSS in JS refers to dynamic css, server side rendering, auto vendor fixes etc. Styled Components have features that cover everything of CSSinJS and moreover it gives you a feel of ReactJS.</p>
<h3 id="heading-props-play-major-role">Props play major role</h3>
<p>Props / properties are nothing but arbitrary inputs of Components. These are helpful to create intuitive theming of components and developers can use them to enable dynamic styling of CSS. Furthermore, props can also be passed conditionally to a component.
Like in react, props are available in styled components as well.
<img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1660386148455/qwDI5ifzM.jpg" alt="4-Props-updated.jpg" />
<br />
<em>Code Sample:</em><br />
<em><strong>Styles.js</strong></em> --&gt; <br /></p>
<pre><code><span class="hljs-keyword">import</span> <span class="hljs-title">styled</span> <span class="hljs-title"><span class="hljs-keyword">from</span></span> <span class="hljs-string">"styled-components"</span>;

export const MsgText <span class="hljs-operator">=</span> styled.div`
 color: ${(props) <span class="hljs-operator">=</span><span class="hljs-operator">&gt;</span> (props.danger ? <span class="hljs-string">"#db0000"</span> : <span class="hljs-string">"#04a134"</span>)};
 font<span class="hljs-operator">-</span>size: 20px;
`;
</code></pre><p><em><strong>App.js</strong></em> --&gt; <br /></p>
<pre><code><span class="hljs-operator">&lt;</span>MsgText danger<span class="hljs-operator">&gt;</span> You are not authorised to edit page...! <span class="hljs-operator">&lt;</span><span class="hljs-operator">/</span>MsgText<span class="hljs-operator">&gt;</span>
       <span class="hljs-operator">&lt;</span>br <span class="hljs-operator">/</span><span class="hljs-operator">&gt;</span>
<span class="hljs-operator">&lt;</span>MsgText<span class="hljs-operator">&gt;</span> But you can <span class="hljs-keyword">view</span> it. &lt;<span class="hljs-operator">/</span>MsgText<span class="hljs-operator">&gt;</span>
</code></pre><h3 id="heading-conditioning-styles">Conditioning Styles</h3>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1660386167869/R4zp2M8Fn.jpg" alt="5-Conditions-updated.jpg" /></p>
<p>While passing props to a styled component, conditions can be added based on which the output(styling) of that component changes when rendered in DOM.
Using a ternary operator is the best and shortest way to add conditions to props’ values as shown in the image below: </p>
<h3 id="heading-flexible-css-components-extend-override">Flexible CSS Components (Extend / Override)</h3>
<p>Unlike normal css, styled components allow us to inherit styles from another. There is a constructor called styled( )which makes inheritance possible.
<br />
<img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1660386197540/0jL-JPCNI.jpg" alt="6-Extend-Overide-updated.jpg" />
<br />
<em>Code Sample:</em><br />
<em><strong>Styles.js</strong></em> --&gt; <br /></p>
<pre><code><span class="hljs-keyword">import</span> <span class="hljs-title">styled</span> <span class="hljs-title"><span class="hljs-keyword">from</span></span> <span class="hljs-string">"styled-components"</span>;
export const MsgText <span class="hljs-operator">=</span> styled.div`
 color: ${(props) <span class="hljs-operator">=</span><span class="hljs-operator">&gt;</span> (props.danger ? <span class="hljs-string">"#db0000"</span> : <span class="hljs-string">"#04a134"</span>)};
 font<span class="hljs-operator">-</span>size: 20px;
`;

export const MsgGhost <span class="hljs-operator">=</span> styled(MsgText)`
color: ${(props) <span class="hljs-operator">=</span><span class="hljs-operator">&gt;</span> (props.restricted ? <span class="hljs-string">"#adadad"</span> : <span class="hljs-string">"#8b8b8b"</span>)};
`;
</code></pre><p><em><strong>App.js</strong></em> --&gt; <br /></p>
<pre><code><span class="hljs-operator">&lt;</span>MsgText<span class="hljs-operator">&gt;</span> You can <span class="hljs-keyword">view</span> it. &lt;<span class="hljs-operator">/</span>MsgText<span class="hljs-operator">&gt;</span>
<span class="hljs-operator">&lt;</span>MsgGhost restricted<span class="hljs-operator">&gt;</span>This <span class="hljs-keyword">is</span> Admin<span class="hljs-string">'s Block.&lt;/MsgGhost&gt;</span>
</code></pre><p>Without disturbing the existing ones, overriding styles seems easy to use with the help of props. As shown in the above code sample, the styled( ) constructor modifies color property in MsgGhost that was inherited from MsgText and overrides its values with some props and conditions. Now, MsgGhost has updated color value and inherited font-size. 
<br />
<strong>Eg:</strong> <br /></p>
<iframe src="https://codesandbox.io/embed/styledcomponents-props-conditions-extend-override-qcsdn?fontsize=14&amp;hidenavigation=1&amp;theme=dark" style="width:100%;height:500px;border:0;border-radius:4px;overflow:hidden" sandbox="allow-forms allow-modals allow-popups allow-presentation allow-same-origin allow-scripts"></iframe>

<h3 id="heading-pseudo-selectors">Pseudo Selectors</h3>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1660388460875/do-5R_sIj.jpg" alt="8-SelectorPseudo-updated.jpg" /></p>
<p>Besides Sass and Less, Stylis is a light-weight css preprocessor. Styled Components library uses it to adapt nested styling, selector patterns etc.
‘&amp;’ character makes different selector patterns possible, for example:</p>
<pre><code><span class="hljs-keyword">import</span> <span class="hljs-title">styled</span> <span class="hljs-title"><span class="hljs-keyword">from</span></span> <span class="hljs-string">"styled-components"</span>;
export const Input <span class="hljs-operator">=</span> styled.input`
color:green;
<span class="hljs-operator">&amp;</span>:hover { 
color:red; 
}
`;
</code></pre><p>In this code, &amp;:hover represents the styles applied on hover of the input element. Similarly, we can make use of different selector patterns like we use in normal css, such as <br />
&amp;:focus <br /> &amp; + &amp; <br /> &amp; ~ &amp; <br /> &amp;.classname <br /> &amp;#id <br /> ...to mention a few.</p>
<h3 id="heading-create-animations">Create Animations</h3>
<p>‘Keyframes’ play an important role animating objects on DOM whether it is core css or any library/framework. It is the same case with Styled Components as well. </p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1660388672768/ge_-Rn2mX.jpg" alt="9-Keyframes-updated.jpg" /></p>
<p>Combining keyframes with attributes binding features allow us to create a number of various interesting animations on the Web. Any css property can be animated except those who have boolean values. In particular, css properties whose values vary in a particular range instead of fixed values, can be animated to get nice visual appeal.
<em>Code Sample:</em><br />
<em><strong>Styles.js</strong></em> --&gt; <br /></p>
<pre><code><span class="hljs-string">import</span> <span class="hljs-string">styled</span> <span class="hljs-string">from</span> <span class="hljs-string">"styled-components"</span><span class="hljs-string">;</span>

<span class="hljs-string">const</span> <span class="hljs-string">blinkText</span> <span class="hljs-string">=</span> <span class="hljs-string">keyframes`</span>
 <span class="hljs-number">0</span><span class="hljs-string">%{color:rgba(9,113,241,1)}</span>
 <span class="hljs-number">25</span><span class="hljs-string">%{color:rgba(9,241,38,1)}</span>
 <span class="hljs-number">50</span><span class="hljs-string">%{color:rgb(241,137,9,1)}</span>
 <span class="hljs-number">100</span><span class="hljs-string">%{color:rgba(9,113,241,1)}</span>
<span class="hljs-string">`;</span>
<span class="hljs-string">export</span> <span class="hljs-string">const</span> <span class="hljs-string">AnimTextC</span> <span class="hljs-string">=</span> <span class="hljs-string">styled.div`</span>
 <span class="hljs-attr">font-size:</span> <span class="hljs-string">30px;</span>
 <span class="hljs-attr">line-height:</span> <span class="hljs-string">70px;</span>
 <span class="hljs-attr">font-weight:</span> <span class="hljs-string">bold;</span>
 <span class="hljs-attr">max-width:</span> <span class="hljs-string">800px;</span>
 <span class="hljs-attr">margin:</span> <span class="hljs-string">auto;</span>
 <span class="hljs-attr">border:</span> <span class="hljs-string">2px</span> <span class="hljs-string">dotted</span> <span class="hljs-comment">#e5e5e5;</span>
 <span class="hljs-attr">animation:</span> <span class="hljs-string">${blinkText}</span> <span class="hljs-string">2s</span> <span class="hljs-string">ease</span> <span class="hljs-string">infinite;</span>
<span class="hljs-string">`;</span>
</code></pre><p><em><strong>App.js</strong></em> --&gt; <br /></p>
<pre><code><span class="hljs-keyword">import</span> { <span class="hljs-title">AnimTextC</span> } <span class="hljs-title"><span class="hljs-keyword">from</span></span> <span class="hljs-string">"./styles.js"</span>;
export default <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">App</span>(<span class="hljs-params"></span>) </span>{
 <span class="hljs-keyword">return</span> (
    <span class="hljs-operator">&lt;</span>div className<span class="hljs-operator">=</span><span class="hljs-string">"App"</span><span class="hljs-operator">&gt;</span>
        <span class="hljs-operator">&lt;</span>AnimTextC<span class="hljs-operator">&gt;</span>Text Viz<span class="hljs-operator">&lt;</span><span class="hljs-operator">/</span>AnimTextC<span class="hljs-operator">&gt;</span>
    <span class="hljs-operator">&lt;</span><span class="hljs-operator">/</span>div<span class="hljs-operator">&gt;</span>
)
}
</code></pre><p><br />
<strong>Eg:</strong> <br /></p>
<iframe src="https://codesandbox.io/embed/styledcomponents-keyframesandattributes-n954z?fontsize=14&amp;hidenavigation=1&amp;theme=dark" style="width:100%;height:500px;border:0;border-radius:4px;overflow:hidden" sandbox="allow-forms allow-modals allow-popups allow-presentation allow-same-origin allow-scripts"></iframe>

<h3 id="heading-theming">Theming</h3>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1660389076522/3nTXKjaS7.jpg" alt="11-Theming-updated.jpg" />
Styled Components have huge support for theming UI Layers. It is easy to use and it reduces repetitive styles. It can be done using a specific wrapper to theme a UI and can be reused and customised with no time.  is a wrapper component to wrap UI with themes. For example,  <br />
<em><strong>App.js</strong></em></p>
<pre><code><span class="hljs-keyword">import</span> { <span class="hljs-title">ThemeProvider</span> } <span class="hljs-title"><span class="hljs-keyword">from</span></span> <span class="hljs-string">"styled-components"</span>;

const cyanTheme <span class="hljs-operator">=</span> {
 regular: <span class="hljs-string">"#588a93"</span>, hover: <span class="hljs-string">"#31808f"</span>
};
const brownTheme <span class="hljs-operator">=</span> {
 regular: <span class="hljs-string">"#816c6c"</span>, hover: <span class="hljs-string">"#5e4848"</span>
};

<span class="hljs-operator">&lt;</span>ThemeProvider theme<span class="hljs-operator">=</span>{cyanTheme}<span class="hljs-operator">&gt;</span>
    <span class="hljs-operator">&lt;</span>form<span class="hljs-operator">&gt;</span>
             <span class="hljs-operator">&lt;</span>div className<span class="hljs-operator">=</span>”title”<span class="hljs-operator">&gt;</span>Fill the details<span class="hljs-operator">&lt;</span><span class="hljs-operator">/</span>div<span class="hljs-operator">&gt;</span>
              ……. …. .. ..     
    <span class="hljs-operator">&lt;</span><span class="hljs-operator">/</span>form<span class="hljs-operator">&gt;</span>
<span class="hljs-operator">&lt;</span><span class="hljs-operator">/</span>ThemeProvider<span class="hljs-operator">&gt;</span>
<span class="hljs-operator">&lt;</span>ThemeProvider theme<span class="hljs-operator">=</span>{brownTheme}<span class="hljs-operator">&gt;</span>
    <span class="hljs-operator">&lt;</span>form<span class="hljs-operator">&gt;</span>
             <span class="hljs-operator">&lt;</span>div className<span class="hljs-operator">=</span>”title”<span class="hljs-operator">&gt;</span>Fill the details<span class="hljs-operator">&lt;</span><span class="hljs-operator">/</span>div<span class="hljs-operator">&gt;</span>
             ……. …. .. .. 
     <span class="hljs-operator">&lt;</span><span class="hljs-operator">/</span>form<span class="hljs-operator">&gt;</span>
<span class="hljs-operator">&lt;</span><span class="hljs-operator">/</span>ThemeProvider<span class="hljs-operator">&gt;</span>
</code></pre><p><em><strong>Styles.js</strong></em> <br /></p>
<pre><code>.title { color: ${(props) <span class="hljs-operator">=</span><span class="hljs-operator">&gt;</span> props.theme.regular}; }
</code></pre><p><strong>Eg:</strong> <br /></p>
<iframe src="https://codesandbox.io/embed/styledcomponents-theming-okg1c?fontsize=14&amp;hidenavigation=1&amp;theme=dark" style="width:100%;height:500px;border:0;border-radius:4px;overflow:hidden" sandbox="allow-forms allow-modals allow-popups allow-presentation allow-same-origin allow-scripts"></iframe>


<h3 id="heading-attributes">Attributes</h3>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1660403961236/NnqBQhp83.jpg" alt="10-Attr-updated.jpg" />
The Styled Components library provides us the right way to decorate a component and make it more dynamic yet simple to use. 
 .attrs( ) constructor is available that can do all the work. This kind of approach is more useful for scalable projects instead of the smaller ones. Have a look at a sample code:</p>
<pre><code>const Anchor <span class="hljs-operator">=</span> styled.a.attrs((props) <span class="hljs-operator">=</span><span class="hljs-operator">&gt;</span> ({
 href: props.yahoo
   ? <span class="hljs-string">"https://www.yahoo.com"</span>
   : props.google
   ? <span class="hljs-string">"https://www.google.com"</span>
   : <span class="hljs-string">""</span>
   ? <span class="hljs-string">"#"</span>
   : props.href,
 target: <span class="hljs-string">"_blank"</span>
}))`
 color: blue;
 font<span class="hljs-operator">-</span>size: 16px;
 padding: 7px;
 display: <span class="hljs-built_in">block</span>;
`;
</code></pre><p>Go through this example to understand it thoroughly:</p>
<iframe src="https://codesandbox.io/embed/stylecomponents-atributes-1mrrk5?fontsize=14&amp;hidenavigation=1&amp;theme=dark" style="width:100%;height:500px;border:0;border-radius:4px;overflow:hidden" sandbox="allow-forms allow-modals allow-popups allow-presentation allow-same-origin allow-scripts"></iframe>

<h3 id="heading-decorating-a-component">Decorating a Component</h3>
<p>Styled Components library provides us the right way to decorate a component and to make it user friendly with the help of props, attrs, conditions, dynamic styling, extending / overriding the styles etc. </p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1660404180411/0GnHOeFPP.jpg" alt="7-DecorateComponent-updated.jpg" /></p>
<p>A different type of prop is available which we can call it ‘Polymorphic’. Create a styled- component and we can render it as an html element as we desire. A keyword “as” is used like an attribute to make this happen, as shown below:</p>
<pre><code><span class="hljs-operator">&lt;</span>button <span class="hljs-keyword">as</span><span class="hljs-operator">=</span>”a”<span class="hljs-operator">&gt;</span>Click to open<span class="hljs-operator">&lt;</span><span class="hljs-operator">/</span>button<span class="hljs-operator">&gt;</span>
</code></pre><p>Here, a button tag will be rendered as an anchor tag as mentioned as=”a”. The value “a” refers to an anchor tag.</p>
<p>Refer this example for more details:</p>
<iframe src="https://codesandbox.io/embed/styledcomponents-selectors-decoratingcomponent-lendch?fontsize=14&amp;hidenavigation=1&amp;theme=dark" style="width:100%;height:500px;border:0;border-radius:4px;overflow:hidden" sandbox="allow-forms allow-modals allow-popups allow-presentation allow-same-origin allow-scripts"></iframe>

<p>Similarly, a React Component can also be rendered as a styled-component by using polymorphic prop ‘as’.</p>
<p><code>... this is Styled-Components library at a glance. Still we can explore many interesting things when it is used along with any component based workflows  like React.</code></p>
<p><em> ...keep an eye for the next article on <a target="_blank" href="https://codecogniz.com/package-managers">Package Managers</a>. </em></p>
]]></content:encoded></item></channel></rss>