array-override

array-override

The array-override overrides functions under Array.prototype to change their behaviour according to the given parameters.

Parameters

Name

Description

Mandatory

Default

method

The Array function to override: push, includes.

Yes

n.a.

needle

The string or regex used to determine which function calls to trap. Enclose in / for regex.

Yes

n.a.

returnValue

Only relevant for includes. What to return when needle matches. Accepts: true or false.

No

false

path

Enables "object checking mode" and looks for needle at that given path.

No

''

stack

Comma separated list of strings to check in the stack trace.

No

''

Filter examples

Filter

Result

array-override push test

Ignores array.push("test") while allowing other values.

array-override push /first.*second/

Ignores the call if the parameter starts with "first" and ends with "second".

array-override includes test true

array.includes("test") always returns true.

array-override includes /first.*second/ false

array.includes("first-123-second") always returns false.

array-override forEach test

Ignores array forEach when value equals "test".

array-override push test '' '' ads.js

Ignores array.push("test") only for ads.js file.

Debugging

Message

When

Definition

Wrapped Array.prototype.push

After wrapping

push calls are intercepted.

Wrapped Array.prototype.includes

After wrapping

includes calls are intercepted.

Array.push is ignored for needle:>>needle>>

Needle matches push call

The push call was ignored.

Array.includes returned >>returnValue>> for >>needle>>

Needle matches includes call

includes returned the overridden value.