arvin.torres e3ca5d94a7 Campanas de Paz para la Mujer | 5 лет назад | |
---|---|---|
.. | ||
.npmignore | 5 лет назад | |
LICENSE | 5 лет назад | |
README.md | 5 лет назад | |
index.js | 5 лет назад | |
package.json | 5 лет назад | |
test.js | 5 лет назад |
Escape XML in javascript (NodeJS)
npm install xml-escape
// Warning escape is a reserved word, so maybe best to use xmlescape for var name
var xmlescape = require('xml-escape');
xmlescape('"hello" \'world\' & false < true > -1');
// output
// '"hello" 'world' & false < true > -1'
// don't escape some characters
xmlescape('"hello" \'world\' & false < true > -1', '>"&')
// output
// '"hello" 'world' & false < true > -1'
There is also now an ignore function thanks to @jayflo
esc = require('./');
ignore = '"<&'
// note you should never ignore an &
output = esc('I am "<¬>" escaped', ignore)
console.log(output)
//I am "<¬>" escaped