body-cleaner

1.1.3 • Public • Published

Body-cleaner

Build Status Coverage Status Known Vulnerabilities CodeFactor

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 } = require('body-cleaner');
 
const newDate = new Date();
const dirty = {
  $bad: 'very bad',
  safe: 'safe',
  count: [1, new Error(), 'it is <script>alert("un")</script>safe'],
  date: newDate
};
 
const clean = object(dirty);
 
// clean = {
//   safe: 'safe',
//   count: [1, undefined, 'it is safe'],
//   date: newDate
// }

Package Sidebar

Install

npm i body-cleaner

Weekly Downloads

7

Version

1.1.3

License

MIT

Unpacked Size

15.4 kB

Total Files

9

Last publish

Collaborators

  • atmys