<?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 Tomasz Zwierzchoń on Medium]]></title>
        <description><![CDATA[Stories by Tomasz Zwierzchoń on Medium]]></description>
        <link>https://medium.com/@tozwierz?source=rss-d70031e2f44f------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*cB6OE9_q6UzWgvCy7vgEMg.jpeg</url>
            <title>Stories by Tomasz Zwierzchoń on Medium</title>
            <link>https://medium.com/@tozwierz?source=rss-d70031e2f44f------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 31 May 2026 20:34:45 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@tozwierz/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[Why do Business Goals Matter in IT?]]></title>
            <link>https://medium.com/@tozwierz/why-do-business-goals-matter-in-it-659624fd5d26?source=rss-d70031e2f44f------2</link>
            <guid isPermaLink="false">https://medium.com/p/659624fd5d26</guid>
            <category><![CDATA[business]]></category>
            <category><![CDATA[project-management]]></category>
            <category><![CDATA[information-technology]]></category>
            <dc:creator><![CDATA[Tomasz Zwierzchoń]]></dc:creator>
            <pubDate>Mon, 02 Jan 2023 17:14:31 GMT</pubDate>
            <atom:updated>2023-01-02T17:14:31.776Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*n_-sfcJMxG--lS605v-mSQ.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/@hnhmarketing?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Hunter Haley</a> on <a href="https://unsplash.com/photos/s8OO2-t-HmQ?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><p>Business goals are the driving force behind any organization, and they are crucial in the process of creating an IT solution. <br>Without a clear understanding of a company’s goals, it is difficult to determine how an IT solution will fit into the overall strategy and what it needs to accomplish.</p><p>A business goal is a target that an organization aims to achieve, whether it be increasing profits, improving efficiency, or expanding into new markets. These goals are usually defined by the leadership of the organization.</p><p>The importance of business goals in the process of creating an IT solution lies in the fact that they provide direction and focus for the project. They help to determine the scope of the solution, the resources needed, and the timeline for completion.</p><p>For example, let’s say a company’s goal is to increase efficiency in its sales department. In this case, an IT solution could be developed to streamline the sales process, such as by automating the tracking of leads and customer interactions. This solution would be tailored to the specific needs of the sales department and would be designed to help the company achieve its efficiency goal.</p><p>Another important aspect of business goals is that they can help to align an IT solution with the overall strategy of the organization. By understanding the direction that a company is heading in, it is possible to create an IT solution that supports and enhances that direction.</p><h3>Project without a business goal</h3><p>When a project does not have a clear business goal, it can lead to several problems. Here are a few examples:</p><ul><li><strong>Lack of direction</strong>: Without a specific target to aim for, it can be difficult to determine the direction of the project and what needs to be done. This can lead to wasted time and resources as the team tries to figure out the purpose of the project.</li><li><strong>Misalignment with company strategy</strong>: Without a business goal, it is harder to align the project with the overall strategy of the organization. This can lead to the IT solution not being integrated into the company’s operations or not supporting its long-term goals.</li><li><strong>Difficulty measuring success</strong>: Without a business goal, it is harder to determine if the project has been successful. This can make it difficult to justify the investment in the IT solution and can lead to a lack of support for future projects.</li><li><strong>Limited scope</strong>: Without a business goal, the scope of the project may be too broad or too narrow. This can lead to the IT solution being overly complex or not providing enough value to the organization.</li></ul><h3>Conclusion</h3><p>Not having a clear business goal can lead to a lack of direction, misalignment with company strategy, difficulty measuring success, and limited scope. <br>It is important to define business goals at the outset of a project to ensure that the IT solution meets the needs of the organization and helps to achieve its goals.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=659624fd5d26" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[JSON Web Tokens (JWT) for a five-year-old.]]></title>
            <link>https://medium.com/@tozwierz/json-web-tokens-jwt-for-a-five-year-old-57034d409e81?source=rss-d70031e2f44f------2</link>
            <guid isPermaLink="false">https://medium.com/p/57034d409e81</guid>
            <category><![CDATA[jwt]]></category>
            <category><![CDATA[jwt-authentication]]></category>
            <dc:creator><![CDATA[Tomasz Zwierzchoń]]></dc:creator>
            <pubDate>Mon, 02 Jan 2023 11:33:44 GMT</pubDate>
            <atom:updated>2023-01-02T11:36:36.629Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*02hiYwiqaxEbz1PeEeBm0Q.png" /></figure><h4>JSON Web Token (JWT) is the compact, URL-safe means of representing claims to be transferred between two parties.</h4><p>JWT is a string, that consists of three parts: a header, a payload, and a signature.</p><h3><strong>The header of a JWT</strong></h3><p><strong>The header</strong> typically consists of two parts: the type of the token, which is JWT, and the signing algorithm being used, such as HMAC SHA256 or RSA.</p><p><strong>Example of JWT header</strong> which specifies that the HMAC SHA-256 algorithm will be used to sign the JWT:</p><pre>{<br>  &quot;alg&quot;: &quot;HS256&quot;,<br>  &quot;typ&quot;: &quot;JWT&quot;<br>}</pre><h3>The payload of a JWT</h3><p>The second part of the token is the payload, which contains the claims. Claims are statements about an entity (typically, the user) and additional data. The claims in the JWT are encoded as a JSON object.<br>There are three types of claims: registered, public, and private claims. Registered claims are a set of predefined claims which are not mandatory but recommended, to provide a set of useful, interoperable claims. <br>Some examples of registered claims include “iss” (issuer), “exp” (expiration time), and “sub” (subject). <br>Public claims are claims that are defined by the user but are not registered. Private claims are claims that are used only in the context of the user and the application.</p><p><strong>Example of JWT claims</strong> set with registered exp and custom name headers:</p><pre>{<br>  &quot;exp&quot;: 2218239022,<br>  &quot;name&quot;: &quot;Tomasz Zwierzchoń&quot;<br>}</pre><h3>The signature of a JWT</h3><p>The third part of the token is<strong> the signature</strong>, which is used to verify that the sender of the JWT is who it says it is and to ensure that the message wasn’t changed along the way.</p><p><strong>Example of JWT signature:</strong></p><pre>HMACSHA256(<br>  base64UrlEncode(header) + &quot;.&quot; +<br>  base64UrlEncode(payload),<br>  secret)</pre><p>In this example, the signature is created by taking the base64Url-encoded header, concatenating it with the base64Url-encoded payload, and then signing it with a secret using the HMAC SHA-256 algorithm. The resulting signature is then appended to the header and payload to create the complete JWT.</p><h3>What is the use of JWT?</h3><p>JWTs are often used to authenticate users. When a user logs in, the user’s credentials are sent to the server. If the credentials are correct, the server sends a JWT back to the user. The user can then use this JWT to authenticate subsequent requests to the server. This allows the server to trust that the requests are coming from an authenticated user, without requiring the server to maintain a session or ask the user to authenticate again for every request.</p><p>Overall, JWTs provide a simple, compact, and secure way to transmit information between parties, and are commonly used in modern web applications.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=57034d409e81" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[MAC and HMAC for a five-year-old.]]></title>
            <link>https://medium.com/@tozwierz/mac-and-hmac-for-a-five-year-old-c4c4de5bc7e8?source=rss-d70031e2f44f------2</link>
            <guid isPermaLink="false">https://medium.com/p/c4c4de5bc7e8</guid>
            <category><![CDATA[shopify]]></category>
            <category><![CDATA[hmav]]></category>
            <dc:creator><![CDATA[Tomasz Zwierzchoń]]></dc:creator>
            <pubDate>Mon, 02 Jan 2023 11:11:15 GMT</pubDate>
            <atom:updated>2023-01-02T11:11:15.640Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/0*19qekR8IL2k9VVa1.jpeg" /></figure><p>This is a follow-up to my article about <a href="https://medium.com/swlh/json-web-signature-jws-and-jws-detached-for-a-five-year-old-88729b7b1a68">JWT</a>. <br>It became clear that many developers do not fully understand what MAC and HMAC are and how they work. Therefore, I wanted to provide a follow-up discussing these concepts in more detail.</p><p><strong>Message Authentication Code (MAC)</strong> is a cryptographic technique that is used to verify the authenticity and integrity of a message. <br>It involves the use of a secret key to generate a MAC value, which is appended to the message. The recipient of the message can then use the same key to recalculate the MAC value and compare it to the one received with the message. If the values match, the authenticity and integrity of the message can be verified.</p><p><strong>HMAC (Hash-based Message Authentication Code)</strong> is a specific type of MAC that uses a cryptographic hash function (e.g., SHA-256) in combination with a secret key to generate the MAC value. This makes it more secure than MAC, as it is more resistant to attacks that try to break the key.</p><p><strong>Here is an example of how HMAC could be used in a RESTful API:</strong></p><ol><li>The client sends a request to the server to retrieve some data.</li><li>The server calculates the HMAC of the request using the secret key and a hash function (e.g. SHA-256).</li><li>The server includes the HMAC value in the response to the client.</li><li>The client calculates the HMAC of the response using the same secret key and hash function.</li><li>The client compares the calculated HMAC value to the one received from the server. If they match, the client can trust that the response has not been tampered with and is authentic.</li></ol><p>This example assumes that the secret key is shared between the client and server and is not transmitted over the network.<br>For example, Shopify apps should validate HMAC to ensure that the request received by them has actually originated from the Shopify platform.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c4c4de5bc7e8" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[JSON Web Signature (JWS) and JWS Detached for a five-year-old]]></title>
            <link>https://medium.com/swlh/json-web-signature-jws-and-jws-detached-for-a-five-year-old-88729b7b1a68?source=rss-d70031e2f44f------2</link>
            <guid isPermaLink="false">https://medium.com/p/88729b7b1a68</guid>
            <category><![CDATA[polishapi]]></category>
            <category><![CDATA[jws-detached]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[jw]]></category>
            <dc:creator><![CDATA[Tomasz Zwierzchoń]]></dc:creator>
            <pubDate>Fri, 05 Jul 2019 07:47:46 GMT</pubDate>
            <atom:updated>2023-01-02T10:51:37.246Z</atom:updated>
            <content:encoded><![CDATA[<h3>JSON Web Signature (JWS) and JWS Detached for a five-year-old.</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*IRhTxk3BZtQvnS9c9SiINQ.jpeg" /></figure><p>Working for some time with JSON Web Signature (JWS) I came to the conclusion that many developers do not understand what it is and how it works.</p><h4>JSON Web Signature (JWS) represents content secured with digital signatures or Message Authentication Codes (MACs) using JSON-based data structures.</h4><p>There are two defined serializations for JWSs: a compact (described in this article) and a JSON.</p><p>The compact serialised JWS is a string containing three parts (in order) joined with a dot (“.”):</p><ul><li>Header,</li><li>Payload,</li><li>Signature.</li></ul><p><em>Example of the compact serialised JWS string: </em>eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9<strong>.</strong>eyJleHAiOjIyMTgyMzkwMjIsIm5hbWUiOiJUb21hc3ogWndpZXJ6Y2hvxYQifQ.t3VhQ7QsILDuV_HNFSMI-Fb2FoT7fuzalpS5AH8A9c0<br>Each part is <em>BASE64URL</em><strong> </strong>encoded.</p><p><strong>The Header</strong> describe the digital signature or message authentication code (MAC) applied to the the Payload and optionally additional properties of the JWS.</p><p>Header part before encoding is a JSON structure (example below):</p><pre>{<br>  &quot;alg&quot;: &quot;HS256&quot;,<br>  &quot;typ&quot;: &quot;JWT&quot;<br>}</pre><p>The Header parameter names (object keys) within the Header <strong>must</strong> be unique. There are registered Header parameter names:</p><ul><li>“alg” (<strong>required</strong>) — algorithm, which identifies the cryptographic<br> algorithm used to secure the JWS;<br><em>It can be set to ‘none’, which indicates that the Signature must be an empty string!</em></li><li>“jku” — (optional) JWK Set URL is a URI that refers to a resource for a set of JSON-encoded public keys, one of which corresponds to the key used to digitally sign the JWS;</li><li>“jwk” — (optional) JSON Web Key is the public key that corresponds to the private key used to digitally sign the JWS. This public key is represented as a JSON Web Key [JWK];</li><li>“kid” — (optional) key ID is a hint indicating which key was used to secure the JWS. It can be used to inform recipient that key is changed;</li><li>“x5u” — (optional) X.509 URL is a URI that points to a resource for the X.509 public key certificate or certificate chain corresponding to the private key used to digitally sign the JWS;</li><li>“x5c” — (optional) X.509 certificate chain contains the X.509 public key certificate or certificate chain corresponding to the private key used to digitally sign the JWS;</li><li>“x5t” — (optional) X.509 certificate SHA-1 thumbprint (fingerprint) is a<br> base64url-encoded SHA-1 thumbprint (a.k.a. digest) of the DER<br> encoding of the X.509 public certificate [RFC5280] corresponding to the private key used to digitally sign the JWS;</li><li>“x5t#S256” — (optional) X.509 certificate SHA-256 thumbprint (fingerprint) is a base64url-encoded SHA-256 thumbprint (a.k.a. digest)<br> of the DER encoding of the X.509 public certificate corresponding<br> to the private key used to digitally sign the JWS;</li><li>“typ” — (optional) type is used by JWS applications to declare the media type of the complete JWS;</li><li>“cty” — (optional) content type is used by JWS applications<br> to declare the media type of the Payload.</li></ul><p>In our example header, we can see that JWS type is JSON Web Token (JWT) and that Payload is secured by HS256 (<a href="https://en.wikipedia.org/wiki/HMAC">HMAC</a> with SHA-256) cryptographic algorithm.</p><p><strong>The payload</strong> can be any content. <em>It can be JSON but it is not needed.</em></p><p><strong>The signature </strong>is computed in the manner defined for the particular algorithm being used (and declared in the Header) from ASCII(BASE64URL(UTF8(JWS Protected Header)) || ‘.’ ||BASE64URL(JWS Payload)).</p><p><strong>Important note: Do not confuse <em>BASE64URL</em> with <em>BASE64</em>!</strong> <br>In <em>BASE64URL</em>:</p><ul><li>all trailing ‘=’ are removed</li><li>‘+’ is replaced by ‘-’</li><li>‘/’ is replaced by ‘_’.</li></ul><h4>JWS Detached is a variation of JWS that allows you to sign content (body) of HTTP request or response without its modification.</h4><p>The HTTP header “x-jws signature” is added, which contains data allowing to check whether the message has not been changed on way from the sender to the recipient.</p><p>JWS Detached generation algorithm is very simple:<br>a) Generate a standard JWS using compact serialization using HTTP body as a payload,<br>b) Turn the middle part (Payload) into an empty string,<br>c) Put final string in the HTTP header “x-jws signature”</p><p><em>Example of the JWS Detached string: </em>eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9<strong>.</strong>.t3VhQ7QsILDuV_HNFSMI-Fb2FoT7fuzalpS5AH8A9c0</p><p>Validation HTTP message with JWS Detached is simple too:<br>a) Get the HTTP header “x-jws signature”,<br>b) Get BASE64URL HTTP body<br>c) Put generate string b) into the Payload section<br>d) Validate JWS</p><p><strong>JWS</strong> is often found in tandem with <strong>JSON Web Token (JWT)</strong>, <strong>JSON Web Encryption (JWE)</strong> or <strong>JSON Object Signing and Encryption (JOSE)</strong>. Many similar shortcuts may lead to confusion.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=88729b7b1a68" width="1" height="1" alt=""><hr><p><a href="https://medium.com/swlh/json-web-signature-jws-and-jws-detached-for-a-five-year-old-88729b7b1a68">JSON Web Signature (JWS) and JWS Detached for a five-year-old</a> was originally published in <a href="https://medium.com/swlh">The Startup</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to embed public signing key in JWS / JWT header?]]></title>
            <link>https://medium.com/@tozwierz/how-to-embed-public-signing-key-in-jws-jwt-header-555c782279c4?source=rss-d70031e2f44f------2</link>
            <guid isPermaLink="false">https://medium.com/p/555c782279c4</guid>
            <category><![CDATA[jwks]]></category>
            <category><![CDATA[jwt-token]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Tomasz Zwierzchoń]]></dc:creator>
            <pubDate>Wed, 06 Mar 2019 21:59:00 GMT</pubDate>
            <atom:updated>2019-06-28T10:11:21.066Z</atom:updated>
            <content:encoded><![CDATA[<h3>How to embed public key in JWK format in JWS / JWT header?</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*CNIvP9GD8Z06gGj3m9UqZQ.jpeg" /></figure><p>It is easy with node-jose library when you know how to do it. <br>It took me some time to learn, because this information is missing in the documentation. Luckily it was in tests.</p><p>The missing example (creates a JWT with an embedded ‘jwk’):</p><pre>// {input} is a String<br>// {key} is from jwk keystore</pre><pre>jose.JWS.createSign(<br>  {<br>    fields: {<br>      typ: &#39;JWT&#39;,<br>    },<br>    format: &#39;compact&#39;,<br>    opts: { protect: <strong>false </strong>},<br>  },<br>  {<br>    key,<br>    reference: &#39;jwk&#39;, // MISSING in documentation<br>  },<br>).update(input, &#39;utf-8&#39;)<br>  .final()<br>  .then((result) =&gt; {<br>  // {result} is a JSON object -- JWT using the JSON General Serialization<br>  });</pre><p>I hope I saved you some time.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=555c782279c4" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Yarn and Bill Of Materials]]></title>
            <link>https://medium.com/@tozwierz/forward-thinking-javascript-6-bill-of-materials-166d0b3d4a5a?source=rss-d70031e2f44f------2</link>
            <guid isPermaLink="false">https://medium.com/p/166d0b3d4a5a</guid>
            <category><![CDATA[yarn]]></category>
            <category><![CDATA[bill-of-materials]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Tomasz Zwierzchoń]]></dc:creator>
            <pubDate>Thu, 07 Jun 2018 13:41:15 GMT</pubDate>
            <atom:updated>2019-03-06T21:16:55.289Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*N5qbJVvwggOMHJKwas1oIw.jpeg" /></figure><p>Today I would like to share small hint about how to get licenses from all packages, used in your javascript project. It’s very useful to make Bill Of Materials for your legal department.</p><p>Assuming you are using <a href="https://yarnpkg.com/en/">yarn</a> (if no — start right now), go to your project directory and paste this command:</p><pre>yarn licenses list</pre><p>To get only licensees use (for yarn 1.7.x):</p><pre>yarn licenses list | awk &#39;/^├─/ {$1=&quot;&quot;; print $0}&#39;</pre><p>That’s all folks. I hope you will find it handy.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=166d0b3d4a5a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to test Socket.io with Jest on backend (Node.js)?]]></title>
            <link>https://medium.com/@tozwierz/testing-socket-io-with-jest-on-backend-node-js-f71f7ec7010f?source=rss-d70031e2f44f------2</link>
            <guid isPermaLink="false">https://medium.com/p/f71f7ec7010f</guid>
            <category><![CDATA[socketio]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[jest]]></category>
            <category><![CDATA[nodejs]]></category>
            <dc:creator><![CDATA[Tomasz Zwierzchoń]]></dc:creator>
            <pubDate>Mon, 16 Apr 2018 12:22:47 GMT</pubDate>
            <atom:updated>2019-03-06T21:14:59.717Z</atom:updated>
            <content:encoded><![CDATA[<p>In one of our projects we’ve decided to use Socket.io to handle webscockets and to use a Jest to write BDD/TDD tests. Simply because on frontend we are using Jest too. And we wanted to use one test framework in all project.</p><p>This has proven to be a challenge. We cannot find any working example. Documentation did not cover our use case.</p><p>So for all of you with this problem I’ve created a boilerplate. I hope it will save you a couple of hours.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2fc13e2923f3127113e2c516b3ec654e/href">https://medium.com/media/2fc13e2923f3127113e2c516b3ec654e/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f71f7ec7010f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Forward Thinking — a never-complete guide to modern JavaScript #5 Maps]]></title>
            <link>https://medium.com/orba/forward-thinking-a-never-complete-guide-to-modern-javascript-5-maps-3be839c9532b?source=rss-d70031e2f44f------2</link>
            <guid isPermaLink="false">https://medium.com/p/3be839c9532b</guid>
            <category><![CDATA[weakmaps]]></category>
            <category><![CDATA[maps]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Tomasz Zwierzchoń]]></dc:creator>
            <pubDate>Mon, 27 Nov 2017 22:49:19 GMT</pubDate>
            <atom:updated>2018-06-07T13:33:03.322Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*N5qbJVvwggOMHJKwas1oIw.jpeg" /></figure><p>In the p<a href="https://medium.com/orba/forward-thinking-a-never-complete-guide-to-modern-javascript-3-sets-68b943090bec">art #3 of my guide</a> we were discovering Sets. Now it’s time for <em>maps</em>.</p><p><em>Maps</em> are ordered lists of key-value pairs. The key and the value can have any type. This is the main difference between objects keys and maps.</p><p>Try this code:</p><pre>const log = x =&gt; console.log(x);<br>const objectMap = Object.create(null);</pre><pre>objectMap[123] = &#39;abc&#39;;<br>log(objectMap[&#39;123&#39;]);<br>log(objectMap[123]);</pre><pre>const map = new Map();<br>map.set(123, &#39;abc&#39;);<br>map.set(&#39;123&#39;, &#39;cba&#39;);</pre><pre>log(map.get(123));<br>log(map.get(&#39;123&#39;));</pre><p>We can even use objects as a keys:</p><pre>const log = x =&gt; console.log(x);<br>const object1 = {};<br>const map = new Map();</pre><pre>map.set(object1, &#39;some value&#39;);<br>log(map.get(object1));</pre><p>We can use it to store addtional data in objects without a need of a jQuery data method:</p><pre>const log = x =&gt; console.log(x);<br>const el = document.querySelector(&#39;html&#39;);<br>const map = new Map();</pre><pre>map.set(el, &#39;some value&#39;);<br>log(map.get(el));</pre><p>This approach has one problem. When we delete a node from DOM it is still present in the map. But we can fix it easily. <em>Weak maps</em> to the help!</p><p>In <em>weak maps</em> every key must be an object and when key reference outside map is deleted, the key-value pair is removed from it.</p><p>Try this code:</p><pre>const log = x =&gt; console.log(x);<br>const query = x =&gt; document.querySelector(x);<br>const body = query(&#39;body&#39;);<br>const map = new WeakMap();</pre><pre>body.innerHTML = &#39;&lt;div id=&quot;div1&quot;&gt;&lt;/div&gt;&lt;div id=&quot;div2&quot;&gt;&lt;/div&gt;&#39;;</pre><pre>let el = query(&#39;#div1&#39;);<br>map.set(el, &#39;some value&#39;);<br>log(`Before delete: ${map.get(el)}`);</pre><pre>el = null;<br>log(`After delete: ${map.get(el)}`);</pre><p>More about <em>Maps</em> here: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map">https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3be839c9532b" width="1" height="1" alt=""><hr><p><a href="https://medium.com/orba/forward-thinking-a-never-complete-guide-to-modern-javascript-5-maps-3be839c9532b">Forward Thinking — a never-complete guide to modern JavaScript #5 Maps</a> was originally published in <a href="https://medium.com/orba">Orba</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Forward Thinking — a never-complete guide to modern JavaScript #4 Spread Operator]]></title>
            <link>https://medium.com/orba/forward-thinking-a-never-complete-guide-to-modern-javascript-4-spread-operator-e4eaa487c51f?source=rss-d70031e2f44f------2</link>
            <guid isPermaLink="false">https://medium.com/p/e4eaa487c51f</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[deconstruction]]></category>
            <category><![CDATA[spread-operator]]></category>
            <dc:creator><![CDATA[Tomasz Zwierzchoń]]></dc:creator>
            <pubDate>Mon, 13 Nov 2017 14:36:10 GMT</pubDate>
            <atom:updated>2017-11-13T23:27:03.001Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cRoelfDYCJl-mU4QYkRDzA.jpeg" /></figure><p>In the <a href="https://medium.com/orba/forward-thinking-a-never-complete-guide-to-modern-javascript-3-sets-68b943090bec">previous post</a> we’ve met magic three dots „…” alias <em>spread operator</em>. Those dots are worth exploring before we will go to <em>maps</em>.</p><p>Main objective of the <em>spread operator</em> is to spread the elements of an array or an iterable object.</p><p>Try this code:</p><pre>const log = x =&gt; console.log(x);<br>const myFunction = (a, b, c) =&gt; {<br>  log(`a: ${a}, b: ${b}, c: ${c}`)<br>};<br>const myArr1 = [1, 2, 3];</pre><pre>myFunction(...myArr1);</pre><p>As you can see each element in the array is passed as the argument to the function. But we can do more! A few examples below.</p><p>Any argument in the list can use spread syntax:</p><pre>const log = x =&gt; console.log(x);<br>const myFunction = (a, b, c) =&gt; {<br>  log(`a: ${a}, b: ${b}, c: ${c}`)<br>};<br>const myArr2 = [1, 2];</pre><pre>myFunction(...myArr2,69);</pre><p>Coping one array to the second or combining them:</p><pre>const log = x =&gt; console.log(x);<br>const myArr3 = [&#39;Lorem&#39;, &#39;Ipsum&#39;, &#39;Sit&#39;, &#39;Amet&#39;];</pre><pre>const myArr4 = [...myArr3];<br>log(myArr4);</pre><pre>const myArr5 = [2, 3, 5, 7, 11, ...myArr3];<br>log(myArr5);</pre><pre>myArr5.unshift(...myArr3);<br>log(myArr5);</pre><p>Or we can use it to deconstructions:</p><pre>const log = x =&gt; console.log(x);<br>const [a, b, ...rest] = [1, 2, 3, 4, 5, 6, 7];<br>log(`a: ${a}, b: ${b}, rest: ${rest}`);</pre><p>I hope you will like those dots as much as I do.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e4eaa487c51f" width="1" height="1" alt=""><hr><p><a href="https://medium.com/orba/forward-thinking-a-never-complete-guide-to-modern-javascript-4-spread-operator-e4eaa487c51f">Forward Thinking — a never-complete guide to modern JavaScript #4 Spread Operator</a> was originally published in <a href="https://medium.com/orba">Orba</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Forward Thinking — a never-complete guide to modern JavaScript #3 — Sets]]></title>
            <link>https://medium.com/orba/forward-thinking-a-never-complete-guide-to-modern-javascript-3-sets-68b943090bec?source=rss-d70031e2f44f------2</link>
            <guid isPermaLink="false">https://medium.com/p/68b943090bec</guid>
            <category><![CDATA[collection]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Tomasz Zwierzchoń]]></dc:creator>
            <pubDate>Mon, 06 Nov 2017 07:11:00 GMT</pubDate>
            <atom:updated>2017-11-13T14:47:47.940Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cRoelfDYCJl-mU4QYkRDzA.jpeg" /></figure><p>I’ve discovered that many of us JavasScript programers haven’t noticed that ECMAScript6 introduced two new types of collections: sets and maps.</p><p>Let’s start today with a <em>set</em>. What is it, you may ask? The <em>set</em> is a collection of unique elements.</p><p>Try this code:</p><pre>const log = x =&gt; console.log(x);</pre><pre>const mySet = new Set();<br>mySet.add(123);<br>mySet.add(&#39;123&#39;);<br>mySet.add(123);<br>log(mySet);</pre><p>As you can see, we have only 2 elements in our set, as expected.</p><p>We can initialize our set using an array:</p><pre>const log = x =&gt; console.log(x);</pre><pre>const mySecondSet = new Set([123,&quot;123&quot;,123]);<br>mySecondSet.add(&quot;123&quot;);<br>log(mySecondSet);</pre><p>And convert it to an array (with a little help from a <em>spread operator</em>):</p><pre>const log = x =&gt; console.log(x);</pre><pre>const myThirdSet = new Set([123,&quot;123&quot;,123]);<br>const myArray = [...myThirdSet];</pre><pre>log(myArray);</pre><p><strong>With this knowledge we can quickly build functions which removes duplicates from an array :)</strong></p><pre>const log = x =&gt; console.log(x);</pre><pre>const removeDuplicates = items =&gt; [...new Set(items)];<br>const arrayWithDuplicates = [1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 5, 6];<br>log(removeDuplicates(arrayWithDuplicates));</pre><p>More about <em>Sets </em>here: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set">https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=68b943090bec" width="1" height="1" alt=""><hr><p><a href="https://medium.com/orba/forward-thinking-a-never-complete-guide-to-modern-javascript-3-sets-68b943090bec">Forward Thinking — a never-complete guide to modern JavaScript #3 — Sets</a> was originally published in <a href="https://medium.com/orba">Orba</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>