<?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 Aakash Thakur on Medium]]></title>
        <description><![CDATA[Stories by Aakash Thakur on Medium]]></description>
        <link>https://medium.com/@akashthakur_15975?source=rss-df77bef746c2------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*Cm8pipeGn-3kgWFx.</url>
            <title>Stories by Aakash Thakur on Medium</title>
            <link>https://medium.com/@akashthakur_15975?source=rss-df77bef746c2------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 29 Nov 2026 14:16:08 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@akashthakur_15975/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[Migrating husky to v9]]></title>
            <link>https://javascript.plainenglish.io/migrating-husky-to-v9-33c1f02eb3a9?source=rss-df77bef746c2------2</link>
            <guid isPermaLink="false">https://medium.com/p/33c1f02eb3a9</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[front-end-development]]></category>
            <category><![CDATA[web-development]]></category>
            <dc:creator><![CDATA[Aakash Thakur]]></dc:creator>
            <pubDate>Thu, 10 Oct 2024 07:57:04 GMT</pubDate>
            <atom:updated>2024-10-10T10:54:30.446Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PqN7ONMZZSm1WuRL2nVE9g.jpeg" /></figure><p>Git hooks are essential tools in modern development workflows, and Husky has long been the go-to solution for managing them in JavaScript projects. With the release of Husky v9, developers face the task of migrating from older versions. Whether you’re coming from v4 or v8, this guide will walk you through the migration process step by step.</p><h4>Why Upgrade to Husky v9?</h4><p>Before diving into the migration steps, let’s understand why upgrading is worth your time:</p><ul><li><strong>Improved Performance</strong>: v9 offers faster hook execution</li><li><strong>Smaller Footprint</strong>: Reduced installation size</li><li><strong>Better Shell Script Handling</strong>: More reliable script execution</li><li><strong>Modern Architecture</strong>: Aligned with current best practices</li></ul><h4>Migrating from Husky v4 to v9</h4><p><strong>1. Update Your Dependencies</strong></p><p>Start by installing the latest versions of Husky and lint-staged:</p><pre>npm install — save-dev husky@latest lint-staged@latest</pre><p><strong>2. Initialize the New Husky</strong></p><pre>npx husky init</pre><p>This command creates a .huskydirectory in your project root and sets up a basic pre-commit hook. It also modifies your package.json to add a prepare script that installs husky hooks.</p><p><strong>3. Configure Your Hooks</strong></p><p>Replace the content in .husky/pre-commit with:</p><pre><br>#!/usr/bin/env sh<br>. “$(dirname — “$0”)/_/husky.sh”<br><br>npx lint-staged</pre><p>Create a pre-push hook to run tests:</p><pre>echo “npm test” &gt; .husky/pre-push<br>chmod +x .husky/pre-push</pre><p><strong>4. Clean Up Package.json</strong></p><p>Remove the old Husky configuration from your package.json:</p><pre>{<br>- “husky”: {<br>-   “hooks”: {<br>-       “pre-commit”: “lint-staged”,<br>-       “pre-push”: “npm test”<br>-   }<br>- }<br>}</pre><p><strong>5. Update lint-staged Configuration</strong></p><p>Update your lint-staged configuration in package.json:</p><pre>{<br> “lint-staged”: {<br>   “*.{ts,tsx,js,jsx}”: [<br>     “prettier — write”,<br>     “eslint — fix”<br>   ]<br> }<br>}</pre><p><strong>6. Update Parameter Handling</strong></p><p>If you were using `$HUSKY_GIT_PARAMS`, update to standard Git hook parameters:</p><pre>- test $HUSKY_GIT_PARAMS<br>+ test “$1” “$2”</pre><h4>Migrating from Husky v8 to v9</h4><p>The journey from v8 to v9 is less dramatic but still requires attention to detail.</p><p><strong>1. Update Husky</strong></p><pre>npm install — save-dev husky@latest</pre><p><strong>2. Update Your Prepare Script</strong></p><p>Ensure your package.json has the correct prepare script:</p><pre>{<br>  &quot;scripts&quot;: {<br>-   &quot;prepare&quot;: &quot;husky install&quot;<br>+   &quot;prepare&quot;: &quot;husky&quot;<br>  }<br>}</pre><p><strong>3. Review Existing Hooks</strong></p><p>Check your hook files in the .husky directory. An example of .husky/pre-commit</p><pre><br>- #!/usr/bin/env sh<br>- . &quot;$(dirname -- &quot;$0&quot;)/_/husky.sh&quot;<br>npm test </pre><h4><strong>Verifying Your Migration</strong></h4><p>Regardless of your starting point, verify your migration with these steps:</p><ol><li>Make a small change to a tracked file</li><li>Attempt to commit: git add . &amp;&amp; git commit -m “test migration”</li><li>Verify that pre-commit hooks run</li><li>Try to push and check that pre-push hooks execute</li></ol><h4><strong>Troubleshooting Common Issues</strong></h4><p><strong>Hooks Not Executing — </strong>Ensure hook files are executable</p><pre>chmod ug+x .husky/*</pre><p><strong>lint-staged Not Found — </strong>Verify lint-staged installation</p><pre><br>npm list lint-staged</pre><h4><strong>Best Practices for Husky v9</strong></h4><ol><li><strong>Keep Hook Scripts Simple</strong>: Each hook should have a clear, single responsibility</li><li><strong>Use Meaningful Hook Names</strong>: Choose descriptive names for custom hooks</li><li><strong>Leverage lint-staged</strong>: Use it to run linters only on changed files</li><li><strong>Version Control</strong>: Always commit the `.husky` directory</li></ol><h4>Final Thoughts</h4><p>Migrating to Husky v9 modernizes your Git hooks and enhances your development workflow. With improved performance and reliability, the effort to upgrade is well worth the benefits you’ll gain.</p><p><em>Have you successfully migrated to Husky v9? Share your experiences and tips in the comments below!</em></p><h3>In Plain English 🚀</h3><p><em>Thank you for being a part of the </em><a href="https://plainenglish.io/"><strong><em>In Plain English</em></strong></a><em> community! Before you go:</em></p><ul><li>Be sure to <strong>clap</strong> and <strong>follow</strong> the writer ️👏<strong>️️</strong></li><li>Follow us: <a href="https://twitter.com/inPlainEngHQ"><strong>X</strong></a> | <a href="https://www.linkedin.com/company/inplainenglish/"><strong>LinkedIn</strong></a> | <a href="https://www.youtube.com/channel/UCtipWUghju290NWcn8jhyAw"><strong>YouTube</strong></a> | <a href="https://discord.gg/in-plain-english-709094664682340443"><strong>Discord</strong></a> | <a href="https://newsletter.plainenglish.io/"><strong>Newsletter</strong></a></li><li>Visit our other platforms: <a href="https://cofeed.app/"><strong>CoFeed</strong></a> | <a href="https://differ.blog/"><strong>Differ</strong></a></li><li>More content at <a href="https://plainenglish.io/"><strong>PlainEnglish.io</strong></a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=33c1f02eb3a9" width="1" height="1" alt=""><hr><p><a href="https://javascript.plainenglish.io/migrating-husky-to-v9-33c1f02eb3a9">Migrating husky to v9</a> was originally published in <a href="https://javascript.plainenglish.io/">JavaScript in Plain English</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Webpack to Rspack: Boosting Your Build Performance]]></title>
            <link>https://javascript.plainenglish.io/webpack-to-rspack-boosting-your-build-performance-17981a3ea982?source=rss-df77bef746c2------2</link>
            <guid isPermaLink="false">https://medium.com/p/17981a3ea982</guid>
            <category><![CDATA[angular]]></category>
            <category><![CDATA[webpack]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[front-end-development]]></category>
            <dc:creator><![CDATA[Aakash Thakur]]></dc:creator>
            <pubDate>Tue, 17 Sep 2024 10:35:45 GMT</pubDate>
            <atom:updated>2024-09-19T15:03:05.544Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*4MxY_GWMoH626yXvi9hjSA.jpeg" /></figure><p>In the ever-evolving world of JavaScript bundlers, a new player has emerged that’s turning heads in the development community. Rspack, a Rust-based bundler developed by ByteDance, promises to deliver webpack-like functionality with a significant boost in performance. In this article, we’ll compare webpack and Rspack, and guide you through the process of converting your existing webpack configuration to Rspack.</p><blockquote>🚀 Rspack recently announced 1.0: <a href="https://rspack.dev/blog/announcing-1-0">https://rspack.dev/blog/announcing-1-0</a></blockquote><h3>Webpack vs. Rspack: A Comparison</h3><h3>Webpack</h3><p>Webpack has long been the go-to bundler for JavaScript projects. It’s known for its flexibility, extensive ecosystem, and robust feature set. However, as projects grow in size and complexity, webpack can sometimes struggle with build times and performance.</p><h3>Rspack</h3><p>Rspack, on the other hand, is the new kid on the block. Built with Rust, it aims to provide a high-performance alternative to webpack while maintaining compatibility with webpack configurations. Here’s how they stack up:</p><ol><li><strong>Performance</strong>: Rspack shines in build speed, often completing builds several times faster than webpack, especially in larger projects.</li><li><strong>Compatibility</strong>: Rspack strives for webpack compatibility, making migration easier for existing projects.</li><li><strong>Ecosystem</strong>: Webpack has a vast ecosystem of plugins and loaders. Rspack is newer but growing, and can use many webpack plugins.</li><li><strong>Configuration</strong>: Both use similar configuration structures, but Rspack simplifies some aspects.</li><li><strong>Language</strong>: Webpack is written in JavaScript, while Rspack is written in Rust, contributing to its performance advantages.</li></ol><h3>Converting Webpack to Rspack: A Step-by-Step Guide</h3><p>Let’s walk through the process of converting a webpack configuration to Rspack.</p><h3>Step 1: Install Rspack</h3><p>First, you’ll need to install Rspack and its CLI:</p><pre>npm install -D @rspack/core @rspack/cli</pre><p>Now, you can remove webpack-related dependencies:</p><pre>npm remove webpack webpack-cli webpack-dev-server</pre><p>Note: In some cases, you might need to keep webpack as a dev dependency, especially if you’re using plugins like vue-loader or fork-ts-checker-webpack-plugin.</p><h3>Step 2: Update package.json</h3><p>Change your build scripts to use Rspack:</p><pre>{<br>  &quot;scripts&quot;: {<br>    &quot;serve&quot;: &quot;rspack serve&quot;,<br>    &quot;build&quot;: &quot;rspack build&quot;<br>  }<br>}</pre><h3>Step 3: Rename Configuration File</h3><p>Rename your webpack.config.js to rspack.config.js. Rspack will look for this file by default.</p><h3>Step 4: Update the Configuration</h3><p>Here’s a basic webpack configuration and how to convert it to Rspack:</p><pre>// rspack.config.js<br>const { HtmlRspackPlugin } = require(&#39;@rspack/core&#39;);</pre><pre>module.exports = {<br>  entry: &#39;./src/index.js&#39;,<br>  output: {<br>    filename: &#39;bundle.js&#39;,<br>    path: path.resolve(__dirname, &#39;dist&#39;),<br>  },<br>  module: {<br>    rules: [<br>      {<br>        test: /\.js$/,<br>        use: &#39;builtin:swc-loader&#39;,<br>        exclude: /node_modules/,<br>      },<br>      {<br>        test: /\.css$/,<br>        type: &#39;css&#39;,<br>      },<br>      {<br>        test: /\.(png|jpe?g|gif)$/i,<br>        type: &quot;asset/resource&quot;,<br>      },<br>    ],<br>  },<br>  plugins: [<br>    new HtmlRspackPlugin({<br>      template: &#39;./src/index.html&#39;,<br>    }),<br>  ],<br>};</pre><h3>Step 5: Adjust Plugins</h3><p>Rspack supports many webpack plugins, but you might need to change how you import them. For example:</p><pre>const rspack = require(&#39;@rspack/core&#39;);</pre><pre>// Use rspack.DefinePlugin instead of webpack.DefinePlugin<br>new rspack.DefinePlugin({<br>  // ...<br>})</pre><pre>// Use rspack.CopyRspackPlugin instead of copy-webpack-plugin<br>new rspack.CopyRspackPlugin({<br>  // ...<br>})</pre><pre>// Use rspack.CssExtractRspackPlugin instead of mini-css-extract-plugin<br>new rspack.CssExtractRspackPlugin({<br>  // ...<br>})</pre><h3>Step 6: Update Loaders</h3><p>Rspack has built-in support for many common use cases, which can simplify your configuration:</p><ol><li>Replace babel-loader or swc-loader with builtin:swc-loader for better performance:</li></ol><pre>{<br>  test: /\.(j|t)sx?$/,<br>  use: {<br>    loader: &#39;builtin:swc-loader&#39;,<br>    options: {<br>      jsc: {<br>        parser: {<br>          syntax: &#39;typescript&#39;,<br>          jsx: true,<br>        },<br>        transform: {<br>          react: {<br>            runtime: &#39;automatic&#39;,<br>          },<br>        },<br>      },<br>    },<br>  },<br>  exclude: /node_modules/,<br>}</pre><p>2. Replace file loaders with Asset Modules:</p><ul><li>Instead of file-loader, use type: &quot;asset/resource&quot;</li><li>Instead of url-loader, use type: &quot;asset/inline&quot;</li><li>Instead of raw-loader, use type: &quot;asset/source&quot;</li></ul><h3>Step 7: Test and Debug</h3><p>After making these changes, run your build process. Rspack provides a loose mode for easier migration:</p><pre>RSPACK_CONFIG_VALIDATE=loose rspack build</pre><p>This will show you configuration errors without stopping the build, helping you identify and fix issues step by step.</p><h3>Step 8: Performance analysis</h3><p>Similar to webpack-bundle-analyzer, rspack provides Rsdoctor for bundle analysis.</p><pre>npm add @rsdoctor/rspack-plugin -D</pre><p>Initialize the RsdoctorRspackPlugin plugin in the <a href="https://rspack.dev/config/plugins#plugins">plugins</a> section of rspack.config.js, as shown below:</p><pre>const { RsdoctorRspackPlugin } = require(&#39;@rsdoctor/rspack-plugin&#39;);<br><br>module.exports = {<br>  // ...<br>  plugins: [<br>    process.env.RSDOCTOR &amp;&amp;<br>      new RsdoctorRspackPlugin({<br>        // plugin options<br>      }),<br>  ].filter(Boolean),<br>};</pre><p>Add RSDOCTOR=true env variable before the CLI command</p><pre># dev<br>RSDOCTOR=true rspack serve<br><br># build<br>RSDOCTOR=true rspack build</pre><p>After running the above commands, when the build is completed, it will open the build analysis page</p><h3>Pros and Cons</h3><h3>Pros of Switching to Rspack</h3><ol><li><strong>Improved Build Speed</strong>: Significantly faster build times, especially for larger projects.</li><li><strong>Webpack Compatibility</strong>: Easier migration due to similar configuration structure.</li><li><strong>Built-in Optimizations</strong>: Many optimizations are included out-of-the-box.</li></ol><h3>Cons and Potential Pitfalls</h3><ol><li><strong>Ecosystem Limitations</strong>: Some webpack plugins or loaders might not be compatible or available.</li><li><strong>Community Support</strong>: Being newer, Rspack has a smaller community and fewer resources available.</li><li><strong>Learning Curve</strong>: While similar to webpack, there are differences that require learning and adjustment.</li></ol><h3>Results</h3><p>For our entrprise dashboard application which used to take <strong>~56s</strong> to compile with webpack significantly got improved to <strong>~4s</strong> with rspack.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/882/1*O2NkRdDtqGRbvq83CGYbpg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/776/1*-FVGGpJBDBbndR0VBfE29A.png" /></figure><h3>Conclusion</h3><p>Rspack offers an exciting alternative to webpack, particularly for projects struggling with build performance. While the transition can be relatively smooth due to webpack compatibility, it’s important to thoroughly test your build process after migration.</p><p>Remember, every project is unique, and what works best for one might not be ideal for another. Always benchmark your specific use case to determine if the switch to Rspack is beneficial for your project.</p><p>As with any new technology, keep an eye on Rspack’s development. Its rapid growth and performance benefits make it a promising tool in the JavaScript bundling landscape.</p><p><strong>Enjoyed this article?</strong> ☕️</p><p>If you found this piece helpful or inspiring, consider supporting my work with a coffee (or two)! Your support helps me keep creating content that you love. Just click the link below to show your appreciation:</p><figure><a href="http://buymeacoffee.com/aakashdevsky"><img alt="" src="https://cdn-images-1.medium.com/max/720/1*-hLwYg1WhQSvzEdEAFaI6Q.jpeg" /></a></figure><p>Thank you for being awesome!</p><h3>In Plain English 🚀</h3><p><em>Thank you for being a part of the </em><a href="https://plainenglish.io/"><strong><em>In Plain English</em></strong></a><em> community! Before you go:</em></p><ul><li>Be sure to <strong>clap</strong> and <strong>follow</strong> the writer ️👏<strong>️️</strong></li><li>Follow us: <a href="https://twitter.com/inPlainEngHQ"><strong>X</strong></a> | <a href="https://www.linkedin.com/company/inplainenglish/"><strong>LinkedIn</strong></a> | <a href="https://www.youtube.com/channel/UCtipWUghju290NWcn8jhyAw"><strong>YouTube</strong></a> | <a href="https://discord.gg/in-plain-english-709094664682340443"><strong>Discord</strong></a> | <a href="https://newsletter.plainenglish.io/"><strong>Newsletter</strong></a></li><li>Visit our other platforms: <a href="https://cofeed.app/"><strong>CoFeed</strong></a> | <a href="https://differ.blog/"><strong>Differ</strong></a></li><li>More content at <a href="https://plainenglish.io/"><strong>PlainEnglish.io</strong></a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=17981a3ea982" width="1" height="1" alt=""><hr><p><a href="https://javascript.plainenglish.io/webpack-to-rspack-boosting-your-build-performance-17981a3ea982">Webpack to Rspack: Boosting Your Build Performance</a> was originally published in <a href="https://javascript.plainenglish.io/">JavaScript in Plain English</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Quick guide: Comparing Session Authentication and JWTs in web development]]></title>
            <link>https://blog.devgenius.io/quick-guide-comparing-session-authentication-and-jwts-in-web-development-92e7b7f0a647?source=rss-df77bef746c2------2</link>
            <guid isPermaLink="false">https://medium.com/p/92e7b7f0a647</guid>
            <category><![CDATA[authentication]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[react]]></category>
            <dc:creator><![CDATA[Aakash Thakur]]></dc:creator>
            <pubDate>Sat, 23 Dec 2023 14:40:46 GMT</pubDate>
            <atom:updated>2023-12-23T16:08:58.364Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*5VygFesiBR9exR9h" /><figcaption>Photo by <a href="https://unsplash.com/@jeroendenotter?utm_source=medium&amp;utm_medium=referral">Jeroen den Otter</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Authentication is a cornerstone in web development, crucial for delivering secure and personalized experiences. In the realm of web applications, two primary authentication mechanisms stand out: Session-based Authentication and JSON Web Tokens (JWTs). Each comes with its unique characteristics, and choosing the right one depends on the specific needs of your application.</p><h3><strong>Session-based Authentication</strong></h3><p>In the world of session-based authentication, the traditional interplay of cookies and server-side sessions takes center stage. As users log in, a session is established on the server, associating a unique identifier with their client-side session cookie. This approach offers a sense of familiarity and control, allowing for nuanced management of user data.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tp9V2g1qeFrYEfIWzqHFyw.png" /><figcaption>Session based authentication flow</figcaption></figure><h4><strong>Pros</strong></h4><p>1. <strong>Enhanced Control:</strong> With server-side sessions, there’s a higher degree of control over user data, making it suitable for applications with complex authorization requirements.</p><p>2. <strong>Simplified Token Management:</strong> Session-based authentication doesn’t require explicit management of tokens on the client-side, reducing potential security risks.</p><h4>Cons</h4><p>1. <strong>Server Dependency:</strong> Relying on server-side storage can introduce scalability challenges, especially in scenarios with a growing user base.</p><p>2. <strong>Potential Performance Impact:</strong> Managing sessions on the server can lead to performance issues, particularly when handling a large number of concurrent users.</p><h4>Example in nodejs with express-session</h4><pre>// Handling login and setting session with express-session<br><br>const express = require(&#39;express&#39;);<br>const session = require(&#39;express-session&#39;);<br>const app = express();<br>const port = 3000;<br><br>app.use(express.json());<br>app.use(session({ secret: &#39;your-secret-key&#39;, resave: true, saveUninitialized: true }));<br><br>app.post(&#39;/api/login&#39;, (req, res) =&gt; {<br>  // Validate user credentials (not shown for brevity)<br>  <br>  // Set session on successful login<br>  req.session.userID = &#39;uniqueID&#39;;<br>  <br>  res.status(200).send(&#39;Login successful&#39;);<br>});<br><br>app.listen(port, () =&gt; console.log(`Server is running on port ${port}`));</pre><h3><strong>JSON Web Tokens (JWTs)</strong></h3><p>On the other side of the spectrum, we have JSON Web Tokens (JWTs) offering a stateless and decentralized approach to authentication. JWTs, compact tokens containing user information, are generated on the server and sent to the client upon successful authentication. Subsequent requests include this token, enabling the server to verify the user’s identity without the need for server-side storage.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KbrI5oHv309b-_233jO5hw.png" /><figcaption>JWT flow</figcaption></figure><h4>Pros</h4><p>1. <strong>Stateless Nature:</strong> JWTs introduce a stateless architecture, providing scalability and flexibility by eliminating the need for server-side session storage.</p><p>2. <strong>Decentralized Authorization:</strong> Unlike session-based authentication, JWTs don’t require the server to store session data, allowing for decentralized authorization.</p><h4><strong>Cons</strong></h4><p>1. <strong>Token Size Concerns:</strong>The size of JWTs can become a consideration, particularly in scenarios where minimizing payload size is crucial.</p><p>2. <strong>Token Revocation Challenges:</strong> Revoking individual tokens can be challenging, requiring additional strategies to manage potential security risks.</p><h4>Example in nodejs</h4><pre>// Handling login and generating JWT<br><br>const express = require(&#39;express&#39;);<br>const jwt = require(&#39;jsonwebtoken&#39;);<br>const app = express();<br>const port = 3000;<br><br>app.use(express.json());<br><br>app.post(&#39;/api/login&#39;, (req, res) =&gt; {<br>  // Validate user credentials (not shown for brevity)<br>  <br>  // Generate JWT on successful login<br>  const token = jwt.sign({ userID: &#39;uniqueID&#39; }, &#39;your-secret-key&#39;, { expiresIn: &#39;1h&#39; });<br>  <br>  res.status(200).json({ token });<br>});<br><br>app.listen(port, () =&gt; console.log(`Server is running on port ${port}`));</pre><h3>Security best practices</h3><p>Ensuring the security of your application goes beyond choosing the right authentication mechanism. Let’s touch upon some best practices to safeguard against common vulnerabilities.</p><ul><li><strong>HTTPS Usage</strong>: Always use HTTPS to encrypt data transmission between the client and server, preventing eavesdropping and man-in-the-middle attacks.</li><li><strong>Token Encryption</strong>: Consider encrypting the token payload to protect sensitive user information, especially in scenarios where the token needs to be stored on the client.</li><li><strong>Token Expiration and Renewal</strong>: Set reasonable expiration times for tokens to minimize the window of opportunity for malicious actors. Implement token renewal strategies for seamless user experiences.</li><li><strong>XSS Prevention</strong>: Sanitize and validate user input, and use Content Security Policy (CSP) headers.</li><li><strong>CSRF Prevention</strong>: Prevention of CSRF attacks typically requires the use of an anti-CSRF token or SameSite cookies.</li></ul><h3><strong>A Comparative Overview</strong></h3><p>When comparing session-based authentication and JWTs, the decision ultimately hinges on your application’s unique requirements.</p><p><strong>For applications where control over user data is paramount and the server-side storage is manageable, session-based authentication shines. It simplifies token management and aligns well with scenarios where complex authorization rules are in play. Example: banking, healthcare.</strong></p><p><strong>On the flip side, if your application requires a scalable, stateless approach with decentralized authorization, JWTs offer an elegant solution. Despite concerns about token size, the flexibility and efficiency of stateless authentication make JWTs a compelling choice. Example: SPAs, social media applications.</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=92e7b7f0a647" width="1" height="1" alt=""><hr><p><a href="https://blog.devgenius.io/quick-guide-comparing-session-authentication-and-jwts-in-web-development-92e7b7f0a647">Quick guide: Comparing Session Authentication and JWTs in web development</a> was originally published in <a href="https://blog.devgenius.io/">Dev Genius</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[An Introduction to Playwright]]></title>
            <link>https://blog.stackademic.com/an-introduction-to-playwright-6d45dc0d7268?source=rss-df77bef746c2------2</link>
            <guid isPermaLink="false">https://medium.com/p/6d45dc0d7268</guid>
            <category><![CDATA[web]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[playwright-test]]></category>
            <category><![CDATA[testing]]></category>
            <category><![CDATA[front-end-development]]></category>
            <dc:creator><![CDATA[Aakash Thakur]]></dc:creator>
            <pubDate>Tue, 29 Aug 2023 12:16:31 GMT</pubDate>
            <atom:updated>2024-09-07T08:12:27.863Z</atom:updated>
            <content:encoded><![CDATA[<p>End-to-end tests made easy</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*RmwNOg2jb30tpCwe" /><figcaption>Photo by <a href="https://unsplash.com/@dtravisphd?utm_source=medium&amp;utm_medium=referral">David Travis</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>When building any user interface, it’s essential that we not just work on the features but also make sure that we make them fail-safe before hitting production. One of the tools that can help us with end-to-end tests is what we are going to discuss in this post.</p><h3>What is Playwright</h3><p>Playwright is a platform which we can use to help us with end-to-end testing. It supports all modern rendering engines including Chromium, WebKit, and Firefox.</p><p>Installation (can use npm, yarn, or pnpm, refer to <a href="https://playwright.dev/docs/intro#installing-playwright">docs</a> for more info):</p><p>Create a folder, cd into it and run below command:</p><p>pnpm create playwright</p><p>Select the following options:</p><pre>✔ Do you want to use TypeScript or JavaScript? · TypeScript<br>✔ Where to put your end-to-end tests? · e2e<br>✔ Add a GitHub Actions workflow? (y/N) · false<br>✔ Install Playwright browsers (can be done manually via &#39;pnpm exec playwright install&#39;)? (Y/n) · true</pre><p>Playwright will download the browsers needed as well as create the following files:</p><ul><li>playwright.config.ts</li><li>package.json</li><li>package-lock.json</li><li>e2e/example.spec.ts</li><li>tests-examples/demo-todo-app.spec.ts</li></ul><h4>What are these files exactly:</h4><ul><li>playwright.config.ts - This is where you can add configuration for Playwright, including modifying which browsers you would like to run Playwright on.</li><li>package.json</li><li>package-lock.json</li><li>e2e folder - As part of the installation steps, this is where our tests will reside.</li><li>tests-examples - This has a starter template which we will use to describe scenarios in this post. You can either delete this file or keep it for your reference.</li></ul><h3>Adding scripts</h3><p>Go ahead and add these scripts in package.json:</p><pre>&quot;scripts&quot;: {<br>  &quot;e2e&quot;: &quot;pnpm exec playwright test&quot;, // Runs the end-to-end tests.<br>  &quot;e2e:ui&quot;: &quot;pnpm exec playwright test --ui&quot;, // Starts the interactive UI mode.<br>}</pre><ul><li>npm run e2e - This will run the tests in non-interactive mode, where you won&#39;t be able to watch the tests happening as they occur in the background. At the end, you&#39;ll see the tests passing or failing on the terminal itself.</li><li>npm run e2e:ui - This will run the tests in interactive mode, where you can run tests as you like, either one at a time or all at once. It also has a lot of other capabilities; refer to the documentation for more information.</li></ul><h3>Adding tests</h3><p>Delete everything inside example.spec.ts file and add the following code:</p><pre>// example.spec.ts<br><br>import { test, expect } from &quot;@playwright/test&quot;;<br><br>const TODO_ITEMS = [<br>  &quot;learn react&quot;,<br>  &quot;learn nextjs&quot;,<br>];<br><br>test(&quot;should allow me to add todo items&quot;, async ({ page }) =&gt; {<br>  // go to url<br>  await page.goto(&quot;https://demo.playwright.dev/todomvc&quot;);<br><br>  // create a new todo locator<br>  const newTodo = page.getByPlaceholder(&quot;What needs to be done?&quot;);<br><br>  // Create 1st todo.<br>  await newTodo.fill(TODO_ITEMS[0]);<br>  await newTodo.press(&quot;Enter&quot;);<br><br>  // Make sure the list only has one todo item.<br>  await expect(page.getByTestId(&quot;todo-title&quot;)).toHaveText([TODO_ITEMS[0]]);<br>});</pre><p>Here’s what this test does:</p><ul><li>Declared a mock todo items array</li><li>Added a test to check whether we are able to add items in todo list</li></ul><pre>test(&quot;should allow me to add todo items&quot;, async ({ page }) =&gt; {<br> ...<br>}</pre><ul><li>Visit url to test</li></ul><pre>await page.goto(&quot;https://demo.playwright.dev/todomvc&quot;);</pre><ul><li>Grab hold of the input element here</li></ul><pre>const newTodo = page.getByPlaceholder(&quot;What needs to be done?&quot;);</pre><ul><li>Fill input element from last step with first item from todo array and press enter to add it to the list</li></ul><pre>await newTodo.fill(TODO_ITEMS[0]);<br>await newTodo.press(&quot;Enter&quot;);</pre><ul><li>Assert by comparing the item added with the first item in the list</li></ul><pre>await expect(page.getByTestId(&quot;todo-title&quot;)).toHaveText([TODO_ITEMS[0]]);</pre><p>You can add more items to the todo array and repeat last two steps to check whether multiple items are getting added as expected or not.</p><p>Execute npm run e2e now to see the test file example.spec.ts running. You should see the test case passing.</p><h3>Test report</h3><p>To get the report for the test runs, run this command:</p><pre>npx playwright show-report</pre><p>You should see a test report generated.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*fXAHUn5r9gYZ7Ino" /></figure><p>Test we ran was executed on 3 environments as per default configuration in playwright.config file. Expand first chromium version to see the steps executed:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*5WTFypQHygcL5nk-" /></figure><p>You can expand individual steps to look into them further.</p><h3>Closing notes</h3><p>Playwright tests are simple; they <strong>perform actions and assert the state against expectations</strong>, as demonstrated in our test above. This is just a starting point of how you can get started with Playwright. Playwright is a powerful tool when it comes to automation testing, and there are more interesting aspects we’ll explore in the future. I recommend giving it a try and seeing the value it brings.</p><p>Also, if you are using VSCode, there’s a useful plugin that can help you run Playwright Test tests in Visual Studio Code. Here’s the link: <a href="https://marketplace.visualstudio.com/items?itemName=ms-playwright.playwright">Playwright Test Runner</a>.</p><ul><li><a href="https://playwright.dev/">Fast and reliable end-to-end testing for modern web apps | Playwright</a></li><li><a href="https://marketplace.visualstudio.com/items?itemName=ms-playwright.playwright">Playwright Test for VSCode - Visual Studio Marketplace</a></li></ul><p><em>Thank you for reading until the end. Please consider following the writer and this publication. Visit </em><a href="https://stackademic.com/"><strong><em>Stackademic</em></strong></a><em> to find out more about how we are democratizing free programming education around the world.</em></p><figure><a href="http://buymeacoffee.com/aakashdevsky"><img alt="" src="https://cdn-images-1.medium.com/max/720/1*-hLwYg1WhQSvzEdEAFaI6Q.jpeg" /></a></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6d45dc0d7268" width="1" height="1" alt=""><hr><p><a href="https://blog.stackademic.com/an-introduction-to-playwright-6d45dc0d7268">An Introduction to Playwright</a> was originally published in <a href="https://blog.stackademic.com/">Stackademic</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Getting Started with Container Queries]]></title>
            <link>https://javascript.plainenglish.io/getting-started-with-container-queries-43c921f832bc?source=rss-df77bef746c2------2</link>
            <guid isPermaLink="false">https://medium.com/p/43c921f832bc</guid>
            <category><![CDATA[responsive-design]]></category>
            <category><![CDATA[css]]></category>
            <category><![CDATA[web-design]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[html-css]]></category>
            <dc:creator><![CDATA[Aakash Thakur]]></dc:creator>
            <pubDate>Tue, 17 Jan 2023 09:16:23 GMT</pubDate>
            <atom:updated>2023-01-17T09:16:23.488Z</atom:updated>
            <content:encoded><![CDATA[<p>Media queries on steroids</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*2sF0Vn4ppaPt0syh" /><figcaption>Photo by <a href="https://unsplash.com/@domenicoloia?utm_source=medium&amp;utm_medium=referral">Domenico Loia</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Container queries, also known as element queries, are a feature of CSS that allows developers <strong>to apply styles to elements based on the size of their containing block, rather than the size of the element itself</strong>. This allows for more flexible and responsive design, as the styles of an element can change based on the size of its parent container.</p><h4>Container queries/Media Queries — how they compare</h4><p>Media queries and container queries are both used to apply styles based on the size of the viewport or an element, respectively.</p><p>Media queries are used to apply styles based on the size of the viewport, such as the width and height of the screen. They allow developers to create responsive designs that adapt to different screen sizes and orientations. Media queries are widely supported by web browsers and are a standard feature of CSS.</p><p>Container queries, on the other hand, are used to apply styles based on the size of an element, such as the width and height of a specific container. They allow developers to create more dynamic and flexible designs that adapt to the size of the surrounding elements. Container queries are not yet widely supported by web browsers, but they are being developed and are being considered as a future feature of CSS.</p><p><strong>In summary, Media queries allow developers to create responsive designs that adapt to different screen sizes and orientations, while container queries allow developers to create more dynamic and flexible designs that adapt to the size of the surrounding elements.</strong></p><h4>Using container queries</h4><p>To use container queries, you need to declare a containment context. To do this, use the <a href="https://developer.mozilla.org/en-US/docs/Web/CSS/container-type">container-type</a> property a value of size, inline-size, or normal. These values have the following effects:</p><ul><li><strong>size</strong>: the query will be based on the <a href="https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Logical_Properties/Basic_concepts#block_and_inline_dimensions">inline and block</a> dimensions of the container. Applies layout, style, and size containment to the container.</li><li><strong>inline-size</strong>: the query will be based on the <a href="https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Logical_Properties/Basic_concepts#block_and_inline_dimensions">inline</a> dimensions of the container. Applies layout, style, and inline-size containment to the element.</li><li><strong>normal</strong>: The element is not a query container for any container size queries, but remains a query container for container style queries.</li></ul><p>Consider this HTML:</p><pre>&lt;div class=&quot;parent&quot;&gt;<br>  &lt;header&gt;<br>    &lt;img class=&quot;avatar&quot; src=&quot;./img.png&quot; alt=&quot;Image&quot;&gt;<br>    &lt;h1&gt;User&lt;/h1&gt;<br>  &lt;/header&gt;<br>  &lt;p&gt;Lorem Ipsum….&lt;/p&gt;<br>&lt;/div&gt;</pre><p>We can use container type property here to create containment context:</p><pre>.parent{<br>   container-type: inline-size;<br>}</pre><p>Now we can use <strong>@container</strong> context to write container query:</p><pre>header img{<br> width:50%;<br>}<br><br>/* Container query applied if the container is larger than 700px */<br>@container (min-width: 700px) {<br>  header img {<br>    width:100%;<br>  }<br>}</pre><p>We can also name containment contexts to target a specific container with container-name property.</p><pre>.parent {<br>  container-type: inline-size;<br>  container-name: parentContainer;<br>}<br><br>@container parentContainer (min-width: 700px) {<br>  .header img {<br>    width:100%;<br>  }<br>}</pre><p>Shorthand syntax for above:</p><pre>.parent {<br>  container: parentContainer / inline-size;<br>}</pre><h4>Example</h4><p>We’ll be working with a container having two cards to display. Below is the markup:</p><pre>&lt;div class=&quot;container&quot;&gt;<br>  &lt;div class=&quot;card&quot;&gt;<br>    &lt;div class=&quot;card-content&quot;&gt;<br>      &lt;img src=&quot;https://via.placeholder.com/150&quot; alt=&quot;Cat with two different color eyes&quot; /&gt;<br>      &lt;div class=&quot;content&quot;&gt;<br>        &lt;h2&gt;Card title&lt;/h2&gt;<br>        &lt;p&gt;Card content&lt;/p&gt;<br>      &lt;/div&gt;<br>    &lt;/div&gt;<br>  &lt;/div&gt;<br>  &lt;div class=&quot;card&quot;&gt;<br>    &lt;div class=&quot;card-content&quot;&gt;<br>      &lt;img src=&quot;https://via.placeholder.com/150&quot; alt=&quot;Cat with two different color eyes&quot; /&gt;<br>      &lt;div class=&quot;content&quot;&gt;<br>        &lt;h2&gt;Card title&lt;/h2&gt;<br>        &lt;p&gt;Card content&lt;/p&gt;<br>      &lt;/div&gt;<br>    &lt;/div&gt;<br>  &lt;/div&gt;<br> <br>&lt;/div&gt;</pre><p>Here’t the container query specific css:</p><pre><br>.card-content {<br>  border: 1px solid grey;<br>  border-radius:10px;<br>  display:flex;<br>  flex-direction:column;<br>  gap:10px;<br>}<br>.card {<br>  container-type: inline-size;<br>} <br><br><br>/* Container query applied if the container is larger than 300px */<br>@container (min-width: 300px) {<br>  .card-content{<br>    flex-direction: row<br>  }<br>} </pre><p>Basically we’re switching the layout of individual card based on their parent’s width. Cards will be laid out horizontally if width of parent if more than 300px otherwise stay stacked. Please note viewport width is nowhere considered here.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fjsfiddle.net%2F7qwcmx56%2F45%2Fembedded%2F&amp;display_name=jsFiddle&amp;url=http%3A%2F%2Fjsfiddle.net%2F7qwcmx56%2F45%2F&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=jsfiddle" width="600" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/85c466a36550aa944ee1c6576fae7f04/href">https://medium.com/media/85c466a36550aa944ee1c6576fae7f04/href</a></iframe><h4>Browser Support as of now</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JzLkAnEgzrDSlcBQjlUrrA.png" /></figure><p>Source: <a href="https://caniuse.com/css-container-queries">https://caniuse.com/css-container-queries</a></p><h4>Conclusion</h4><p>In this post, we covered the basics around container queries. In the following post, I’ll try to cover container query length units which provides more flexiblility to design better layouts.</p><p><em>More content at </em><a href="https://plainenglish.io/"><strong><em>PlainEnglish.io</em></strong></a><em>. Sign up for our </em><a href="http://newsletter.plainenglish.io/"><strong><em>free weekly newsletter</em></strong></a><em>. Follow us on </em><a href="https://twitter.com/inPlainEngHQ"><strong><em>Twitter</em></strong></a>, <a href="https://www.linkedin.com/company/inplainenglish/"><strong><em>LinkedIn</em></strong></a><em>, </em><a href="https://www.youtube.com/channel/UCtipWUghju290NWcn8jhyAw"><strong><em>YouTube</em></strong></a><em>, and </em><a href="https://discord.gg/GtDtUAvyhW"><strong><em>Discord</em></strong></a><strong><em>.</em></strong></p><p><strong><em>Interested in scaling your software startup</em></strong><em>? Check out </em><a href="https://circuit.ooo/?utm=publication-post-cta"><strong><em>Circuit</em></strong></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=43c921f832bc" width="1" height="1" alt=""><hr><p><a href="https://javascript.plainenglish.io/getting-started-with-container-queries-43c921f832bc">Getting Started with Container Queries</a> was originally published in <a href="https://javascript.plainenglish.io/">JavaScript in Plain English</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[TypeScript Essentials You Should Know]]></title>
            <link>https://javascript.plainenglish.io/typescript-essentials-you-should-know-d026f9e88bc1?source=rss-df77bef746c2------2</link>
            <guid isPermaLink="false">https://medium.com/p/d026f9e88bc1</guid>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[front-end-development]]></category>
            <category><![CDATA[typescript]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Aakash Thakur]]></dc:creator>
            <pubDate>Tue, 19 Apr 2022 11:17:39 GMT</pubDate>
            <atom:updated>2022-04-19T11:17:39.698Z</atom:updated>
            <content:encoded><![CDATA[<h4>Learn these basics to make better use of TypeScript.</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*9tgn7hSm6OPhLT2O" /><figcaption>Photo by <a href="https://unsplash.com/@toddquackenbush?utm_source=medium&amp;utm_medium=referral">Todd Quackenbush</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>This post covers some of the basics of TypeScript which one can consider learning to make better use of the language.</p><h4>Interface and Type</h4><p>In TypeScript, interfaces and types are powerful ways of defining contracts within your code as well as contracts with code outside of your project.</p><p>These are mostly similar with some minor differences in usage and implementation.</p><ol><li><strong>Extending</strong></li></ol><p>Interface:</p><pre><br>interface Animal{<br>  name:string;<br>}</pre><pre>interface Bear <strong>extends Animal</strong>{<br>  honey: boolean;<br>}</pre><pre>const bear: Bear = getBear(); // getBear returns Bear<br>bear.name;<br>bear.honey;</pre><p>Type:</p><pre>type Animal = {<br>  name:string;<br>}</pre><pre>type Bear = Animal <strong>&amp;</strong> {<br>  honey: boolean;<br>}</pre><pre>const bear: Bear = getBear(); // getBear returns Bear<br>bear.name;<br>bear.honey;</pre><p>2. <strong>Modifying fields</strong></p><p>Interface: can add new fields to an existing interface.</p><pre>interface Window{<br>  title:string;<br>}</pre><pre>interface Window{<br>  name:string<br>}</pre><pre>// Now interface Window has both title and name</pre><p>Type: cannot be changed after being created.</p><pre>type Window{<br>  title:string;<br>}</pre><pre>type Window{<br>  name:string<br>}</pre><pre>// Error Duplicate Identifier Window</pre><h4>keyof type operator</h4><p>This operator takes an object and produces a string or numeric literal union of its key.</p><pre>type Person = { name: string, age: number }<br>type PersonType = keyof Person; // name | age</pre><h4>typeof type operator</h4><p>typeof can be used in a type context to refer to the type of a variable or property.</p><pre>Example 1: <br>let name = &#39;John&#39;;<br>let NType: typeof name; // NType is string</pre><pre><br>Example 2:<br>let person = {<br>  code:&quot;1&quot;, name:&quot;Rahul&quot;<br>}</pre><pre>let employee: <strong>typeof</strong> person;</pre><pre>employee = { code:&quot;2&quot;, name:&quot;Sachin&quot;};    <em>//OK</em></pre><pre>employee = { code: &quot;2&quot;, name: &quot;Sachin&quot;, salary: 1000 }; <em>// </em><strong><em>ErrorType &#39;{ code: string; name: string; salary: number; }&#39; is not assignable to type &#39;{ code: string; name: string; }&#39;</em></strong></pre><h4>Indexed Access Type</h4><p>We can use this type to look up a specific property on another type.</p><pre>type Person = { name: string, age: number, isMale: boolean };</pre><pre>type PType = Person[keyof Person]; <br>// string | number | boolean</pre><h4>Mapped type</h4><p>Can be used to create a type based on another type.</p><pre>type OptionalFlags&lt;T&gt; = {<br>    [Property in keyof T]:boolean;<br>}</pre><pre>type FeatureFlags = {<br>    darkMode: () =&gt; void;<br>    profile: () =&gt; void;<br>}</pre><pre>type FeatureOptions = OptionalFlags&lt;FeatureFlags&gt;;<br>// { darkMode: boolean, profile: boolean }</pre><h4>Mapping modifiers</h4><p>There are two additional modifiers that can be applied during mapping: readonly and ? which affect mutability and optionality respectively.</p><p>You can remove or add these modifiers by prefixing them with - or +. If you don’t add a prefix, then + is assumed.</p><pre>// Removes &#39;readonly&#39; attributes from a type&#39;s properties</pre><pre>type CreateMutable&lt;T&gt; = {<br>    -readonly[Property in keyof T]:T[Property]<br>}</pre><pre>type LockedAccount = {<br>    readonly id: string;<br>    readonly name: string;<br>}</pre><pre>type UnlockedAccount = CreateMutable&lt;LockedAccount&gt;;<br>// { id: string; name: string } <br><strong>// notice readonly has been removed</strong></pre><h4>Key remapping via “as”</h4><p>In TypeScript 4.1 and onwards, you can re-map keys in mapped types with an as clause in a mapped type:</p><pre><strong>type MappedWithNewProperties&lt;T&gt; = {<br>    [Properties in keyof T as NewKeyType]: T[Properties]<br>}</strong></pre><p>E.g.</p><pre>type Getters&lt;T&gt; = {<br>  [Property in keyof T as `get${Capitalize&lt;string &amp; Property&gt;}`]: () =&gt; T[Property]<br>};</pre><pre>interface Person {<br>    name: string;<br>    age: number;<br>}</pre><pre>type LazyPerson = Getters&lt;Person&gt;;<br>// { getName: () =&gt; string; getAge: () =&gt; number }</pre><p>That’s it for this topic. Thank you for reading.</p><p><a href="https://www.typescriptlang.org/docs/">The starting point for learning TypeScript</a></p><p><em>More content at </em><a href="https://plainenglish.io/"><strong><em>PlainEnglish.io</em></strong></a><em>. Sign up for our </em><a href="http://newsletter.plainenglish.io/"><strong><em>free weekly newsletter</em></strong></a><em>. Follow us on </em><a href="https://twitter.com/inPlainEngHQ"><strong><em>Twitter</em></strong></a><em> and </em><a href="https://www.linkedin.com/company/inplainenglish/"><strong><em>LinkedIn</em></strong></a><em>. Join our </em><a href="https://discord.gg/GtDtUAvyhW"><strong><em>community Discord</em></strong></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d026f9e88bc1" width="1" height="1" alt=""><hr><p><a href="https://javascript.plainenglish.io/typescript-essentials-you-should-know-d026f9e88bc1">TypeScript Essentials You Should Know</a> was originally published in <a href="https://javascript.plainenglish.io/">JavaScript in Plain English</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Git Merging Strategies: A Simple Explanation and Guide]]></title>
            <link>https://javascript.plainenglish.io/git-merging-strategies-a-simple-explanation-and-guide-9e7e508b369c?source=rss-df77bef746c2------2</link>
            <guid isPermaLink="false">https://medium.com/p/9e7e508b369c</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[git]]></category>
            <category><![CDATA[github]]></category>
            <category><![CDATA[front-end-development]]></category>
            <dc:creator><![CDATA[Aakash Thakur]]></dc:creator>
            <pubDate>Mon, 01 Nov 2021 08:52:38 GMT</pubDate>
            <atom:updated>2024-09-07T08:14:02.669Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*OhOmOqMLFyM1OY5Q" /><figcaption>Photo by <a href="https://unsplash.com/@kingimaging?utm_source=medium&amp;utm_medium=referral">Loren King</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>All of us who have worked on git as a version control system must have come across these two merging strategies: <strong>fast-forward merge and merge made by recursive strategy</strong>.</p><p>But oftentimes, since most of the things are taken care of by git itself, we do not exactly get an idea of what might have happened in terms of git history, or at least that’s what the case has been with me. Every time I saw messages like “fast-forward” or “merge made by recursive strategy” I wondered what that meant. In this article, I’ll try to explain what these merge strategies mean and I hope it clears some air for you guys as well.</p><h3>The example we are working with</h3><p>Here’s the git tree that we will be working with, in this article.</p><pre>master       m1  m2</pre><pre>feature      m1  m2  f1  f2</pre><p>Let’s take master as our main branch from which we would branch out and feature as the new branch from master.</p><p>Initial commits in master are m1 and m2, after which a new branch feature is checked out which further has f1 and f2 commits.</p><h3>Fast forward merge</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*44He7mhmqKp7fl8U" /><figcaption>Photo by <a href="https://unsplash.com/@kydroon?utm_source=medium&amp;utm_medium=referral">Kurt Cotoaga</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>In fast forward merge, if <strong>master</strong> doesn’t have any changes after branching out <strong>feature</strong>, on merging to master no merge commit are created, instead all feature commits are placed above the master ones.</p><p>For e.g., if in the above example, we run “git merge feature” on master, next state would be something like this:</p><pre>master       m1  m2  f1  f2</pre><blockquote><strong>Note:</strong> In case if you have multiple commits in feature branch and you’d like to combine them into one before merging to master, you can run:<br><strong>“git merge --squash feature”,</strong> this would prompt you for a commit message and the state would look like:</blockquote><pre>master        m1  m2  “single commit”</pre><blockquote>Here “single commit” is the message we provided on running squash command(both f1 and f2 are part of this commit).</blockquote><h3>Non fast-forward merge(Recursive Strategy)</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*T6kmIc9A3DKvXinR" /><figcaption>Photo by <a href="https://unsplash.com/@seimesa?utm_source=medium&amp;utm_medium=referral">Mario Mesaglio</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>This strategy is employed by git when <strong>master</strong> has evolved and has newer commits(probably due to some other branch getting merged) since the time <strong>feature</strong> was created from <strong>master</strong>. In this case initial tree would be:</p><pre>master       m1  m2  m3</pre><pre>feature      m1  m2  f1  f2</pre><p>If you see, m3 is the new commit in master and if we now run “git merge feature” on <strong>master</strong>, all commits of <strong>feature</strong> branch are played on top of <strong>master</strong> and one merge commit is created as well. This is different from fast forward merge in the additional commit creation.</p><p>Here’s the new state after merge:</p><pre>master       m1  m2  f1  f2  m3  &quot;merge commit of feature branch&quot;</pre><p><strong><em>While git would automatically perform this type of merge strategy if master has evolved, if we explicitly want to do it, we can run “git merge --no-ff feature”.</em></strong></p><blockquote><strong>Note:</strong> In case if you have multiple commits in feature branch and you’d like to combine them into one before merging to master, you can run:<br>“<strong>git merge --squash feature</strong>”, this would prompt you for a commit message and the state would look be:</blockquote><pre>master        m1  m2  m3  “single commit”</pre><blockquote>Here “single commit” is the message we provided on running squash command (both f1 and f2 are part of this commit).</blockquote><h3>Resources</h3><ul><li><a href="https://www.tutorialspoint.com/what-is-a-fast-forward-merge-in-git">What is a fast-forward merge in Git?</a></li><li><a href="https://www.atlassian.com/git/tutorials/using-branches/git-merge">Git Merge | Atlassian Git Tutorial</a></li></ul><p><em>More content at </em><a href="http://plainenglish.io/"><strong><em>plainenglish.io</em></strong></a></p><figure><a href="http://buymeacoffee.com/aakashdevsky"><img alt="" src="https://cdn-images-1.medium.com/max/720/1*-hLwYg1WhQSvzEdEAFaI6Q.jpeg" /></a></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9e7e508b369c" width="1" height="1" alt=""><hr><p><a href="https://javascript.plainenglish.io/git-merging-strategies-a-simple-explanation-and-guide-9e7e508b369c">Git Merging Strategies: A Simple Explanation and Guide</a> was originally published in <a href="https://javascript.plainenglish.io/">JavaScript in Plain English</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Array.at() Will Change How We Access Array Values in JavaScript]]></title>
            <link>https://javascript.plainenglish.io/array-at-will-change-how-we-access-array-values-in-javascript-517c3a13d505?source=rss-df77bef746c2------2</link>
            <guid isPermaLink="false">https://medium.com/p/517c3a13d505</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[front-end-development]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[software-development]]></category>
            <dc:creator><![CDATA[Aakash Thakur]]></dc:creator>
            <pubDate>Sun, 20 Jun 2021 14:08:35 GMT</pubDate>
            <atom:updated>2024-09-07T08:13:20.333Z</atom:updated>
            <content:encoded><![CDATA[<h4>How to access negative indexes in JavaScript, and how this could change with Array.prototype.at()</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*wxnYxo_0eH2ADFJd" /><figcaption>Photo by <a href="https://unsplash.com/@lastnameeaster?utm_source=medium&amp;utm_medium=referral">La-Rel Easter</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>There are times when I felt a dire need to access array elements from reverse, maybe the last item or the second last.</p><p>The way to go about it was never straightforward like it is in some other languages where you can just say array[-1] and it gives you the last item.</p><p>Instead we have to do things like array[array.length-1] and so on.</p><p>The [] syntax is not specific to Arrays and Strings; it applies to all objects. Referring to a value by index, like array[1], actually just refers to the property of the object with the key 1, which is something that any object can have. So array[-1] already “works” in today’s code, but it returns the value of the -1 property of the object, rather than returning an index counting backwards from the end.</p><h4>Accessing elements</h4><p>Trying to get a value for an index which isn’t present in the array will return undefined in JavaScript.</p><pre>const arr=[&#39;a&#39;, &#39;b&#39;, &#39;c&#39;, &#39;d&#39;, &#39;e&#39;];</pre><pre>arr[1] // b</pre><pre>arr[4] // e</pre><pre>arr[-1] // undefined</pre><p>What are the options here to access the last element, currently we can do arr[arr.length — 1] or arr.slice(-1)[0] and this would give us e as an output for the above array.</p><h4>Proposed Property — “at”</h4><p>With this new property, accessing elements in array is going to become convenient going forward.</p><p>The way we access values isn’t going to change with <strong>at</strong> but accessing negative indexes will become easy. Here’s how it would look:</p><pre>const arr=[&#39;a&#39;, &#39;b&#39;, &#39;c&#39;, &#39;d&#39;, &#39;e&#39;];</pre><pre>arr.at(1) // b</pre><pre>arr.at(4) // e</pre><pre>arr.at(-1) // e</pre><pre>arr.at(10) // undefined</pre><h4>Conclusion</h4><p>Hopefully this will move forward to Stage 4 soon and be officially adopted. I am quite excited about this one and can see this becoming a syntactic sugar for accessing array elements.</p><p>There’s also a <a href="https://github.com/tc39/proposal-array-last"><strong>last</strong></a> property being in discussion (accessing last element of an array/string) but it’s still in stage 1 and might well be dropped in favour of this new property <a href="https://github.com/tc39/proposal-relative-indexing-method"><strong>at</strong></a> as it’s already stage 3 and solves the same purpose and much more.</p><ul><li><a href="https://github.com/tc39/proposal-relative-indexing-method">GitHub - tc39/proposal-relative-indexing-method: A TC39 proposal to add an .at() method to all the basic indexable classes (Array, String, TypedArray)</a></li><li><a href="https://github.com/tc39/proposal-array-last">tc39/proposal-array-last</a></li></ul><p><em>More content at </em><a href="http://plainenglish.io/"><strong><em>plainenglish.io</em></strong></a></p><figure><a href="http://buymeacoffee.com/aakashdevsky"><img alt="" src="https://cdn-images-1.medium.com/max/720/1*-hLwYg1WhQSvzEdEAFaI6Q.jpeg" /></a></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=517c3a13d505" width="1" height="1" alt=""><hr><p><a href="https://javascript.plainenglish.io/array-at-will-change-how-we-access-array-values-in-javascript-517c3a13d505">Array.at() Will Change How We Access Array Values in JavaScript</a> was originally published in <a href="https://javascript.plainenglish.io/">JavaScript in Plain English</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[6 Quirky JavaScript and CSS Tricks You Should Know]]></title>
            <link>https://javascript.plainenglish.io/6-quirky-javascript-and-css-tricks-you-should-know-a17c59c7ef22?source=rss-df77bef746c2------2</link>
            <guid isPermaLink="false">https://medium.com/p/a17c59c7ef22</guid>
            <category><![CDATA[html]]></category>
            <category><![CDATA[front-end-development]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[css]]></category>
            <category><![CDATA[web-development]]></category>
            <dc:creator><![CDATA[Aakash Thakur]]></dc:creator>
            <pubDate>Sun, 14 Feb 2021 16:35:38 GMT</pubDate>
            <atom:updated>2024-09-07T08:14:31.315Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*NRaTRWUtOyy5maRL" /><figcaption>Photo by <a href="https://unsplash.com/@acharki95?utm_source=medium&amp;utm_medium=referral">Aziz Acharki</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>I have lately come across a lot of JS and CSS tricks post and today I have compiled a list of my own. I hope you learn something from these.</p><h4><strong>1. Optionally add JS property</strong></h4><p>Quite often we have keys in objects that are dynamic in nature and whether they make it to the final object is dependent on a condition.</p><p>For example, let’s say we have a tracking event function and one of the parameters is optional. If it’s there we would like to include it in the tracking object otherwise not have that property only.</p><pre>// title is optional here<br>function sendTrackingEvent(status, title, pageName) {</pre><pre>    const obj = {<br>         status,<br>         pageName,<br>     };</pre><pre>     if (title) {<br>          obj[&quot;title&quot;] = title;<br>     }<br>     trackPageview(obj);<br>}</pre><p>That’s one way to add a check and add property, but there’s an even better way to add property conditionally and that’s with spread operator. Here’s the same example:</p><pre>function sendTrackingEvent(status, title, pageName){<br>     const obj = {<br>         status,<br>         pageName,<br>         ...(title &amp;&amp; {title: title})<br>     }<br>     trackPageview(obj);<br>}</pre><h4>2. <strong>Responsive layout with css grid</strong></h4><p>The most useful line of code that I find pretty handy from CSS grid is:</p><pre>grid-template-columns: repeat(auto-fill, minmax(minValue, maxValue));</pre><blockquote>Each parameter for minmax can be a &lt;length&gt;, a &lt;percentage&gt;, a &lt;flex&gt; value, or one of the keyword values max-content, min-content, or auto.</blockquote><p>Without any media queries, this will set up a grid container that has a flexible number of columns. The columns will stretch a little, until there is enough room for another one, and then a new column is added, and in reverse.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1w_873UVvbWCyF7m8xSWiQ.gif" /></figure><p>Here’s a working sandbox: <a href="https://codesandbox.io/s/quizzical-carson-7iqjp">https://codesandbox.io/s/quizzical-carson-7iqjp</a></p><h4>3. <strong>Dynamic property names</strong></h4><p>You can assign dynamic property while declaring the object.</p><pre>const dynamic = &#39;color&#39;;<br>var item = {<br>    brand: &#39;Ford&#39;,<br>    <strong>[dynamic]</strong>: &#39;Blue&#39;<br>}</pre><pre>console.log(item); // { brand: &quot;Ford&quot;, color: &quot;Blue&quot; }</pre><h4>4. <strong>Truncate string</strong></h4><p>The text-overflow property specifies how overflowed content that is not displayed should be signaled to the user. It can be clipped, display an ellipsis (…), or display a custom string</p><p>Both of the following properties are required for text-overflow:</p><ul><li>white-space: nowrap;</li><li>overflow: hidden;</li></ul><p>Working example can be seen here: <a href="https://www.w3schools.com/csSref/tryit.asp?filename=trycss3_text-overflow">https://www.w3schools.com/csSref/css3_pr_text-overflow.asp</a></p><h4>5. <strong>Reading browser URL</strong></h4><p>JavaScript can access the current URL in parts. We can get the protocol, pathname, host and search params. For this URL:</p><p><strong>https://example.com/xyz/index.html?page=1</strong></p><ul><li>window.location.protocol = “https:”</li><li>window.location.host = “example.com”</li><li>window.location.pathname = “/xyz/index.html”</li><li>window.location.search = “?page=1”</li></ul><h4>6. <strong>CSS counters</strong></h4><p>To style numbers in a numbered list, we need to play with properties called CSS counters. CSS counters let you adjust the appearance of content based on its location in a document</p><p>To use CSS counters:</p><ul><li>The counters’ value can be increased or decreased by counter-increment</li><li>We can display the value of the counter by using the counter() or counters() function from within a content property</li></ul><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcodepen.io%2FSky-123%2Fembed%2Fpreview%2FyLVgvao%3Fheight%3D600%26slug-hash%3DyLVgvao%26default-tabs%3Dhtml%2Cresult%26host%3Dhttps%3A%2F%2Fcodepen.io&amp;display_name=CodePen&amp;url=https%3A%2F%2Fcodepen.io%2FSky-123%2Fpen%2FyLVgvao&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=codepen" width="800" height="600" frameborder="0" scrolling="no"><a href="https://medium.com/media/b16023591655326db0789d1e2b9cba6b/href">https://medium.com/media/b16023591655326db0789d1e2b9cba6b/href</a></iframe><h4>Further Reading</h4><p><a href="https://differ.blog/p/rarely-used-css-properties-and-their-relevance-f68de4">Rarely Used CSS Properties and Their Relevance</a></p><figure><a href="http://buymeacoffee.com/aakashdevsky"><img alt="" src="https://cdn-images-1.medium.com/max/720/1*-hLwYg1WhQSvzEdEAFaI6Q.jpeg" /></a></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a17c59c7ef22" width="1" height="1" alt=""><hr><p><a href="https://javascript.plainenglish.io/6-quirky-javascript-and-css-tricks-you-should-know-a17c59c7ef22">6 Quirky JavaScript and CSS Tricks You Should Know</a> was originally published in <a href="https://javascript.plainenglish.io/">JavaScript in Plain English</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Flipping card on hover CSS]]></title>
            <link>https://blog.devgenius.io/flipping-card-on-hover-css-8b57043e1dcc?source=rss-df77bef746c2------2</link>
            <guid isPermaLink="false">https://medium.com/p/8b57043e1dcc</guid>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[css]]></category>
            <category><![CDATA[html]]></category>
            <category><![CDATA[animation]]></category>
            <category><![CDATA[frontend]]></category>
            <dc:creator><![CDATA[Aakash Thakur]]></dc:creator>
            <pubDate>Thu, 29 Oct 2020 13:18:50 GMT</pubDate>
            <atom:updated>2024-09-07T08:15:08.034Z</atom:updated>
            <content:encoded><![CDATA[<p>CSS <strong>perspective</strong> and <strong>backface-visibility</strong> in action</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*YfUFSQlpcJgPBUeH" /><figcaption>Photo by <a href="https://unsplash.com/@stevewelch?utm_source=medium&amp;utm_medium=referral">Steven Welch</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>In this article, I am going to show you how to flip a card and give it a 3Dish look while rotating. Some CSS terminologies that will come in handy here are perspective and backface-visibiity which I will explain along in the article. So let’s begin.</p><h4>Basic card</h4><p>Here’s the markup that we will be working with. I won’t go into the nitty gritty of this card style as it’s pretty basic stuff.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcodepen.io%2FSky-123%2Fembed%2Fpreview%2FVwjrmzX%3Fheight%3D600%26slug-hash%3DVwjrmzX%26default-tabs%3Dhtml%2Cresult%26host%3Dhttps%3A%2F%2Fcodepen.io&amp;display_name=CodePen&amp;url=https%3A%2F%2Fcodepen.io%2FSky-123%2Fpen%2FVwjrmzX&amp;image=https%3A%2F%2Fassets.codepen.io%2F506210%2Finternal%2Fscreenshots%2Fpens%2FVwjrmzX.default.png%3Ffit%3Dcover%26amp%3Bformat%3Dauto%26amp%3Bha%3Dtrue%26amp%3Bheight%3D360%26amp%3Bquality%3D75%26amp%3Bv%3D2%26amp%3Bversion%3D1603872043%26amp%3Bwidth%3D640&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=codepen" width="800" height="600" frameborder="0" scrolling="no"><a href="https://medium.com/media/9c421b81184d2b5b217c90afa9fcadc3/href">https://medium.com/media/9c421b81184d2b5b217c90afa9fcadc3/href</a></iframe><h4>Flipping the card</h4><p>Flipping the card is as simple as applying a <strong>transform</strong> property to the card. We will achieve this effect on card hover.</p><pre>.card:hover .card-content {<br>    transform: rotateY(180deg);<br>}</pre><p>Adding a transition to smoothen the effect:</p><pre>.card-content {<br>   box-shadow: 0 2rem 2rem rgba(0, 0, 0, .5);<br>   <strong>transition: all 2s;</strong><br>}</pre><p>This is how it would behave on hover:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/598/1*VahXcygNPLmLtVFFigX6TQ.gif" /><figcaption>card animation</figcaption></figure><p>It’s rotating however it lacks in aesthetics. We want it to emulate a real card flip and want it to pop off the screen and give a 3D look. This is where perpective CSS property comes in handy.</p><blockquote><strong>The perspective property is used to give a 3D-positioned element some perspective. It defines how far the object is away from the user.</strong></blockquote><blockquote>Note: When defining the perspective property for an element, it is the CHILD elements that get the perspective view, NOT the element itself.</blockquote><p>Let’s add perspective to card class:</p><pre>.card {<br>    <strong>perspective: 1000px;</strong><br>    width: 300px;<br>}</pre><p>Here a higher value will result in a less intensive 3D effect than a lower value. You can adjust it’s value and see the difference.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcodepen.io%2FSky-123%2Fembed%2Fpreview%2FxxOPOJM%3Fheight%3D600%26slug-hash%3DxxOPOJM%26default-tabs%3Dcss%2Cresult%26host%3Dhttps%3A%2F%2Fcodepen.io&amp;display_name=CodePen&amp;url=https%3A%2F%2Fcodepen.io%2FSky-123%2Fpen%2FxxOPOJM&amp;image=https%3A%2F%2Fassets.codepen.io%2F506210%2Finternal%2Fscreenshots%2Fpens%2FxxOPOJM.default.png%3Ffit%3Dcover%26amp%3Bformat%3Dauto%26amp%3Bha%3Dtrue%26amp%3Bheight%3D360%26amp%3Bquality%3D75%26amp%3Bv%3D2%26amp%3Bversion%3D1603872847%26amp%3Bwidth%3D640&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=codepen" width="800" height="600" frameborder="0" scrolling="no"><a href="https://medium.com/media/e7f9d7a6d217ee6038928d9c29e21866/href">https://medium.com/media/e7f9d7a6d217ee6038928d9c29e21866/href</a></iframe><h3>Adding back side to the card</h3><p>Now we want to show something else once the card is rotated.</p><p>I know some of you reading this article must be cat fans so I thought of adding a cat at the back side of the card. This is how our markup looks like now:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a44f563df4f2e50a97478de35b06477a/href">https://medium.com/media/a44f563df4f2e50a97478de35b06477a/href</a></iframe><p>Just added one more card-content with the cat information for the back side of the card.</p><p>Currently entire card content is laying vertically but what we instead want is to have the card sides on top of each other. Adding some positioning to card-content class will fix this:</p><pre>.card{<br>    <strong>postition:reative;</strong><br>}</pre><pre>.card-content {<br>    box-shadow: 0 2rem 2rem rgba(0, 0, 0, .5);<br>    transition: all 2s;<br>    <strong>position:absolute;<br>    top:0;<br>    left:0;<br>    width:100%;</strong><br>}</pre><p>Now all that is left is to rotate the card sides based on whether it’s on front side or back:</p><pre>.card-back{<br>    transform:rotateY(180deg);//to rotate it towards right<br>}</pre><pre>.card:hover .card-front {<br>    transform: rotateY(-180deg); //to rotate it towards left<br>}</pre><pre>.card:hover .card-back {<br>    transform: rotateY(0);// show backside of card on hover<br>}</pre><p>What we end up getting is not exactly what we expected in the first place. Only the back side of the card is visible even on rotation:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*fp9BchjmSeqeH5Xo4aBpyQ.gif" /><figcaption>card animation</figcaption></figure><p>This is where we can make use of backface-visibility property in CSS.</p><blockquote><strong>The backface-visibility property defines whether or not the back face of an element should be visible when facing the user.</strong></blockquote><p>Adding it to card-content class solves this minor issue:</p><pre>.card-content {<br>    box-shadow: 0 2rem 2rem rgba(0, 0, 0, .5);<br>    transition: all 2s;<br>    position:absolute;<br>    top:0;<br>    left:0;<br>    width:100%;<br>    <strong>backface-visibility: hidden;<br></strong>}</pre><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcodepen.io%2FSky-123%2Fembed%2Fpreview%2FzYBPEdo%3Fheight%3D600%26slug-hash%3DzYBPEdo%26default-tabs%3Dhtml%2Cresult%26host%3Dhttps%3A%2F%2Fcodepen.io&amp;display_name=CodePen&amp;url=https%3A%2F%2Fcodepen.io%2FSky-123%2Fpen%2FzYBPEdo&amp;image=https%3A%2F%2Fassets.codepen.io%2F506210%2Finternal%2Fscreenshots%2Fpens%2FzYBPEdo.default.png%3Ffit%3Dcover%26amp%3Bformat%3Dauto%26amp%3Bha%3Dtrue%26amp%3Bheight%3D360%26amp%3Bquality%3D75%26amp%3Bv%3D2%26amp%3Bversion%3D1603874067%26amp%3Bwidth%3D640&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=codepen" width="800" height="600" frameborder="0" scrolling="no"><a href="https://medium.com/media/151f5ce7978de26bc8ade513d023b80d/href">https://medium.com/media/151f5ce7978de26bc8ade513d023b80d/href</a></iframe><h4>Note on the CSS properties used</h4><p>Please take a note on how the perspective and backface-visibility properties are globally accepted by browsers. Here’s the <a href="https://caniuse.com/">caniuse</a> reference:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cE3v-MbjMP-G3Zcx-vJVPw.png" /><figcaption><a href="https://caniuse.com/?search=perspective">https://caniuse.com/?search=perspective</a></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OT1n_pzAAbgvWRRWChOMaw.png" /><figcaption><a href="https://caniuse.com/?search=backface-visibility">https://caniuse.com/?search=backface-visibility</a></figcaption></figure><p>Keep coding!!</p><figure><a href="http://buymeacoffee.com/aakashdevsky"><img alt="" src="https://cdn-images-1.medium.com/max/720/1*-hLwYg1WhQSvzEdEAFaI6Q.jpeg" /></a></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8b57043e1dcc" width="1" height="1" alt=""><hr><p><a href="https://blog.devgenius.io/flipping-card-on-hover-css-8b57043e1dcc">Flipping card on hover CSS</a> was originally published in <a href="https://blog.devgenius.io/">Dev Genius</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>