Skip to content

This NPM module replaces characters that are not valid in XML in a string with XML/HTML character entities (and vice versa).

Notifications You must be signed in to change notification settings

teamwethrift/xml-sanitize-string

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 

Repository files navigation

xml-sanitize-string

This module replaces characters that are not valid in XML in a string with XML/HTML character entities (and vice versa).

Emoji, and many other characters are not valid in XML, and may cause problems if they sneak into your XML. This small module has two methods to sanitize (escape invalid characters) a string, and to unescape a string.

Installation & usage

Install xml-sanitize-string via NPM:

npm install xml-sanitize-string

In Node:

var xmlSanitizeString = require('xml-sanitize-string');

// Sanatize a string for use in XML by escaping invalid characters to XML character entities.
xmlSanitizeString.escape('Some 👉 invalid 💻 characters 🎒')
// Some &#1f449; invalid &#1f4bb; characters &#1f392;

// Unescape a string containing XML character entities to unicode characters
xmlSanitizeString.unescape('Some &#1f449; invalid &#1f4bb; characters &#1f392;')
// Some 👉 invalid 💻 characters 🎒

About

xml-sanitize-string was built by Nick Drewe to deal with user searches on searchmy.bio that may contain emoji, or other characters that are invalid in XML.

About

This NPM module replaces characters that are not valid in XML in a string with XML/HTML character entities (and vice versa).

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published