README
drycleaner
A very tiny library for manipulating HTML entity strings
This library was created to make working with MS Word documents easier, especially if you need to insert html or possibly even color-coded html into the document.
To install
$ npm install drycleaner
API
An instance of the Drycleaner object contains three methods:
escape
escapes the initial string passed.unescape
unescapes the initial string passed.wrap
wrappes the initial string passed into a dom element.
Options
wrap
takes a single object as its argument. It contains two properties. The result of the object on which wrap was called will become a dom object, not an escaped html string.
el {string}
: node name of the html element you wish create.
style {object}
: style properties that will be appended inline to the html element wrapper.
var html = new Drycleaner("<b>Hello world</b>");
var processed = html.wrap({
el: "pre",
style: {
background-color: "yellow",
color: "grey"
}
})
var result = processed.str;
--> <pre style="background-color: yellow; color: grey"><b>hello world</b></pre>
escape
and unescape
can each take a single object as their argument. It contains four properties.
nbsp {boolean}
: if set to true, non-breaking white space will be converted to and from " "
and
The default value is false.
var html = new Drycleaner("<b>hello world</b>");
var processed = html.escape({ npsp: true });
var result = processed.str;
--> <b>hello world</b>
except {array}
: an array of characters or html entity strings you wish to filter.
var html = new Drycleaner("<b>hello world</b>");
var processed = html.escape({ except: ["<"] });
var result = processed.str;
--> <b>hello world</b>
on {string}
: the property you wish to perform work on. Set to str
by default.
var html = new Drycleaner("<b>Hello world</b>");
var processed = html.escape({ result: "myResult" })
.unescape({ on: "myResult" });
var result = processed.myResult;
--> <b>Hello world</b>
result {string}
: the property you wish to set the result of an operation on. Set to str
by default.
var html = new Drycleaner("<b>Hello world</b>");
var processed = html.escape({ result: "myResult" });
var result = processed.myResult;
--> <b>hello world</b>