The lodash _.pad, _.padStart, and _.padEnd methods for padding strings in javaScript.

So today I will be putting together another quick post on lodash as well as vanilla js alternatives to using lodash when it comes to the process of quickly padding strings. What I mean by padding is making it so a string is always a certain fixed length of characters, so in the event that a string is lower than that fixed length a number of chars of a given value are used to pad the remaining number of characters.

With lodash there is the _.pad, _.padStart, and _.padEnd methods that can be used to make quick work of string padding with lodash. If lodash is part of the project these methods are there to work with, but I will be looking at some other options as well when it comes to just native javaScript alone for padding strings. With that said in late javaScript specs there are padding methods baked into core javaScript now, these methods are the String.padStart and String.padEnd String prototype methods. In addition to that of native String prototype methods, if you want better backward support there are some concise tricks for this that will still work just fine in most older javaScript specs.

Read More

The lodash _.round method compared to Math.round, and formating fun.

So today for yet another of my posts on lodash and corresponding topics I have come around to writing a quick post on the _.round method that can be used in a similar way to that of Math.round in native javaScript. The lodash round method works more or less the same way, but with just one little additional feature that I just which the native methods had but does not that has to do with precession. Also in this post I will be writing about some related topics that have to do with formating numbers, something that comes up all the time when I am making a javaScript project.

Read More

The lodash groupBy method

In lodash there is a useful collection method called _.groupBy that can be used to created an object that has keys where each each key is a group that meets some kind of conditions defined in a function that is given to it. Each group in the resulting collection contains one or more elements from the source collection where the return value is the name of the group for that source element.

In other words in can be used to group items in a collection into new collections. Say for example you have a bunch of enemy display objects in a collection and you want to group them into dead, weak, and well groups based on there current hit point values. Such a task can be done with the lodash group by method. So this post will show some examples of _.groupBy in action.

Read More

The lodash concat method and native javaScript options for adding two or more arrays together

In this lodash post I will be writing about the lodash _.concat method, and of course the corresponding vanilla js method Array.concat built into the Array prototype in core javaScript itself. Regardless of which one you use the result is the same, adding two or more arrays into a single array in other words concatenation of arrays rather then Strings. There is of course more than one intention when it comes to the subject of adding two arrays together though, in some cases i might not want to concatenate elements from two arrays, into a single array, but create some kind of single primitive value that is a sum from two or more arrays. So then while I am at it maybe I should touch base on various other methods in lodash as well as native javaScript that have to do with creating a product from one or more arrays also.

If you are wondering what the difference is between the lodash and native options when it comes to an array concatenation method in javaScript, the answer is there is none beyond that os just making an abstraction. The lodash concat method is one of several methods in lodash that I have come to call lodash wrapper methods. These are methods where a native javaScript method is just simply being wrapped, and in this case more os less just for the sake of consistency when it comes to using lodash.

Still it is there just for the hell of it, and looking into the lodash source code, it looks like the lodash developers are not just directly referencing the native method, as is the case with some of these methods.

Read More

Some ways to parse command line interface options in node.js

When making a node.js project that is to one extent or another a command line tool, there is often a need to parse options that may be given from the command line when using the tool. In this post i will be breefly covering some options for quickly getting this over with, and continuing with what really matters when making your node.js cli tool.

Read More