Installation
Quick Take
Examples
- Deletion by the key only
- Deletion by the value only
- Disable the cleanup which would otherwise happen after deletion
- Wildcards
Deleting
Three modes:
- Delete all
key
/value
pairs found in any nested plain objects wherekey
equalsvalue
. - Delete all
key
/value
pairs found in any nested plain objects wherekey
is equal to a certain thing.value
doesn’t matter. - Delete all
key
/value
pairs found in any nested plain objects wherevalue
is equal to a certain thing.key
doesn’t matter.
This library accepts anything as input, including parsed HTML, which is deeply nested arrays of plain objects, arrays and strings. You can feed anything as input into this library — if it’s traversable, it will be traversed and searched for your key
and/or value
in any plain objects.
If you want to delete any nested objects that contain certain key
/value
pair(s), check out ast-delete-object.
API — deleteKey()
The main function deleteKey()
is imported like this:
It’s a function which takes three input arguments:
Input argument | Type | Obligatory | Description |
---|---|---|---|
input Type: Plain object Obligatory: yes | |||
input | Plain object | yes | Input to work upon. |
options Type: Plain object Obligatory: yes | |||
options | Plain object | yes | Obligatory Options object. |
The Obligatory Options Object has the following shape:
Key | Type | Obligatory | Default | Description |
---|---|---|---|---|
key Type: String Obligatory: no^ Default: n/a | ||||
key | String | no^ | n/a | Key to find and delete. |
val Type: Whatever Obligatory: no^ Default: n/a | ||||
val | Whatever | no^ | n/a | Key’s value to find and delete. |
cleanup Type: Boolean Obligatory: no Default: true | ||||
cleanup | Boolean | no | true | Should this package delete any empty carcases of arrays/objects left after the deletion? |
only Type: "array" , "object" or "any" Obligatory: no Default: "any" | ||||
only | "array" , "object" or "any" | no | "any" | Default setting will delete from both arrays and objects. Here you can limit the scope. |
^ — at least one, key
or val
must be present.
Function returns the input
with all requested keys/value pairs removed.