escape-goat

WebJar for escape-goat

License

License

MIT
GroupId

GroupId

org.webjars.npm
ArtifactId

ArtifactId

escape-goat
Last Version

Last Version

2.1.1
Release Date

Release Date

Type

Type

jar
Description

Description

escape-goat
WebJar for escape-goat
Project URL

Project URL

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

Source Code Management

https://github.com/sindresorhus/escape-goat

Download escape-goat

How to add to project

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

Dependencies

There are no dependencies for this project. It is a standalone project that does not depend on any other jars.

Project Modules

There are no modules declared in this project.

escape-goat

Escape a string for use in HTML or the inverse

Build Status

Install

$ npm install escape-goat

Usage

const {htmlEscape, htmlUnescape} = require('escape-goat');

htmlEscape('๐Ÿฆ„ & ๐Ÿ');
//=> '๐Ÿฆ„ &amp; ๐Ÿ'

htmlUnescape('๐Ÿฆ„ &amp; ๐Ÿ');
//=> '๐Ÿฆ„ & ๐Ÿ'

htmlEscape('Hello <em>World</em>');
//=> 'Hello &lt;em&gt;World&lt;/em&gt;'

const url = 'https://sindresorhus.com?x="๐Ÿฆ„"';

htmlEscape`<a href="${url}">Unicorn</a>`;
//=> '<a href="https://sindresorhus.com?x=&quot;๐Ÿฆ„&quot;">Unicorn</a>'

const escapedUrl = 'https://sindresorhus.com?x=&quot;๐Ÿฆ„&quot;';

htmlUnescape`URL from HTML: ${escapedUrl}`;
//=> 'URL from HTML: https://sindresorhus.com?x="๐Ÿฆ„"'

API

htmlEscape(string)

Escapes the following characters in the given string argument: & < > " '

The function also works as a tagged template literal that escapes interpolated values.

htmlUnescape(htmlString)

Unescapes the following HTML entities in the given htmlString argument: &amp; &lt; &gt; &quot; &#39;

The function also works as a tagged template literal that unescapes interpolated values.

Tip

Ensure you always quote your HTML attributes to prevent possible XSS.

FAQ

Why yet another HTML escaping package?

I couldn't find one I liked that was tiny, well-tested, and had both .escape() and .unescape().

Versions

Version
2.1.1