Some Ways to walk a file system in node.js

As I work to expand my content on node.js, I have come around to working out some examples on how to walk a files system. This includes both my own vanilla js solutions, as well as some walkers that other people have made for node.js, such as klaw, and node-dir, just to name a few. In this post I will be covering some options, and if you are looking into this sort of thing for your own project hopefully you will find this post helpful.

Read More

Using klaw, and through2 to walk a file system in node.js.

When making a command line interface program in node.js that needs to walk a file system recursively there are many options. If you do want to work within the core set of node.js modules without installing any additional from npm there is of course the fs.readdir method in the file system module that may be of interest. However in this post I will be writing about an npm package option that I seem to like a little for this known as klaw, that can also be used with another popular project known as through2. I will be giving file system walking examples mainly using this, but will also touch base on some alternatives as well.

Read More

Quick color conversion in phaser using Phaser.Color

When making a game with phaser 2, or with javaScript in general I sometimes come around to the issue of converting color values from one format to another. It is not hard to find or make methods that can be used to convert a decimal color value to a web friendly rgba string format, but still I can help but one can help but think that this should be part of the Phaser framework, well good news, it is.

Read More

The lodash sample method, and vanilla javaScript solutions for getting random elements from a collection.

In lodash the _.sample method will return a random element from a given collection object. That is it will give a random value from a random public key from an array, or one of the own properties of a given object in general.

Although methods like the lodash sample method can prove to be useful in some situations, it is still not to hard to clone many such methods with plain vanilla javaScript. Also often I might need to do something similar to what the lodash same method does such as getting a random range of elements, or a few single selections from a collection with or without replacement. So in this post I will be writing about _.sample in lodash, as well as native javaScript solutions for the same task that the lodash sample method does and then some. These examples might help to show why many still like to use lodash to help get things done faster, and focus more on what really matters when working on a project. However they might also show the limitations of lodash, and why it might in fact be best to write, and select solutions from the ground up as they are needed by making some kind of custom made utilty library in place of lodash.

Read More

Examples of the _.pick object method in lodash

When working with objects it is sometimes nice to quickly be able to make a custom object that is composed of properties from another object, just a few of them, not the whole thing. For this in lodash there is the _.pick method that can be used to create a new object that is a shallow copy of a given object, but with only properties that are in a given list of property names. So as the name suggests it is a pay to go about picking properties from another object, and create a new object with this list of properties from a source object.

Read More