# striptags

> PHP strip_tags in Node.js

Latest version **3.2.0** (published 2021-06-18) · MIT license · 0 weekly downloads

## Install

```sh
npm install striptags
pnpm add striptags
yarn add striptags
bun add striptags
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 3.2.0 |
| Published | 2021-06-18 |
| First published | 2014-06-30 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 17.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 492 |
| Author | Eric Norris |
| Maintainers | ericnorris |
| Keywords | striptags, strip_tags, html, strip, tags |

## Links

- npm: https://www.npmjs.com/package/striptags
- Repository: https://github.com/ericnorris/striptags
- Issues: https://github.com/ericnorris/striptags/issues
- npm.io page: https://npm.io/package/striptags

## Alternatives

- [@tsparticles/shape-image](https://npm.io/package/@tsparticles/shape-image.md) — 303.7K weekly downloads
- [@tsparticles/shape-line](https://npm.io/package/@tsparticles/shape-line.md) — 233.7K weekly downloads
- [stringify-attributes](https://npm.io/package/stringify-attributes.md) — 58.6K weekly downloads
- [mobile-drag-drop](https://npm.io/package/mobile-drag-drop.md) — 46.3K weekly downloads
- [@comunica/actor-rdf-parse-html](https://npm.io/package/@comunica/actor-rdf-parse-html.md) — 29.2K weekly downloads

## Recent versions

- 3.2.0 (latest) — 2021-06-18
- 4.0.0-alpha.4 (alpha) — 2022-10-04
- 4.0.0-alpha.3 — 2022-10-04
- 4.0.0-alpha.2 — 2020-11-30
- 4.0.0-alpha.1 — 2020-11-29
- 4.0.0-alpha.0 — 2020-11-29
- 3.1.1 — 2017-12-02
- 3.1.0 — 2017-08-26
- 3.0.1 — 2017-02-05
- 3.0.0 — 2017-02-01
- 2.2.1 — 2017-01-18
- 2.2.0 — 2017-01-18
- 2.1.1 — 2016-01-06
- 2.1.0 — 2016-01-02
- 2.0.4 — 2015-10-12
- … 5 more at https://npm.io/package/striptags/versions

## README

# striptags [![Build Status](https://travis-ci.org/ericnorris/striptags.svg)](https://travis-ci.org/ericnorris/striptags)
An implementation of PHP's [strip_tags](http://www.php.net/manual/en/function.strip-tags.php) in Node.js.

**Note:** `v3+` targets ES6, and is therefore incompatible with the master branch of `uglifyjs`. You can either:
- use `babili`, which supports ES6
- use the `harmony` branch of `uglifyjs`
- stick with the [2.x.x](https://github.com/ericnorris/striptags/tree/v2.x.x) branch

## Features
- Fast
- Zero dependencies
- 100% test code coverage
- No unsafe regular expressions

## Installing
```
npm install striptags
```

## Basic Usage
```javascript
striptags(html, allowed_tags, tag_replacement);
```

### Example
```javascript
var striptags = require('striptags');

var html =
    '<a href="https://example.com">' +
        'lorem ipsum <strong>dolor</strong> <em>sit</em> amet' +
    '</a>';

striptags(html);
striptags(html, '<strong>');
striptags(html, ['a']);
striptags(html, [], '\n');
```

Outputs:
```
'lorem ipsum dolor sit amet'
```

```
lorem ipsum <strong>dolor</strong> sit amet'
```

```
'<a href="https://example.com">lorem ipsum dolor sit amet</a>'
```

```
lorem ipsum 
dolor
 
sit
 amet
```

## Streaming Mode
`striptags` can also operate in streaming mode. Simply call `init_streaming_mode` to get back a function that accepts HTML and outputs stripped HTML. State is saved between calls so that partial HTML can be safely passed in.

```javascript
let stream_function = striptags.init_streaming_mode(
    allowed_tags,
    tag_replacement
);

let partial_text = stream_function(partial_html);
let more_text    = stream_function(more_html);
```

Check out [test/striptags-test.js](test/striptags-test.js) for a concrete example.

## Tests
You can run tests (powered by [mocha](http://mochajs.org/)) locally via:
```
npm test
```

Generate test coverage (powered by [istanbul](https://github.com/gotwarlost/istanbul)) via :
```
npm run coverage
```


## Doesn't use regular expressions
`striptags` does not use any regular expressions for stripping HTML tags.

Regular expressions are not capable of preventing all possible scripting attacks (see [this](http://stackoverflow.com/a/535022)). Here is a [great StackOverflow answer](http://stackoverflow.com/a/5793453) regarding how strip_tags (**when used without specifying allowableTags**) is not vulnerable to scripting attacks.

---
_Source: https://npm.io/package/striptags · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
