f57e811e38322f">30f7226d9a first commit 3 lat temu tailwind-color-palette 30f7226d9a first commit 3 lat temu tailwindcss 30f7226d9a first commit 3 lat temu thenify 30f7226d9a first commit 3 lat temu thenify-all 30f7226d9a first commit 3 lat temu to-regex-range 30f7226d9a first commit 3 lat temu tr46 30f7226d9a first commit 3 lat temu ts-interface-checker 30f7226d9a first commit 3 lat temu uglify-js 30f7226d9a first commit 3 lat temu underscore 30f7226d9a first commit 3 lat temu upper-case 30f7226d9a first commit 3 lat temu util-deprecate 30f7226d9a first commit 3 lat temu valid-data-url 30f7226d9a first commit 3 lat temu web-resource-inliner 30f7226d9a first commit 3 lat temu webidl-conversions 30f7226d9a first commit 3 lat temu whatwg-url 30f7226d9a first commit 3 lat temu wrap-ansi 30f7226d9a first commit 3 lat temu wrappy 30f7226d9a first commit 3 lat temu y18n 30f7226d9a first commit 3 lat temu yallist 30f7226d9a first commit 3 lat temu yaml 30f7226d9a first commit 3 lat temu yargs 30f7226d9a first commit 3 lat temu yargs-parser 30f7226d9a first commit 3 lat temu .yarn-integrity 30f7226d9a first commit 3 lat temu tum/network_report_server - Gogs: Simplico Git Service

説明なし

tum 30f7226d9a first commit 3 年 前
..
index.d.ts 30f7226d9a first commit 3 年 前
index.js 30f7226d9a first commit 3 年 前
license 30f7226d9a first commit 3 年 前
package.json 30f7226d9a first commit 3 年 前
readme.md 30f7226d9a first commit 3 年 前

readme.md

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('🦄 & 🐐');
//=> '🦄 & 🐐'

htmlUnescape('🦄 & 🐐');
//=> '🦄 & 🐐'

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: ${url}`;
//=> '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().