entities

  • Version 3.0.1
  • Published
  • 171 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

Index

Variables

variable escape

const escape: (str: string) => string;
  • Encodes all non-ASCII characters, as well as characters not valid in XML documents using numeric hexadecimal 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: (data: string, options?: DecodingOptions | EntityLevel) => string;
  • Decodes a string with entities.

    Parameter data

    String to decode.

    Parameter options

    Decoding options.

function decodeHTML

decodeHTML: (str: string) => string;

    function decodeHTML4

    decodeHTML4: (str: string) => string;

      function decodeHTML4Strict

      decodeHTML4Strict: (str: string) => string;

        function decodeHTML5

        decodeHTML5: (str: string) => string;

          function decodeHTML5Strict

          decodeHTML5Strict: (str: string) => string;

            function decodeHTMLStrict

            decodeHTMLStrict: (str: string) => string;

              function decodeStrict

              decodeStrict: (data: string, options?: DecodingOptions | EntityLevel) => string;
              • Decodes a string with entities. Does not allow missing trailing semicolons for entities.

                Parameter data

                String to decode.

                Parameter options

                Decoding options.

                Deprecated

                Use decode with the mode set to Strict.

              function decodeXML

              decodeXML: (str: string) => string;

                function decodeXMLStrict

                decodeXMLStrict: (str: string) => string;

                  function encode

                  encode: (data: string, options?: EncodingOptions | EntityLevel) => string;
                  • Encodes a string with entities.

                    Parameter data

                    String to encode.

                    Parameter options

                    Encoding options.

                  function encodeHTML

                  encodeHTML: (data: string) => string;
                  • Encodes all entities and non-ASCII characters in the input.

                    This includes characters that are valid ASCII characters in HTML documents. For example # will be encoded as #. To get a more compact output, consider using the encodeNonAsciiHTML function.

                    If a character has no equivalent entity, a numeric hexadecimal reference (eg. ü) will be used.

                  function encodeHTML4

                  encodeHTML4: (data: string) => string;
                  • Encodes all entities and non-ASCII characters in the input.

                    This includes characters that are valid ASCII characters in HTML documents. For example # will be encoded as #. To get a more compact output, consider using the encodeNonAsciiHTML function.

                    If a character has no equivalent entity, a numeric hexadecimal reference (eg. ü) will be used.

                  function encodeHTML5

                  encodeHTML5: (data: string) => string;
                  • Encodes all entities and non-ASCII characters in the input.

                    This includes characters that are valid ASCII characters in HTML documents. For example # will be encoded as #. To get a more compact output, consider using the encodeNonAsciiHTML function.

                    If a character has no equivalent entity, a numeric hexadecimal reference (eg. ü) will be used.

                  function encodeNonAsciiHTML

                  encodeNonAsciiHTML: (data: string) => string;
                  • Encodes all non-ASCII characters, as well as characters not valid in HTML documents using HTML entities.

                    If a character has no equivalent entity, a numeric hexadecimal reference (eg. ü) will be used.

                  function encodeXML

                  encodeXML: (str: 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 hexadecimal reference (eg. ü) will be used.

                  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.

                  Interfaces

                  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,
                  }
                  • Determines whether some entities are allowed to be written without a trailing ;.

                  member Legacy

                  Legacy = 0
                  • Support legacy HTML entities.

                  member Strict

                  Strict = 1
                  • Do not support legacy HTML entities.

                  enum EncodingMode

                  enum EncodingMode {
                  UTF8 = 0,
                  ASCII = 1,
                  Extensive = 2,
                  }

                    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 Extensive

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

                    member UTF8

                    UTF8 = 0
                    • The output is UTF-8 encoded. Only characters that need escaping within HTML 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 (3)

                    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>