While coding, you will notice that there are some things you stumble upon over and over, and normally they beg for that quick solution. A lot of these things do not even need you to install a library to solve it. These are my top 25 collected over the years.
Type check util
Check for empty
Get any list last item
Random number generator with a range
Random id generator
Create a range of numbers
Format JSON string and stringify anything
Execute promise sequentially
Wait for all Promises to complete
Swap array values place
Conditional Object key
Use variables as the object key
Check for key in object
Remove Array duplicates
Destructuring with alias name and default values
Extend class with functions
Extend constructor functions
Make function argument required
Create modules or singletons
Deep clone object
Deep freeze object
The problem with “_typeof_” is that if you use it for some primitives and function it works great but for array and objects it becomes hard to know the difference since they are both considered “objects”
Sometimes you just need to know if something is empty and depending on what you are checking, you need to use different methods like, checking the length, size, or if it contains any child elements. This util unifies all of that.
Sometimes you need to generate random numbers but you want these numbers to be in a range so, you need this small utility.
Just need some id? No need to install a new library for that unless you need some more complex id like UUID. Check these options.
I find myself using this a lot when working on something with NodeJs to log objects to the console. The JSON.stringify takes a third parameter that must be a number of spaces to indent the line with. The second parameter can be null but you can use it to handle things like function, Set, Map, and Symbol that the JSON.stringify method does not handle or simply ignores.
If you have a bunch of asynchronous or normal function that returns a promise that you need to execute one after the other, this utility can help a lot. It takes a list of functions or promises and sequentially resolves them using the array reduce method.
If you ever need to keep checking for data updates but don’t have WebSocket available in your system, this util lets you do just that. It is great for cases where you upload a file and you want to keep checking if the file is done processing, or you are working with a third-party API like dropbox or uber and you want to keep checking whether the process is complete or the ride has reached the destination.
This is not quite a code solution but a good to know about the Promise API. It is constantly evolving and I used to have a code solution for the now available methods “allSettled”, “race” and “any” but I am glad just to tell you about them instead of sharing a code implementation of them.
Article covers: How native is react native?, React Native vs (Ionic, Cordova), Similarities and difference between React Native and Native App Development.
We are providing robust Node.JS Development Services with expert Node.js Developers. Get affordable Node.JS Web Development services from Skenix Infotech.
Have you ever thought of having your own app that runs smoothly over multiple platforms? React Native is an open-source cross-platform mobile application framework which is a great option to create mobile apps for both Android and iOS. **[Hire...