JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 11137102
  • Score
    100M100P100Q225435F
  • License MIT

Encode HTML character references and character entities

Package Exports

  • stringify-entities

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (stringify-entities) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

stringify-entities Build Status Coverage Status

Encode HTML character references and character entities.

  • Very fast;

  • Just the encoding part;

  • Reliable: "`" characters are escaped to ensure no scripts execute in IE6-8. Additionally, only named entities recognized by HTML4 are encoded, meaning the infamous ' (which people think is a virus) won’t show up.

Installation

npm:

npm install stringify-entities

stringify-entities is also available for duo, and bundled for AMD, CommonJS, and globals (uncompressed and compressed).

Usage

var stringify = require('stringify-entities');

stringify.encode('alpha Β© bravo β‰  charlie πŒ† delta');

Yields:

alpha © bravo ≠ charlie 𝌆 delta

…and with useNamedReferences: true.

stringify.encode('alpha Β© bravo β‰  charlie πŒ† delta', { useNamedReferences: true });

Yields:

alpha © bravo ≠ charlie 𝌆 delta

API

stringifyEntities(value[, options?])

Encode special characters in value.

Parameters:

  • value (string) β€” Value to encode;

  • options (Object?, optional) β€” Configuration:

    • escapeOnly (boolean?, optional, default: false) β€” Whether to only escape possibly dangerous characters (", ', <, > &, and `);

    • useNamedReferences (boolean?, optional, default: false) β€” Whether to use entities where possible.

Returns: string, encoded value.

stringifyEntities.escape(value[, options?])

Escape special characters in value. Shortcut for stringifyEntities with escapeOnly: true and useNamedReferences: true.

Support

See html.spec.whatwg.org.

License

MIT Β© Titus Wormer