Textflow

JavaScript
GitHub Repo

What It Is

A library to enable serial text transformation using a "pipeline" of "commands," each of which cumulatively operates on a string of text.

Status

Stable and actively development. The library is in use in several customer and demo instances at Staffbase.

Details

Textflow is a “language” to perform a series of transformations on text. Text can be obtained before and sent through the “pipeline,” or it can be acquired from within the pipeline.

Textflow is normally configured using Config Lang, and a configuration can be stored as parsable text, which makes it user-editable, suitable for editing in a UI.

A very simple example:

set -text:bar
prepend -text:"foo "
append -text:" baz"

Assuming the pipeline starts with no text (meaning nothing is “poured in the top”):

The result is foo bar baz.

Here’s a more practical example:

http -url:https://domain.com/some/path
extract -selector:body -scope:inner
remove -selector:h1
wrap -tag:div -style:"border: solid 1px red; padding: 1em;"

This pipeline:

  1. Retrieves an entire HTML document from a specified URL. The resulting response body becomes the working text of the pipeline
  2. Extracts the innerHTML of the BODY element
  3. Removes any H1 tags in the document
  4. Wraps what’s left inside a DIV tag with some styling

The result is a fragment of HTML that can be injected into a DOM.

In a practical sense, imagine that pipeline is stored in some type of widget that can be placed inside rich text in a CMS editor. With this, you have effectively created a small, domain-specific language that will execute at runtime, and retrieve, transform, and format a string of HTML to display.

Documentation