entities
- Version 9.0.0
- Published
- 328 kB
- No dependencies
- BSD-2-Clause license
Install
npm i entitiesyarn add entitiespnpm add entitiesOverview
Encode & decode XML and HTML entities with ease & speed
Index
Variables
Functions
Classes
Interfaces
Enums
Variables
variable escape
const escape: (input: string) => string;Encodes all non-ASCII characters, as well as characters not valid in XML documents using numeric decimal reference (eg.
ü).Have a look at
escapeUTF8if you want a more concise output at the expense of reduced transportability.Parameter data
String to escape.
Functions
function decode
decode: (input: string, options?: DecodingOptions | EntityLevel) => string;Decodes a string with entities.
Parameter input
String to decode.
Parameter options
Decoding options.
function decodeHTML
decodeHTML: (htmlString: string, mode?: DecodingMode) => string;Decodes an HTML string.
Parameter htmlString
The string to decode.
Parameter mode
The decoding mode.
Returns
The decoded string.
function decodeHTMLAttribute
decodeHTMLAttribute: (htmlAttribute: string) => string;Decodes an HTML string in an attribute.
Parameter htmlAttribute
The string to decode.
Returns
The decoded string.
function decodeHTMLStrict
decodeHTMLStrict: (htmlString: string) => string;Decodes an HTML string, requiring all entities to be terminated by a semicolon.
Parameter htmlString
The string to decode.
Returns
The decoded string.
function decodeXML
decodeXML: (xmlString: string) => string;Decodes an XML string, requiring all entities to be terminated by a semicolon.
Parameter xmlString
The string to decode.
Returns
The decoded string.
function decodeXMLStrict
decodeXMLStrict: (xmlString: string) => string;Decodes an XML string, requiring all entities to be terminated by a semicolon.
Parameter xmlString
The string to decode.
Returns
The decoded string.
function encode
encode: (input: string, options?: EncodingOptions | EntityLevel) => string;Encodes a string with entities.
Parameter input
String to encode.
Parameter options
Encoding options.
function encodeHTML
encodeHTML: (input: string) => string;Encodes all characters in the input using HTML entities. This includes characters that are valid ASCII characters in HTML documents, such as
#.To get a more compact output, consider using the
encodeNonAsciiHTMLfunction, which will only encode characters that are not valid in HTML documents, as well as non-ASCII characters.If a character has no equivalent entity, a numeric decimal reference (eg.
ü) will be used.Parameter input
Input string to encode.
function encodeNonAsciiHTML
encodeNonAsciiHTML: (input: string) => string;Encodes all non-ASCII characters, as well as characters not valid in HTML documents using HTML entities. This function will not encode characters that are valid in HTML documents, such as
#.If a character has no equivalent entity, a numeric decimal reference (eg.
ü) will be used.Parameter input
Input string to encode.
function encodeXML
encodeXML: (input: string) => string;Encodes all non-ASCII characters, as well as characters not valid in XML documents using XML entities.
If a character has no equivalent entity, a numeric decimal reference (eg.
ü) will be used.Parameter input
Input string to encode.
function escapeAttribute
escapeAttribute: (data: string) => string;Encodes all characters that have to be escaped in HTML attributes, following https://html.spec.whatwg.org/multipage/parsing.html#escapingString.
Parameter data
String to escape.
function escapeText
escapeText: (data: string) => string;Encodes all characters that have to be escaped in HTML text, following https://html.spec.whatwg.org/multipage/parsing.html#escapingString.
Parameter data
String to escape.
function escapeUTF8
escapeUTF8: (data: string) => string;Encodes all characters not valid in XML documents using XML entities.
Note that the output will be character-set dependent.
Parameter data
String to escape.
Classes
class HtmlEntityDecoder
class HtmlEntityDecoder extends EntityDecoderBase {}Streaming decoder for HTML entities.
When the entity fits inside the current chunk (the common case), the lookup runs directly on the chunk via the same length-probe scheme as the synchronous decoder; chunk-boundary runs use a reusable character buffer.
method endNamedEntity
protected endNamedEntity: () => number;method startEntity
startEntity: (decodeMode: DecodingMode) => void;method stateNamedEntity
protected stateNamedEntity: (input: string, offset: number) => number;class XmlEntityDecoder
class XmlEntityDecoder extends EntityDecoderBase {}Streaming decoder for XML entities: the five predefined named entities plus numeric character references.
property replaceNumericCodePoint
protected readonly replaceNumericCodePoint: (codePoint: number) => number;method endNamedEntity
protected endNamedEntity: () => number;method stateNamedEntity
protected stateNamedEntity: (input: string, offset: number) => number;Interfaces
interface DecodingOptions
interface DecodingOptions {}Options for
decode.
property level
level?: EntityLevel;The level of entities to support. EntityLevel.XML
property mode
mode?: DecodingMode | undefined;Decoding mode. If
Legacy, will support legacy entities not terminated with a semicolon (;).Always
Strictfor XML. For HTML, set this to DecodingMode.Attribute if you are parsing an attribute value. DecodingMode.Legacy
interface EncodingOptions
interface EncodingOptions {}Options for
encode.
property level
level?: EntityLevel;The level of entities to support. EntityLevel.XML
property mode
mode?: EncodingMode;Output format. EncodingMode.Extensive
Enums
enum DecodingMode
enum DecodingMode { Legacy = 0, Strict = 1, Attribute = 2,}Decoding mode for named entities.
enum EncodingMode
enum EncodingMode { UTF8 = 0, ASCII = 1, Extensive = 2, Attribute = 3, Text = 4,}Encoding strategy used by
encode.
member ASCII
ASCII = 1The output consists only of ASCII characters. Characters that need escaping within HTML, and characters that aren't ASCII characters will be escaped.
member Attribute
Attribute = 3Encode all characters that have to be escaped in HTML attributes, following https://html.spec.whatwg.org/multipage/parsing.html#escapingString.
member Extensive
Extensive = 2Encode all characters that have an equivalent entity, as well as all characters that are not ASCII characters.
member Text
Text = 4Encode all characters that have to be escaped in HTML text, following https://html.spec.whatwg.org/multipage/parsing.html#escapingString.
member UTF8
UTF8 = 0The output is UTF-8 encoded. Only characters that need escaping within XML will be escaped.
enum EntityLevel
enum EntityLevel { XML = 0, HTML = 1,}The level of entities to support.
Package Files (4)
Dependencies (0)
No dependencies.
Dev Dependencies (11)
Peer Dependencies (0)
No peer dependencies.
Badge
To add a badge like this oneto your package's README, use the codes available below.
You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/entities.
- Markdown[](https://www.jsdocs.io/package/entities)
- HTML<a href="https://www.jsdocs.io/package/entities"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>
- Updated .
Package analyzed in 2988 ms. - Missing or incorrect documentation? Open an issue for this package.
