JSPM

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

Parse HTML character references: fast, spec-compliant, positional information

Package Exports

  • parse-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 (parse-entities) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

parse-entities Build Status Coverage Status

Parse HTML character references: fast, spec-compliant, positional information.

Installation

npm:

npm install parse-entities

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

Usage

var decode = require('parse-entities');

decode('alpha &amp bravo');
// alpha & bravo

decode('charlie &copycat; delta');
// charlie Β©cat; delta

decode('echo © foxtrot ≠ golf 𝌆 hotel');
// echo Β© foxtrot β‰  golf πŒ† hotel

API

parseEntities(value[, options])

Parameters

  • value (string) β€” Value with entities to parse;

  • options (Object, optional):

    • additional (string, optional, default: '') β€” Additional character to accept when following an ampersand (without error);

    • attribute (boolean, optional, default: false) β€” Whether to parse value as an attribute value;

    • position (Location or Position, optional) β€” Starting position of value, useful when dealing with values nested in some sort of syntax tree. The default is:

      {
        "start": {
          "line": 1,
          "column": 1,
          "offset": 0
        },
        "indent": []
      }
    • warning (Function, optional) β€” Error handler;

    • text (Function, optional) β€” Text handler;

    • reference (Function, optional) β€” Reference handler;

    • warningContext ('*', optional) β€” Context used when invoking warning;

    • textContext ('*', optional) β€” Context used when invoking text;

    • referenceContext ('*', optional) β€” Context used when invoking reference.

Returns

string β€” Decoded value.

function warning(reason, position, code)

Error handler.

Context: this refers to warningContext when given to parseEntities.

Parameters

  • reason (string) β€” Reason (human-readable) for triggering a parse error;

  • position (Position) β€” Place at which the parse error occurred;

  • code (number) β€” Identifier of reason for triggering a parse error.

The following codes are used:

Code Example Note
1 foo &amp bar Missing semicolon (named)
2 foo &#123 bar Missing semicolon (numeric)
3 Foo &bar baz Ampersand did not start a reference
4 Foo &# Empty reference
5 Foo &bar; baz Unknown entity
6 Foo € baz Disallowed reference
7 Foo � baz Prohibited: outside permissible unicode range

function text(value, location)

Text handler.

Context: this refers to textContext when given to parseEntities.

Parameters

  • value (string) β€” String of content;
  • location (Location) β€” Location at which value starts and ends.

function reference(value, location, source)

Character reference handler.

Context: this refers to referenceContext when given to parseEntities.

Parameters

  • value (string) β€” Encoded character reference;
  • location (Location) β€” Location at which value starts and ends;
  • source (Location) β€” Source of character reference.

License

MIT Β© Titus Wormer