4.0.0 • Published 5 years ago

escape-goat v4.0.0

Weekly downloads
4,544,325
License
MIT
Repository
github
Last release
5 years ago

Escape a string for use in HTML or the inverse

Install

$ npm install escape-goat

Usage

import {htmlEscape, htmlUnescape} from '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: ${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 methods.

pupaeasy-select-rnreact-native-bluetooth2@determapp/viewer@determapp/viewer-serverairscanairscan-examplebb-chatreact-native-esc-pos-sahaab@borisovart/atol-kkt-moduledeneme323112@ntt_app/react-native-custom-notificationvuechatboxwidgetdiscord-music-botsreact-native-covid-sdk@saeon/quick-formmysql-formatreact-native-printer-brothersreact-native-shekhar-bridge-testcogoportutilsdyx-react@oiti/documentoscopy-react-nativequoc-test@infinitebrahmanuniverse/nolb-esc@gerhardsletten/get-urlsluminos-ui-core@everything-registry/sub-chunk-1598jawwy-sdkjawwy_gamification_releasereact-native-sphereuisphereuijawwy_libraryreact-native-credit-card-pkgreact-native-jawwy_samplegriffin-ui-librarytempstreamtest-library-123test-haptik-libwired-chatvue-n-beautiful-chatvue-beautichatvue-beautiful-chatvue-beautiful-chat-emoji-in-textvue-beautiful-chat-extendedvue-beautiful-chat-fork-qcwvue-beautiful-chat-stepanvue-beautiful-foxchatvue-beautiful-multi-chatwifi_configuration_packagewhatsconcstan_vue-beautiful-chattest-zeo-collectvision-camera-plugin-face-detectorvision-camera-plugin-scan-facesvite-live-previewvision-camera-base64-resizedvantiq-reactvue-chat-appvue-chat-bettervue-chat-ijadamsvue-chat-stepanvidyoai-uploadervite_vue3_ts_ssssdddddyyyy@rowinbot/mdx-code-formatter@praella/localisationistjreleasejrennsoh88-react-native-scroll-indicatorjesh-calculationjnf-accesscontrol-rnttljordy-frijters-test-libkhaled-salem-custom-componentsimp-vue-beautiful-chatimp-vue3-beautiful-chathw9ics-servicehong1-utilshifyhexo-generator-search-indexlionpluc-beautiful-chatlyricsifymama-exporterm2m-chartjs-plugin-crosshairslider-doc@wecraftapps/react-native-use-keyboard@tlgeo/react-native-gdal@thinxviewx/core-rn@trunkery/ui@types/escape-goat@tonysusi/vapid@thejpg/vue-beautiful-chat-widget@textlint/txtast-to-html@uppy/companion@vandai-nguyen/module_test@v2widget/widget@xiwen5566/aqara-automation-switch@yplabs-ltd/react-native-detector@zotasys/nativeagent-get-agentabwf-settings-components
4.0.0

5 years ago

3.0.0

6 years ago

2.1.1

6 years ago

2.1.0

6 years ago

2.0.0

7 years ago

1.3.0

8 years ago

1.2.0

8 years ago

1.1.0

8 years ago

1.0.1

8 years ago

1.0.0

8 years ago