<commit_before># script_sanitizer.js
A simple npm library to remove script tags but keep other html

[![npm](https://img.shields.io/npm/dt/script_sanitize.svg)](https://www.npmjs.com/package/script_sanitize)
[![Build Status](https://travis-ci.org/EverlessDrop41/script_sanitizer.js.svg?branch=master)](https://travis-ci.org/EverlessDrop41/script_sanitizer.js)
[![npm](https://img.shields.io/npm/v/script_sanitize.svg?maxAge=2592000)](https://www.npmjs.com/package/script_sanitize)
[![npm](https://img.shields.io/npm/l/express.svg?maxAge=2592000)](https://www.npmjs.com/package/script_sanitize)

Installation
===
- NPM:  `npm install script_sanitize`
- CDN:   https://cdn.rawgit.com/EverlessDrop41/script_sanitizer.js/master/dist/script_sanitize.min.js
- Repo:  dist/script_sanitize.js
- Repo Minified:  dist/script_sanitize.min.js

Usage
===
If on Node.js
```js
var script_sanitize = require('../script_sanitize').sanitize;
```

If on a website

```html
<script href="https://cdn.rawgit.com/EverlessDrop41/script_sanitizer.js/master/dist/script_sanitize.min.js"></script>
<script type="text/javascript">
  var script_sanitize = script_sanitize.sanitize;
</script>
```

The method is defined as

`script_sanitize(html, options (optional))`

and can be used like so

```js
var sanitized = script_sanitize("<h1>Hello</h1><script>alert('hi')</script>");
//=> <h1>Hello</h1>
```

```js
var sanitizedWithReplacment = script_sanitize("<h1>Hello</h1><script>alert('hi')</script>", { replacementText: "no" });
//=> <h1>Hello</h1>no
```

Utils
--
```js
{
  isDefined: function (obj) {
    return (typeof obj !== 'undefined') && obj != null
  },
  defaultFor: function (variable,defaultValue){
    return (this.isDefined(variable))?(variable):(defaultValue);
  },
  generateRegexForTag: function (tag) {
    var a = "<" + tag + "\\b[^<]*(?:(?!<\\/" + tag + ">)<[^<]*)*<\\/" + tag + "\\s*>";
    return new RegExp(a, "gi");
  },
  generateRegexForEndTag: function (tag) {
    var a = "<\\/" + tag + "\\s*>";
    return new RegExp(a, "gi");
  }
}
```

The options parameter
--

| Option              | Description                                                                             | Default Value |
|---------------------|-----------------------------------------------------------------------------------------|---------------|
| replacementText     | The text to replace the script tag with                                                 | ""            |
| loop                | Whether to replace via looping or a single statement                                    | true          |
| replaceEndTagsAfter | In certain cases the ending script tag is still there, this options ensures it won't be | true          |


License
===
[MIT](https://opensource.org/licenses/MIT)
<commit_msg>added a table for the utils object to the readme<commit_after># script_sanitizer.js
A simple npm library to remove script tags but keep other html

[![npm](https://img.shields.io/npm/dt/script_sanitize.svg)](https://www.npmjs.com/package/script_sanitize)
[![Build Status](https://travis-ci.org/EverlessDrop41/script_sanitizer.js.svg?branch=master)](https://travis-ci.org/EverlessDrop41/script_sanitizer.js)
[![npm](https://img.shields.io/npm/v/script_sanitize.svg?maxAge=2592000)](https://www.npmjs.com/package/script_sanitize)
[![npm](https://img.shields.io/npm/l/express.svg?maxAge=2592000)](https://www.npmjs.com/package/script_sanitize)

Installation
===
- NPM:  `npm install script_sanitize`
- CDN:   https://cdn.rawgit.com/EverlessDrop41/script_sanitizer.js/master/dist/script_sanitize.min.js
- Repo:  dist/script_sanitize.js
- Repo Minified:  dist/script_sanitize.min.js

Usage
===
If on Node.js
```js
var script_sanitize = require('../script_sanitize').sanitize;
```

If on a website

```html
<script href="https://cdn.rawgit.com/EverlessDrop41/script_sanitizer.js/master/dist/script_sanitize.min.js"></script>
<script type="text/javascript">
  var script_sanitize = script_sanitize.sanitize;
</script>
```

The method is defined as

`script_sanitize(html, options (optional))`

and can be used like so

```js
var sanitized = script_sanitize("<h1>Hello</h1><script>alert('hi')</script>");
//=> <h1>Hello</h1>
```

```js
var sanitizedWithReplacment = script_sanitize("<h1>Hello</h1><script>alert('hi')</script>", { replacementText: "no" });
//=> <h1>Hello</h1>no
```

The options parameter
--

| Option              | Description                                                                             | Default Value |
|---------------------|-----------------------------------------------------------------------------------------|---------------|
| replacementText     | The text to replace the script tag with                                                 | ""            |
| loop                | Whether to replace via looping or a single statement                                    | true          |
| replaceEndTagsAfter | In certain cases the ending script tag is still there, this options ensures it won't be | true          |

Utils
--
| Util                   | Description                                   |
|------------------------|-----------------------------------------------|
| isDefined              | Checks if a variable is defined               |
| defaultFor             | Sets a default value if a variable is defined |
| generateRegexForTag    | Generates a regex object for a tag            |
| generateRegexForEndTag | Generates a regex object to check an end tag  |

License
===
[MIT](https://opensource.org/licenses/MIT)

{'fraction_non_alphanumeric': 0.20284633399387497, 'fraction_numerical': 0.010808863267879661, 'mean_word_length': 2.338544798556825, 'pattern_counts': {'":': 0, '<': 42, '<?xml version=': 0, '>': 42, 'https://': 22, 'lorem ipsum': 0, 'www.': 6, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 15, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4054345', 'n_tokens_mistral': 1758, 'n_tokens_neox': 1673, 'n_words': 338}