4.0.0 • Published 4 years ago

escape-goat v4.0.0

Weekly downloads
4,544,325
License
MIT
Repository
github
Last release
4 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_packagewhatsconcrn-tm-notifyrn-currency-formatterrn-counter-demorn-session-multiplier-demorn_unique_device_idrnttlocksausscout-chatbot-widgetreactnativelyremark-table-of-contentsrfp-librn-check-btnrn-circular-chartreleaseappsreleasern-adyen-dropinstan_vue-beautiful-chatreact-native-wtfreact-native-version-appreact-native-withframework-checksemantic-release-gitmoji-actionrich-slatetest-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_ssssdddddyyyyjawwy_library_newjawy_library_v1gamification-jawwy-libraryframework_test_library_sixdee_new_jawwytest_lib_module_aarquickcapture_react_nativern-agora-ios-m@corenode/cli@nodecorejs/climikichathexo-generator-search-indexgnurub-companionjesh-calculationjrennsoh88-react-native-scroll-indicatorjreleaseics-service
4.0.0

4 years ago

3.0.0

5 years ago

2.1.1

5 years ago

2.1.0

6 years ago

2.0.0

6 years ago

1.3.0

7 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