entities

  • Version 9.0.0
  • Published
  • 328 kB
  • No dependencies
  • BSD-2-Clause license

Install

npm i entities
yarn add entities
pnpm add entities

Overview

Encode & decode XML and HTML entities with ease & speed

Index

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 escapeUTF8 if 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 encodeNonAsciiHTML function, 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;

function escapeText

escapeText: (data: string) => string;

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;

              property mode

              mode?: DecodingMode | undefined;
              • Decoding mode. If Legacy, will support legacy entities not terminated with a semicolon (;).

                Always Strict for 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;

              property mode

              mode?: EncodingMode;

              Enums

              enum DecodingMode

              enum DecodingMode {
              Legacy = 0,
              Strict = 1,
              Attribute = 2,
              }
              • Decoding mode for named entities.

              member Attribute

              Attribute = 2
              • Entities in attributes have limitations on ending characters.

              member Legacy

              Legacy = 0
              • Entities in text nodes that can end with any character.

              member Strict

              Strict = 1
              • Only allow entities terminated with a semicolon.

              enum EncodingMode

              enum EncodingMode {
              UTF8 = 0,
              ASCII = 1,
              Extensive = 2,
              Attribute = 3,
              Text = 4,
              }
              • Encoding strategy used by encode.

              member ASCII

              ASCII = 1
              • The 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 = 3

              member Extensive

              Extensive = 2
              • Encode all characters that have an equivalent entity, as well as all characters that are not ASCII characters.

              member Text

              Text = 4

              member UTF8

              UTF8 = 0
              • The 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.

              member HTML

              HTML = 1
              • Support HTML entities, which are a superset of XML entities.

              member XML

              XML = 0
              • Support only XML entities.

              Package Files (4)

              Dependencies (0)

              No dependencies.

              Dev Dependencies (11)

              Peer Dependencies (0)

              No peer dependencies.

              Badge

              To add a badge like this onejsDocs.io badgeto 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
                [![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](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>