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

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 & bravo');
// alpha & bravo
decode('charlie ©cat; 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 parsevalue
as an attribute value;position
(Location
orPosition
, optional) β Startingposition
ofvalue
, 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 invokingwarning
;textContext
('*', optional) β Context used when invokingtext
;referenceContext
('*', optional) β Context used when invokingreference
.
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 & bar |
Missing semicolon (named) |
2 |
foo { 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 whichvalue
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 whichvalue
starts and ends;source
(Location
) β Source of character reference.
License
MIT Β© Titus Wormer