The lodash _.reduce method and Array.reduce.

For todays post on lodash I thought I should write a post on the _.reduce collection method, and also of course the corresponding Array.reduce method in core javaScript itself. Speaking of the native array reduce method I have now wrote a post on the native array reduce method also, but I will be touching base on that method on this post also.

The Array.reduce method works just fine, however if you are using lodash in a project the _.reduce method is a little more robust, as it is one of the many lodash collection methods that will work on arrays and many object collections in general and it also has some baked in shorthands for cretin common use case examples of it also. In any case the two solutions work very similar, and this post should help gain some insight as to why reduce is useful in some situations that call for it.

Read More

The yargs option parser for node.js

So this week I have been looking into option parsers, for the sake of expanding my horizons when it comes to what the options are for parsing options. I have writing a post on nopt a long time ago, which was one of the first option parsers I have dealt with. It works fine, but so far I think I am liking commander the best. However this post is about another popular option parser for node.js called yargs.

Read More

Using the walk npm package to loop over the contents of a file system in node.js.

For the past few days I have been exploring node.js powered options when it comes to walking over the contents of a file system. I have been looking at methods in the node.js fs module that can be used to just start doing something like this from the ground up, as well as npm packages. Im my travels I have found what looks like maybe one of the most popular solutions when it comes to npm packages that is just simply called walk. In this post I will be covering the use of walk to just get this aspect of development over with quickly.

Read More

Setting boundaries in Phaser with wrap, and clamp

When making a phaser game, with many projects there might be a need to wrap, or clamp a sprite or other display object to a set of boundaries. There are also all kinds of other situations in which such a method would prove to be useful when it comes to things like parsing index values for array elements that might go out or range or something to that effect.

In lodash there is a lodash clamp method but oddly enough there is no wrap method at least not when it comes to wrapping numbers so if I want one in lodash I need to add one to it as a mixin. However this is a post on the javaScript game framework known as phaser, and because wrapping and clamping values is a typical scenario with most games, phaser includes some methods it the Phaser Math object to help with this, mainly wrap, and clamp. So then in this post I will be going over a few quick examples that make use of these methods in a phaser CE project.

Read More

Walking over the contents of a path recursively with fs.readdir

The subject of walking, or looping over a file system path recursively for the purpose of doing some kind of file operation on a whole bunch of files in a directory that meet a certain criteria is a subject that comes up often with node.js development. There are many options when it comes to doing this, some of which are well known npm packages such as walk, and klaw. However in this post I will be writing about how to go about doing so with just the node.js build in file system modules readdir method, along with some others a well.

Read More