@vbarbarosh/node-helpers 1.1.2 → 1.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "author": "Vladimir Barbarosh <vladimir.barbarosh@gmail.com>",
3
3
  "license": "MIT",
4
4
  "name": "@vbarbarosh/node-helpers",
5
- "version": "1.1.2",
5
+ "version": "1.1.3",
6
6
  "description": "A set of helpers for JavaScript/Node.js",
7
7
  "files": [
8
8
  "src"
@@ -1,7 +1,7 @@
1
1
  function array_index(array, fn)
2
2
  {
3
3
  const out = {};
4
- array.forEach((v,i) => out[v] = fn(v, i, array, out));
4
+ array.forEach(v => out[fn(v)] = v);
5
5
  return out;
6
6
  }
7
7
 
@@ -0,0 +1,14 @@
1
+ import array_index from './array_index';
2
+ import assert from 'assert';
3
+
4
+ describe('array_index', function () {
5
+ it('should accept empty array', function () {
6
+ assert.deepStrictEqual(array_index([]), {});
7
+ });
8
+ it('should handle basic input', function () {
9
+ const a = {uid: 'a'};
10
+ const b = {uid: 'b'};
11
+ const c = {uid: 'c'};
12
+ assert.deepStrictEqual(array_index([a, b, c], v => v.uid), {a, b, c});
13
+ });
14
+ });