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/valuepairs found in any nested plain objects wherekeyequalsvalue. - Delete all
key/valuepairs found in any nested plain objects wherekeyis equal to a certain thing.valuedoesn’t matter. - Delete all
key/valuepairs found in any nested plain objects wherevalueis equal to a certain thing.keydoesn’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 |
|---|---|---|---|
inputType: Plain object Obligatory: yes | |||
input | Plain object | yes | Input to work upon. |
optionsType: Plain object Obligatory: yes | |||
options | Plain object | yes | Obligatory Options object. |
The Obligatory Options Object has the following shape:
| Key | Type | Obligatory | Default | Description |
|---|---|---|---|---|
keyType: String Obligatory: no^ Default: n/a | ||||
key | String | no^ | n/a | Key to find and delete. |
valType: Whatever Obligatory: no^ Default: n/a | ||||
val | Whatever | no^ | n/a | Key’s value to find and delete. |
cleanupType: Boolean Obligatory: no Default: true | ||||
cleanup | Boolean | no | true | Should this package delete any empty carcases of arrays/objects left after the deletion? |
onlyType: "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.