concat-map
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|
The "concat-map" NPM package is a tool used for concatenative mapdashery in JavaScript. With this utility, you can return an array of concatenated elements by calling a function for each element and index within an array. When your callback function returns an array, its result will be concatenated with the original array. If it returns any other value, this will be pushed to the end of the result array.
Using "concat-map" is simple. First install the package using NPM, with the command npm install concat-map
. After the package is installed, you can use it in your JavaScript code by requiring it and then calling the concatMap
function with your array and function as arguments. Here is a code example:
var concatMap = require('concat-map');
var arr = [1, 2, 3, 4, 5, 6];
var new_arr = concatMap(arr, function (element, index) {
return element % 2 ? [element - 0.1, element, element + 0.1] : [];
});
console.dir(new_arr);
In this example, the callback function checks if the current value is odd. If so, it returns a new array with the current value decreased by 0.1, the current value, and the current value increased by 0.1. If the current value is even, it returns an empty array. The returned array is then combined with the original result array.
The official documentation for "concat-map" is not directly mentioned in the readme file. While it provides a simple example and explains the purpose and usage, more detailed documentation, if exists, could be found in the GitHub repository of the project located at https://github.com/ljharb/concat-map
. You can peruse the project's README and the source code for a deeper understanding of its usage and capabilities.