|
|
6 päivää sitten | |
|---|---|---|
| .. | ||
| LICENSE | 6 päivää sitten | |
| dangerous.json | 6 päivää sitten | |
| index.js | 6 päivää sitten | |
| package.json | 6 päivää sitten | |
| readme.md | 6 päivää sitten | |
Encode HTML character references and character entities.
'`' characters are escaped to ensure no scripts
run in IE6-8. Additionally, only named entities recognised by HTML4
are encoded, meaning the infamous ' (which people think is a
virus) won’t show upBy default, all dangerous, non-ASCII, or non-printable ASCII characters
are encoded. A subset of characters can be given to encode just
those characters. Alternatively, pass escapeOnly to
escape just the dangerous characters (", ', <, >, &, `).
By default, numeric entities are used. Pass useNamedReferences
to use named entities when possible, or useShortestReferences
to use them if that results in less bytes.
npm:
npm install stringify-entities
var stringify = require('stringify-entities')
stringify('alpha © bravo ≠ charlie 𝌆 delta')
// => 'alpha © bravo ≠ charlie 𝌆 delta'
stringify('alpha © bravo ≠ charlie 𝌆 delta', {useNamedReferences: true})
// => 'alpha © bravo ≠ charlie 𝌆 delta'
stringifyEntities(value[, options])Encode special characters in value.
optionsoptions.escapeOnlyWhether to only escape possibly dangerous characters (boolean,
default: false). Those characters are ", ', <, > &, and
`.
options.subsetWhether to only escape the given subset of characters (Array.<string>).
options.useNamedReferencesWhether to use named entities where possible (boolean?, default:
false).
options.useShortestReferencesWhether to use named entities, where possible, if that results in less
bytes (boolean?, default: false). Note: useNamedReferences
can be omitted when using useShortestReferences.
options.omitOptionalSemicolonsWhether to omit semi-colons when possible (boolean?, default: false).
Note: This creates parse errors: don’t use this except when building
a minifier.
Omitting semi-colons is possible for certain legacy named references, and numeric entities, in some cases.
options.attributeOnly needed when operating dangerously with omitOptionalSemicolons: true.
Create entities which don’t fail in attributes (boolean?, default:
false).
parse-entities
— Parse HTML character referencescharacter-entities
— Info on character entitiescharacter-entities-html4
— Info on HTML4 character entitiescharacter-entities-legacy
— Info on legacy character entitiescharacter-reference-invalid
— Info on invalid numeric character references