Skip to content

Commit

Permalink
Require Node.js 10
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus committed Jan 15, 2020
1 parent c8585cf commit 1bad680
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 20 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
language: node_js
node_js:
- '12'
- '10'
- '8'
8 changes: 4 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ exports.htmlEscape = (strings, ...values) => {
}

let output = strings[0];
for (let i = 0; i < values.length; i++) {
output = output + htmlEscape(String(values[i])) + strings[i + 1];
for (const [index, value] of values.entries()) {
output = output + htmlEscape(String(value)) + strings[index + 1];
}

return output;
Expand All @@ -33,8 +33,8 @@ exports.htmlUnescape = (strings, ...values) => {
}

let output = strings[0];
for (let i = 0; i < values.length; i++) {
output = output + htmlUnescape(String(values[i])) + strings[i + 1];
for (const [index, value] of values.entries()) {
output = output + htmlUnescape(String(value)) + strings[index + 1];
}

return output;
Expand Down
9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@
"description": "Escape a string for use in HTML or the inverse",
"license": "MIT",
"repository": "sindresorhus/escape-goat",
"funding": "https://github.com/sponsors/sindresorhus",
"author": {
"name": "Sindre Sorhus",
"email": "[email protected]",
"url": "sindresorhus.com"
},
"engines": {
"node": ">=8"
"node": ">=10"
},
"scripts": {
"test": "xo && ava && tsd"
Expand Down Expand Up @@ -38,8 +39,8 @@
"🐐"
],
"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"
}
}
12 changes: 1 addition & 11 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,12 @@
[![Build Status](https://travis-ci.org/sindresorhus/escape-goat.svg?branch=master)](https://travis-ci.org/sindresorhus/escape-goat)


## Install

```
$ npm install escape-goat
```


## Usage

```js
Expand All @@ -39,7 +37,6 @@ htmlUnescape`URL from HTML: ${url}`;
//=> 'URL from HTML: https://sindresorhus.com?x="🦄"'
```


## API

### htmlEscape(string)
Expand All @@ -52,21 +49,14 @@ The function also works as a [tagged template literal](https://developer.mozilla

Unescapes the following HTML entities in the given `htmlString` argument: `&amp;` `&lt;` `&gt;` `&quot;` `&#39;`

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.

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.

## Tip

Ensure you always quote your HTML attributes to prevent possible [XSS](https://en.wikipedia.org/wiki/Cross-site_scripting).


## 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()`.


## License

MIT © [Sindre Sorhus](https://sindresorhus.com)

0 comments on commit 1bad680

Please sign in to comment.