stringify-entities

WebJar for stringify-entities

License

License

MIT
GroupId

GroupId

org.webjars.npm
ArtifactId

ArtifactId

stringify-entities
Last Version

Last Version

3.0.1
Release Date

Release Date

Type

Type

jar
Description

Description

stringify-entities
WebJar for stringify-entities
Project URL

Project URL

https://www.webjars.org
Source Code Management

Source Code Management

https://github.com/wooorm/stringify-entities

Download stringify-entities

How to add to project

<!-- https://jarcasting.com/artifacts/org.webjars.npm/stringify-entities/ -->
<dependency>
    <groupId>org.webjars.npm</groupId>
    <artifactId>stringify-entities</artifactId>
    <version>3.0.1</version>
</dependency>
// https://jarcasting.com/artifacts/org.webjars.npm/stringify-entities/
implementation 'org.webjars.npm:stringify-entities:3.0.1'
// https://jarcasting.com/artifacts/org.webjars.npm/stringify-entities/
implementation ("org.webjars.npm:stringify-entities:3.0.1")
'org.webjars.npm:stringify-entities:jar:3.0.1'
<dependency org="org.webjars.npm" name="stringify-entities" rev="3.0.1">
  <artifact name="stringify-entities" type="jar" />
</dependency>
@Grapes(
@Grab(group='org.webjars.npm', module='stringify-entities', version='3.0.1')
)
libraryDependencies += "org.webjars.npm" % "stringify-entities" % "3.0.1"
[org.webjars.npm/stringify-entities "3.0.1"]

Dependencies

compile (5)

Group / Artifact Type Version
org.webjars.npm : character-entities-legacy jar [1.0.0,2)
org.webjars.npm : character-entities-html4 jar [1.0.0,2)
org.webjars.npm : is-decimal jar [1.0.2,2)
org.webjars.npm : is-alphanumerical jar [1.0.0,2)
org.webjars.npm : is-hexadecimal jar [1.0.0,2)

Project Modules

There are no modules declared in this project.

stringify-entities

Build Status Coverage Status Downloads Size

Encode HTML character references.

  • Very fast
  • Just the encoding part
  • Has either all the options you need for a minifier/prettifier, or a tiny size w/ stringify-entities/light
  • Reliable: '`' characters are escaped to ensure no scripts run in Internet Explorer 6 to 8. Additionally, only named references recognized by HTML4 are encoded, meaning the infamous &apos; (which people think is a virus) won’t show up

Algorithm

By default, all dangerous, non-ASCII, and non-printable ASCII characters are encoded. A subset of characters can be given to encode just those characters. Alternatively, pass escapeOnly to escape just the dangerous characters (", ', <, >, &, `). By default, hexadecimal character references are used. Pass useNamedReferences to use named character references when possible, or useShortestReferences to use whichever is shortest: decimal, hexadecimal, or named. There is also a stringify-entities/light module, which works just like stringifyEntities but without the formatting options: it’s much smaller but always outputs hexadecimal character references.

Install

npm:

npm install stringify-entities

Use

var stringify = require('stringify-entities')

stringify('alpha © bravo ≠ charlie 𝌆 delta')
// => 'alpha &#xA9; bravo &#x2260; charlie &#x1D306; delta'

stringify('alpha © bravo ≠ charlie 𝌆 delta', {useNamedReferences: true})
// => 'alpha &copy; bravo &ne; charlie &#x1D306; delta'

API

stringifyEntities(value[, options])

Encode special characters in value.

options
Core options
options.escapeOnly

Whether to only escape possibly dangerous characters (boolean, default: false). Those characters are ", &, ', <, >, and `.

options.subset

Whether to only escape the given subset of characters (Array.<string>). Note that only BMP characters are supported here (so no emoji).

Formatting options

If you do not care about these, use stringify-entities/light, which always outputs hexadecimal character references.

options.useNamedReferences

Prefer named character references (&amp;) where possible (boolean?, default: false).

options.useShortestReferences

Prefer the shortest possible reference, if that results in less bytes (boolean?, default: false). Note: useNamedReferences can be omitted when using useShortestReferences.

options.omitOptionalSemicolons

Whether to omit semicolons when possible (boolean?, default: false). Note: This creates what HTML calls “parse errors” but is otherwise still valid HTML — don’t use this except when building a minifier.

Omitting semicolons is possible for legacy named references in certain cases, and numeric references in some cases.

options.attribute

Only needed when operating dangerously with omitOptionalSemicolons: true. Create character references which don’t fail in attributes (boolean?, default: false).

Related

License

MIT © Titus Wormer

Versions

Version
3.0.1
2.0.0
1.3.2