Socket
Socket
Sign inDemoInstall

array-walker

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

array-walker - npm Package Compare versions

Comparing version 1.0.0 to 1.1.0

6

index.js

@@ -7,3 +7,3 @@ (() => {

function arrayWalker(items, observationCallback, ...lineage) {
function arrayWalker(items, observationCallback, context, ...lineage) {

@@ -14,7 +14,7 @@ items.forEach((value, key) => {

arrayWalker(value, observationCallback, ...lineage, key);
arrayWalker(value, observationCallback, context, ...lineage, key);
} else {
observationCallback(value, ...lineage, key);
observationCallback.call(context, value, ...lineage, key);

@@ -21,0 +21,0 @@ }

{
"name": "array-walker",
"version": "1.0.0",
"version": "1.1.0",
"description": "Multi-dimensional array walker with observation",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -31,2 +31,11 @@ # Array Walker

// With context
walker(['a', 'b'], callbackWithContext, {example: "The Answer"});
// The Answer, a, 0
// The Answer, b, 1
function callbackWithContext(value, key) {
console.log(this.example, value, key);
}
```

@@ -41,3 +50,3 @@ ## Installation

```
### walker(items, observationCallback, ...lineage)
### walker(items, observationCallback, context, ...lineage)
| Type | Data Type | Name | Description |

@@ -47,2 +56,3 @@ | --- | --- | --- | --- |

| parameter | function | observationCallback | The function to call when a non-array value is found. |
| parameter | * | The context passed to the callback |
| parameter | ...number | [lineage] | The parent indexes. |

@@ -57,2 +67,3 @@ | returns | undefined | n/a | n/a |

| --- | --- | --- | --- |
| this | * | this | The context passed to the walker |
| parameter | !\*[] | value | The value that was discovered. |

@@ -59,0 +70,0 @@ | parameter | ...number | lineage | The indexes in each dimension of the array. |

@@ -150,5 +150,6 @@ /* global describe it expect jasmine */

let items = ['t'],
callback = jasmine.createSpy('callback');
callback = jasmine.createSpy('callback'),
context;
target(items, callback, 1, 2, 'three');
target(items, callback, context, 1, 2, 'three');

@@ -164,4 +165,22 @@ it('executes callback for each item', () => {

describe('callbacks with context', () => {
let items = ['t'],
callback = jasmine.createSpy('callback'),
context = {
testing: 'the context'
};
target(items, callback, context);
it('provides context', () => {
expect(callback.calls[0].object).toBe(context);
});
});
});
})();
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc