4.0.0 • Published 3 years ago

escape-goat v4.0.0

Weekly downloads
4,544,325
License
MIT
Repository
github
Last release
3 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.

pupa@segment/action-destinationseasy-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_samplepayutestingphaast-chatphaast-floating-chatphaast-messagepupa-browserpnm-yph-react-native-custom-componentsproject-wajs-dv@dimerapp/edge@doublepi/chat-ui@fusuma-ex/mdx-loader@fusuma/mdx-loaderweb-resource-inlinervue-persian-chatvue-slideout-chatvue-chat-ijadamsvue-chat-stepanvue-chat-appvue-chat-betterzeo-collectzf-np@dej10/js-utils@ganbarodigital/storytracker@geeky-apo/react-native-advanced-clipboardwifi_configuration_packagewired-chatvue3-beautiful-chatwangyaling-1ayangtao-jstry-help-custom-chatvue-beautichatvue-beautiful-chatvue-beautiful-chat-emoji-in-textvue-beautiful-chat-extendedvue-beautiful-chat-fork-qcwvue-beautiful-chat-stepanvue-beautiful-foxchatvue-beautiful-multi-chatvidyoai-uploadervite_vue3_ts_ssssdddddyyyyvue-n-beautiful-chat@hemith/react-native-tnk@girish_kumar/md-utilsfluent.adflow.reactnativesdk-alphafluent.adflow.reactnativesdkfmsl@lwrjs/base-template-engine@lwrjs/base-view-provider@lwr-js/base-template-enginejawwy_library_newjawy_library_v1gamification-jawwy-libraryframework_test_library_sixdee_new_jawwytest_lib_module_aarreact-native-create-video-thumbnailreact-native-android-video-player-viewreact-native-animate-textreact-native-additionreact-native-pulsator-nativereact-native-plugpag-wrapperreact-native-rom-componentsreact-native-rtn-ips-poslin-testreact-native-savczuk-feature-libraryreact-native-sandycomponentreact-native-shared-gesturereact-native-recent-framework-update
4.0.0

3 years ago

3.0.0

4 years ago

2.1.1

5 years ago

2.1.0

5 years ago

2.0.0

5 years ago

1.3.0

7 years ago

1.2.0

7 years ago

1.1.0

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago