Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

escape-goat

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

escape-goat - npm Package Compare versions

Comparing version 2.1.1 to 3.0.0

12

index.d.ts

@@ -39,11 +39,11 @@ /**

```
import {htmlEscapeTag} from 'escape-goat';
import {htmlEscape} from 'escape-goat';
const url = 'https://sindresorhus.com?x="🦄"';
htmlEscapeTag`<a href="${url}">Unicorn</a>`;
htmlEscape`<a href="${url}">Unicorn</a>`;
//=> '<a href="https://sindresorhus.com?x=&quot;🦄&quot;">Unicorn</a>'
```
*/
export function htmlEscapeTag(template: TemplateStringsArray, ...substitutions: readonly unknown[]): string;
export function htmlEscape(template: TemplateStringsArray, ...substitutions: readonly unknown[]): string;

@@ -55,10 +55,10 @@ /**

```
import {htmlUnescapeTag} from 'escape-goat';
import {htmlUnescape} from 'escape-goat';
const escapedUrl = 'https://sindresorhus.com?x=&quot;🦄&quot;';
htmlUnescapeTag`URL from HTML: ${url}`;
htmlUnescape`URL from HTML: ${url}`;
//=> 'URL from HTML: https://sindresorhus.com?x="🦄"'
```
*/
export function htmlUnescapeTag(template: TemplateStringsArray, ...substitutions: readonly unknown[]): string;
export function htmlUnescape(template: TemplateStringsArray, ...substitutions: readonly unknown[]): string;
'use strict';
exports.htmlEscape = string => string
const htmlEscape = string => string
.replace(/&/g, '&amp;')

@@ -10,3 +10,3 @@ .replace(/"/g, '&quot;')

exports.htmlUnescape = htmlString => htmlString
const htmlUnescape = htmlString => htmlString
.replace(/&gt;/g, '>')

@@ -18,6 +18,10 @@ .replace(/&lt;/g, '<')

exports.htmlEscapeTag = (strings, ...values) => {
exports.htmlEscape = (strings, ...values) => {
if (typeof strings === 'string') {
return htmlEscape(strings);
}
let output = strings[0];
for (let i = 0; i < values.length; i++) {
output = output + exports.htmlEscape(String(values[i])) + strings[i + 1];
for (const [index, value] of values.entries()) {
output = output + htmlEscape(String(value)) + strings[index + 1];
}

@@ -28,6 +32,10 @@

exports.htmlUnescapeTag = (strings, ...values) => {
exports.htmlUnescape = (strings, ...values) => {
if (typeof strings === 'string') {
return htmlUnescape(strings);
}
let output = strings[0];
for (let i = 0; i < values.length; i++) {
output = output + exports.htmlUnescape(String(values[i])) + strings[i + 1];
for (const [index, value] of values.entries()) {
output = output + htmlUnescape(String(value)) + strings[index + 1];
}

@@ -34,0 +42,0 @@

{
"name": "escape-goat",
"version": "2.1.1",
"version": "3.0.0",
"description": "Escape a string for use in HTML or the inverse",
"license": "MIT",
"repository": "sindresorhus/escape-goat",
"funding": "https://github.com/sponsors/sindresorhus",
"author": {

@@ -13,3 +14,3 @@ "name": "Sindre Sorhus",

"engines": {
"node": ">=8"
"node": ">=10"
},

@@ -42,6 +43,6 @@ "scripts": {

"devDependencies": {
"ava": "^1.4.1",
"tsd": "^0.7.2",
"xo": "^0.24.0"
"ava": "^2.4.0",
"tsd": "^0.11.0",
"xo": "^0.25.3"
}
}

@@ -9,3 +9,2 @@ <h1>

## Install

@@ -17,7 +16,6 @@

## Usage
```js
const {htmlEscape, htmlUnescape, htmlEscapeTag, htmlUnescapeTag} = require('escape-goat');
const {htmlEscape, htmlUnescape} = require('escape-goat');

@@ -35,3 +33,3 @@ htmlEscape('🦄 & 🐐');

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

@@ -41,7 +39,6 @@

htmlUnescapeTag`URL from HTML: ${url}`;
htmlUnescape`URL from HTML: ${url}`;
//=> 'URL from HTML: https://sindresorhus.com?x="🦄"'
```
## API

@@ -53,2 +50,4 @@

The function also works as a [tagged template literal](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Template_literals#Tagged_template_literals) that escapes interpolated values.
### htmlUnescape(htmlString)

@@ -58,11 +57,4 @@

### htmlEscapeTag
The function also works as a [tagged template literal](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Template_literals#Tagged_template_literals) that unescapes interpolated values.
[Tagged template literal](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Template_literals#Tagged_template_literals) that escapes interpolated values.
### htmlUnescapeTag
[Tagged template literal](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Template_literals#Tagged_template_literals) that unescapes interpolated values.
## Tip

@@ -72,3 +64,2 @@

## FAQ

@@ -79,6 +70,1 @@

I couldn't find one I liked that was tiny, well-tested, and had both `.escape()` and `.unescape()`.
## License
MIT © [Sindre Sorhus](https://sindresorhus.com)
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc