convert-with-ents
v1.0.2
Published
Light-weight tool for converting characters in a string into common HTML entities (without regex).
Downloads
2
Maintainers
Readme
convert-with-ents
Light-weight tool for converting characters in a string into common HTML entities (without regex).
Converts the following characters into the HTML entity equivalents.
- Ampersand (&)
- Less than (<)
- Greater than (>)
- Double quote (")
- Single quote (')
Note: Ampersands are replaced by default, but they can be skipped. Please see the examples below.
Code Sample
import convertWithEnts from "convert-with-ents";
var source = "<text>Hey, how are you doing?<\/text>";
var result = convertWithEnts(source);
console.log(result);
If, for some reason, you need to skip ampersands, please use convertWithEnts(source, true)
import convertWithEnts from "convert-with-ents";
var source = "<text>I like JS && Python.<\/text>";
var result = convertWithEnts(source, true);
console.log(result);
Other Packages
If you would like to filter out or create a whitelist for punctuation characters, please see https://github.com/Rairye/js-mnl-punct-norm