Socket
Socket
Sign inDemoInstall

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 3.0.0 to 4.0.0

28

index.d.ts

@@ -20,30 +20,30 @@ /**

/**
Unescape an HTML string to use as a plain string.
[Tagged template literal](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Template_literals#Tagged_template_literals) that escapes interpolated values.
Unescapes the following HTML entities in the given `htmlString` argument: `&` `<` `>` `"` `'`.
@example
```
import {htmlUnescape} from 'escape-goat';
import {htmlEscape} from 'escape-goat';
htmlUnescape('🦄 & 🐐');
//=> '🦄 & 🐐'
const url = 'https://sindresorhus.com?x="🦄"';
htmlEscape`<a href="${url}">Unicorn</a>`;
//=> '<a href="https://sindresorhus.com?x=&quot;🦄&quot;">Unicorn</a>'
```
*/
export function htmlUnescape(htmlString: string): string;
export function htmlEscape(template: TemplateStringsArray, ...substitutions: readonly unknown[]): string;
/**
[Tagged template literal](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Template_literals#Tagged_template_literals) that escapes interpolated values.
Unescape an HTML string to use as a plain string.
Unescapes the following HTML entities in the given `htmlString` argument: `&amp;` `&lt;` `&gt;` `&quot;` `&#39;`.
@example
```
import {htmlEscape} from 'escape-goat';
import {htmlUnescape} from 'escape-goat';
const url = 'https://sindresorhus.com?x="🦄"';
htmlEscape`<a href="${url}">Unicorn</a>`;
//=> '<a href="https://sindresorhus.com?x=&quot;🦄&quot;">Unicorn</a>'
htmlUnescape('🦄 &amp; 🐐');
//=> '🦄 & 🐐'
```
*/
export function htmlEscape(template: TemplateStringsArray, ...substitutions: readonly unknown[]): string;
export function htmlUnescape(htmlString: string): string;

@@ -50,0 +50,0 @@ /**

@@ -1,4 +0,2 @@

'use strict';
const htmlEscape = string => string
const _htmlEscape = string => string
.replace(/&/g, '&amp;')

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

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

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

exports.htmlEscape = (strings, ...values) => {
export function htmlEscape(strings, ...values) {
if (typeof strings === 'string') {
return htmlEscape(strings);
return _htmlEscape(strings);
}

@@ -26,11 +24,11 @@

for (const [index, value] of values.entries()) {
output = output + htmlEscape(String(value)) + strings[index + 1];
output = output + _htmlEscape(String(value)) + strings[index + 1];
}
return output;
};
}
exports.htmlUnescape = (strings, ...values) => {
export function htmlUnescape(strings, ...values) {
if (typeof strings === 'string') {
return htmlUnescape(strings);
return _htmlUnescape(strings);
}

@@ -40,6 +38,6 @@

for (const [index, value] of values.entries()) {
output = output + htmlUnescape(String(value)) + strings[index + 1];
output = output + _htmlUnescape(String(value)) + strings[index + 1];
}
return output;
};
}
{
"name": "escape-goat",
"version": "3.0.0",
"version": "4.0.0",
"description": "Escape a string for use in HTML or the inverse",

@@ -11,6 +11,8 @@ "license": "MIT",

"email": "sindresorhus@gmail.com",
"url": "sindresorhus.com"
"url": "https://sindresorhus.com"
},
"type": "module",
"exports": "./index.js",
"engines": {
"node": ">=10"
"node": ">=12"
},

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

"devDependencies": {
"ava": "^2.4.0",
"tsd": "^0.11.0",
"xo": "^0.25.3"
"ava": "^3.15.0",
"tsd": "^0.14.0",
"xo": "^0.38.2"
}
}

@@ -7,4 +7,2 @@ <h1>

[![Build Status](https://travis-ci.org/sindresorhus/escape-goat.svg?branch=master)](https://travis-ci.org/sindresorhus/escape-goat)
## Install

@@ -19,3 +17,3 @@

```js
const {htmlEscape, htmlUnescape} = require('escape-goat');
import {htmlEscape, htmlUnescape} from 'escape-goat';

@@ -38,3 +36,3 @@ htmlEscape('🦄 & 🐐');

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

@@ -65,2 +63,2 @@ ```

I couldn't find one I liked that was tiny, well-tested, and had both `.escape()` and `.unescape()`.
I couldn't find one I liked that was tiny, well-tested, and had both escape and unescape methods.

Sorry, the diff of this file is not supported yet

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