Using AWS S3 functionality in our node application, this issue suddenly broke our functionality for no plausible reason. The strange aspect was that the same thing worked correctly on the local server, but any remote server would throw this error.
[Read More]Yup Date Format Validation With Moment JS
Yup Number Validation: Allow Empty String
With min and max number validation.
Exactly Same Query Behaving Differently in Mongo Client and Mongoose
Understanding Mongoose's strict schema handling
You might notice that the same query behaves differently in a MongoDB client, like Compass or mongo shell, compared to when using Mongoose within a Node.js application. Below is one such scenario.
[Read More]JavaScript Unit Testing JSON Schema Validation
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]Restrict Content for Users of Specific Countries With JavaScript Only
A browser firewall without any backend!
As I have shown in a previous post, we can find the country of the user on the browser with JavaScript only. Using this information, you can restrict your site content for users belonging to specific countries.
[Read More]