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 | Plain object | yes | Input to work upon. |
options | Plain object | yes | Obligatory Options object. |
The Obligatory Options Object has the following shape:
options object's key | Type | Obligatory? | Default | Description |
---|---|---|---|---|
key | String | no^ | n/a | Key to find and delete. |
val | Whatever | no^ | n/a | Key's value to find and delete. |
cleanup | Boolean | no | true | Should this package delete any empty carcases of arrays/objects left after the deletion? |
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.