Reduce JS Size With Constant Strings

Refactor for micro-optimization of frontend packages, scripts, and bundles.

Do Repeated string literals in the JavaSript codebase increase the final file size? Yes, they do. Does it matter? Not for the backend applications, but for frontend applications – and anything that contributes towards them – it does. For example, npm packages and directly loaded scripts, server-side rendered web applications, and SPAs such as Angular, React, and Vue.

[Read More]

JavaScript SDK

This post discusses SDK, JavaScript/Typescript SDK, its types, benefits, and drawbacks.

[Read More]

JavaScript: Find if the String Has a Particular Case

Helper methods to tell if the case of the string is camel, snake, kebab, upper, lower, or start.

Instead of writing our own logic to determine if the given string is of a particular case or not, we can write a helper method that acts as a wrapper, in which we compare the original string with the one returned by lodash method, and return true or false. The wrapper is a good way to pass on the responsibility of correct logic to lodash, a thoroughly tested library.

[Read More]

Replace All Keys of Deeply Nested Objects or Array of Objects in JavaScript

Change the case of object keys recursively to camel, snake, kebab, upper, lower, and start. Or modify in another way.

For a deeply nested object or array of objects, we might want to replace all the keys in some way, such as modifying their case (camel case, snake case, etc.) or adding an underscore at the start of each key or on both sides. Or we may like to change the keys in any other way.

[Read More]

React JS Render Form With Dynamic Data From Backend API

including field validations

We need to plot a form whose entire fields are coming from the backend. Since the fields are not known in advance, we cannot add them statically. The data about each field, such as its id to save with, name, validations, etc. all comes in the API response too.

For the given scenario, I have used React Hook Form. The demo and example code for a dynamic questionnaire is shared below.

[Read More]

Exclude Yourself From Google Analytics Without Filtering IP Addresses or Using Extensions

Including localhost calls. Works regardless of location, browser, or device.

When you visit your own blog or website, Google Analytics still tracks it as a view, which kind of corrupt your stats a little. If you want to check your site and keep the analytics data clean and legitimate, you must somehow exclude yourself from all the visits on all the pages. [Read More]

JavaScript Find Total Time Duration

Excluding overlapping and idle times

Say we have a an array of objects with start and end times in each. This could be anything, ranging from work experience (the way LinkedIn shows per job), to education, to sports career. We want to sum all these small experiences, excluding overlapping and idle times, and give out the total duration, which can further be converted into years, months, or days. [Read More]
When you purchase through links on techighness.com, I may earn an affiliate commission.