Body-cleaner
Very simple sanitizer to clean client-submitted data before you deal with it server-side. It iterates through objects & arrays to remove html & script tags, $ keys & everything that is not a string, a number, a date or a boolean.
Getting Started
Install
npm i --save body-cleaner
API
object(unsafe, options)
options <Object>
:ignoreKeys <Array>
: array of keys to ignore. Will ignore theses keys on all level.
- returns
safe <Object>
string(unsafe)
- returns
safe <String>
boolean(unsafe)
- returns
safe <Boolean>
Usage
Test it on RunKit.
const object = ; const newDate = ;const dirty = $bad: 'very bad' safe: 'safe' count: 1 'it is <script>alert("un")</script>safe' date: newDate; const clean = ; // clean = {// safe: 'safe',// count: [1, undefined, 'it is safe'],// date: newDate// }