Skip to Content
  • Website
Codsen
  • Home
  • Open Source
  • Articles
  • About

prevOpen Source→stristrinext

stristri

Extracts or deletes HTML, CSS, text and/or templating tags from string

Downloads per monthMIT Licenselibera manifesto
  • the top
  • IDEA
  • FEATURES
  • API — STRI()
  • API — DEFAULTS
  • API — VERSION

Idea

A parsing alternative of string-strip-html.

Features

  • Pick what to strip: HTML and/or CSS and/or text and/or templating tags
  • Supports well: Nunjucks/Jinja, JSP, Responsys
  • Should support all other templating languages and ESP templating tags
  • Runs off our own lexer

API — stri()

The main function stri() is imported like this:

It’s a function which takes two input arguments:

Input argumentTypeObligatoryDescription
input
Type: String
Obligatory: yes
inputStringyesText you want to strip HTML tags from
opts
Type: Plain object
Obligatory: no
optsPlain objectnoThe Optional Options Object, see below for its API

The Optional Options Object has the following shape:

KeyTypeDefaultDescription
html
Type: Boolean
Default: true
htmlBooleantrueStrip HTML, XML tags and their comments?
css
Type: Boolean
Default: true
cssBooleantrueStrip head CSS style tags and CSS rules?
text
Type: Boolean
Default: false
textBooleanfalseStrip text?
templatingTags
Type: Boolean
Default: false
templatingTagsBooleanfalseStrip any templating tags (like Nunjucks)?
js
Type: Boolean
Default: true
jsBooleantrueStrip any JS code?
reportProgressFunc
Type: null or Function
Default: null
reportProgressFuncnull or FunctionnullPass a function, progress value, 0-100 will be passed to it
reportProgressFuncFrom
Type: Natural number [0; 100]
Default: 0
reportProgressFuncFromNatural number [0; 100]0Starting progress percentage
reportProgressFuncTo
Type: Natural number [0; 100]
Default: 100
reportProgressFuncToNatural number [0; 100]100Ending progress percentage

Here are all defaults in one place for copying:

The function will return a plain object of a shape:

Key’s nameTypeDescription
log
Type: Plain object
logPlain objectVarious statistics
result
Type: String
resultStringThe result.
applicableOpts
Type: Plain object, only boolean keys from opts
applicableOptsPlain object, only boolean keys from optsTells which options object keys would have made a difference for this string input, if toggled differently
templatingLang
Type: Plain object
templatingLangPlain objectPipes the output of detect-templating-language

API — defaults

You can import defaults:

It's a plain object:

The main function calculates the options to be used by merging the options you passed with these defaults.

API — version

You can import version:

↑ back to top
prev next

Copyright

All rights reserved © Roy Revelt 2026
All our open source packages are under MIT licenceopens in a new tab

Activities

🐛 See a bug? Raise an issueopens in a new tab
💘 Check out the Indiewebopens in a new tab and Libera manifestoopens in a new tab