escape-goat
Advanced tools
Comparing version 3.0.0 to 4.0.0
@@ -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="🦄"">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: `&` `<` `>` `"` `'`. | ||
@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="🦄"">Unicorn</a>' | ||
htmlUnescape('🦄 & 🐐'); | ||
//=> '🦄 & 🐐' | ||
``` | ||
*/ | ||
export function htmlEscape(template: TemplateStringsArray, ...substitutions: readonly unknown[]): string; | ||
export function htmlUnescape(htmlString: string): string; | ||
@@ -50,0 +50,0 @@ /** |
22
index.js
@@ -1,4 +0,2 @@ | ||
'use strict'; | ||
const htmlEscape = string => string | ||
const _htmlEscape = string => string | ||
.replace(/&/g, '&') | ||
@@ -10,3 +8,3 @@ .replace(/"/g, '"') | ||
const htmlUnescape = htmlString => htmlString | ||
const _htmlUnescape = htmlString => htmlString | ||
.replace(/>/g, '>') | ||
@@ -18,5 +16,5 @@ .replace(/</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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Yes
6280
78
61