Travis build: 600
This commit is contained in:
67
README.md
67
README.md
@ -216,6 +216,7 @@
|
||||
* [`capitalize`](#capitalize)
|
||||
* [`capitalizeEveryWord`](#capitalizeeveryword)
|
||||
* [`countVowels`](#countvowels)
|
||||
* [`escapeHTML`](#escapehtml)
|
||||
* [`escapeRegExp`](#escaperegexp)
|
||||
* [`fromCamelCase`](#fromcamelcase)
|
||||
* [`repeatString`](#repeatstring)
|
||||
@ -226,6 +227,7 @@
|
||||
* [`toKebabCase`](#tokebabcase)
|
||||
* [`toSnakeCase`](#tosnakecase)
|
||||
* [`truncateString`](#truncatestring)
|
||||
* [`unescapeHTML`](#unescapehtml)
|
||||
* [`words`](#words)
|
||||
|
||||
</details>
|
||||
@ -3276,6 +3278,39 @@ countVowels('gym'); // 0
|
||||
<br>[⬆ Back to top](#table-of-contents)
|
||||
|
||||
|
||||
### escapeHTML
|
||||
|
||||
Escapes a string for use in HTML.
|
||||
|
||||
Use `String.replace()` with a regex that matches the characters that need to be escaped, using a callback function to replace each character instance with its associated escaped character using a dictionary (object).
|
||||
|
||||
```js
|
||||
const escapeHTML = str =>
|
||||
str.replace(
|
||||
/[&<>'"]/g,
|
||||
tag =>
|
||||
({
|
||||
'&': '&',
|
||||
'<': '<',
|
||||
'>': '>',
|
||||
"'": ''',
|
||||
'"': '"'
|
||||
}[tag] || tag)
|
||||
);
|
||||
```
|
||||
|
||||
<details>
|
||||
<summary>Examples</summary>
|
||||
|
||||
```js
|
||||
escapeHTML('<a href="#">Me & you</a>'); // '<a href="#">Me & you</a>'
|
||||
```
|
||||
|
||||
</details>
|
||||
|
||||
<br>[⬆ Back to top](#table-of-contents)
|
||||
|
||||
|
||||
### escapeRegExp
|
||||
|
||||
Escapes a string to use in a regular expression.
|
||||
@ -3551,6 +3586,38 @@ truncateString('boomerang', 7); // 'boom...'
|
||||
<br>[⬆ Back to top](#table-of-contents)
|
||||
|
||||
|
||||
### unescapeHTML
|
||||
|
||||
Unescapes escaped HTML characters.
|
||||
|
||||
Use `String.replace()` with a regex that matches the characters that need to be escaped, using a callback function to replace each escaped character instance with its associated unescaped character using a dictionary (object).
|
||||
|
||||
```js
|
||||
const unescapeHTML = str =>
|
||||
str.replace(
|
||||
/&|<|>|'|"/g,
|
||||
tag =>
|
||||
({
|
||||
'&': '&',
|
||||
'<': '<',
|
||||
'>': '>',
|
||||
''': "'",
|
||||
'"': '"'
|
||||
}[tag] || tag)
|
||||
);
|
||||
```
|
||||
<details>
|
||||
<summary>Examples</summary>
|
||||
|
||||
```js
|
||||
unescapeHTML('<a href="#">Me & you</a>'); // '<a href="#">Me & you</a>'
|
||||
```
|
||||
|
||||
</details>
|
||||
|
||||
<br>[⬆ Back to top](#table-of-contents)
|
||||
|
||||
|
||||
### words
|
||||
|
||||
Converts a given string into an array of words.
|
||||
|
||||
@ -237,6 +237,7 @@
|
||||
<a class="sublink-1" href="#capitalize">capitalize</a>
|
||||
<a class="sublink-1" href="#capitalizeeveryword">capitalizeEveryWord</a>
|
||||
<a class="sublink-1" href="#countvowels">countVowels</a>
|
||||
<a class="sublink-1" href="#escapehtml">escapeHTML</a>
|
||||
<a class="sublink-1" href="#escaperegexp">escapeRegExp</a>
|
||||
<a class="sublink-1" href="#fromcamelcase">fromCamelCase</a>
|
||||
<a class="sublink-1" href="#repeatstring">repeatString</a>
|
||||
@ -247,6 +248,7 @@
|
||||
<a class="sublink-1" href="#tokebabcase">toKebabCase</a>
|
||||
<a class="sublink-1" href="#tosnakecase">toSnakeCase</a>
|
||||
<a class="sublink-1" href="#truncatestring">truncateString</a>
|
||||
<a class="sublink-1" href="#unescapehtml">unescapeHTML</a>
|
||||
<a class="sublink-1" href="#words">words</a>
|
||||
|
||||
<h3>Utility
|
||||
@ -1516,6 +1518,24 @@ capitalize('fooBar', true); // 'Foobar'
|
||||
<pre><code class="language-js">countVowels('foobar'); // 3
|
||||
countVowels('gym'); // 0
|
||||
</code></pre>
|
||||
</div></div><br/><div class="card fluid"><div class="section double-padded"><h3 id="escapehtml">escapeHTML</h3></div><div class="section double-padded">
|
||||
<p>Escapes a string for use in HTML.</p>
|
||||
<p>Use <code>String.replace()</code> with a regex that matches the characters that need to be escaped, using a callback function to replace each character instance with its associated escaped character using a dictionary (object).</p>
|
||||
<pre><code class="language-js">const escapeHTML = str =>
|
||||
str.replace(
|
||||
/[&<>'"]/g,
|
||||
tag =>
|
||||
({
|
||||
'&': '&amp;',
|
||||
'<': '&lt;',
|
||||
'>': '&gt;',
|
||||
"'": '&#39;',
|
||||
'"': '&quot;'
|
||||
}[tag] || tag)
|
||||
);
|
||||
</code></pre>
|
||||
<pre><code class="language-js">escapeHTML('<a href="#">Me & you</a>'); // '&lt;a href=&quot;#&quot;&gt;Me &amp; you&lt;/a&gt;'
|
||||
</code></pre>
|
||||
</div></div><br/><div class="card fluid"><div class="section double-padded"><h3 id="escaperegexp">escapeRegExp</h3></div><div class="section double-padded">
|
||||
<p>Escapes a string to use in a regular expression.</p>
|
||||
<p>Use <code>replace()</code> to escape special characters.</p>
|
||||
@ -1641,6 +1661,24 @@ Return the string truncated to the desired length, with <code>...</code> appende
|
||||
</code></pre>
|
||||
<pre><code class="language-js">truncateString('boomerang', 7); // 'boom...'
|
||||
</code></pre>
|
||||
</div></div><br/><div class="card fluid"><div class="section double-padded"><h3 id="unescapehtml">unescapeHTML</h3></div><div class="section double-padded">
|
||||
<p>Unescapes escaped HTML characters.</p>
|
||||
<p>Use <code>String.replace()</code> with a regex that matches the characters that need to be escaped, using a callback function to replace each escaped character instance with its associated unescaped character using a dictionary (object).</p>
|
||||
<pre><code class="language-js">const unescapeHTML = str =>
|
||||
str.replace(
|
||||
/&amp;|&lt;|&gt;|&#39;|&quot;/g,
|
||||
tag =>
|
||||
({
|
||||
'&amp;': '&',
|
||||
'&lt;': '<',
|
||||
'&gt;': '>',
|
||||
'&#39;': "'",
|
||||
'&quot;': '"'
|
||||
}[tag] || tag)
|
||||
);
|
||||
</code></pre>
|
||||
<pre><code class="language-js">unescapeHTML('&lt;a href=&quot;#&quot;&gt;Me &amp; you&lt;/a&gt;'); // '<a href="#">Me & you</a>'
|
||||
</code></pre>
|
||||
</div></div><br/><div class="card fluid"><div class="section double-padded"><h3 id="words">words</h3></div><div class="section double-padded">
|
||||
<p>Converts a given string into an array of words.</p>
|
||||
<p>Use <code>String.split()</code> with a supplied pattern (defaults to non-alpha as a regex) to convert to an array of strings. Use <code>Array.filter()</code> to remove any empty strings.
|
||||
|
||||
@ -5,13 +5,18 @@ Escapes a string for use in HTML.
|
||||
Use `String.replace()` with a regex that matches the characters that need to be escaped, using a callback function to replace each character instance with its associated escaped character using a dictionary (object).
|
||||
|
||||
```js
|
||||
const escapeHTML = str => str.replace(/[&<>'"]/g, tag => ({
|
||||
'&': '&',
|
||||
'<': '<',
|
||||
'>': '>',
|
||||
'\'': ''',
|
||||
'"': '"'
|
||||
})[tag] || tag);
|
||||
const escapeHTML = str =>
|
||||
str.replace(
|
||||
/[&<>'"]/g,
|
||||
tag =>
|
||||
({
|
||||
'&': '&',
|
||||
'<': '<',
|
||||
'>': '>',
|
||||
"'": ''',
|
||||
'"': '"'
|
||||
}[tag] || tag)
|
||||
);
|
||||
```
|
||||
|
||||
```js
|
||||
|
||||
@ -5,13 +5,19 @@ Unescapes escaped HTML characters.
|
||||
Use `String.replace()` with a regex that matches the characters that need to be escaped, using a callback function to replace each escaped character instance with its associated unescaped character using a dictionary (object).
|
||||
|
||||
```js
|
||||
const unescapeHTML = str => str.replace(/&|<|>|'|"/g, tag => ({
|
||||
'&': '&',
|
||||
'<': '<',
|
||||
'>': '>',
|
||||
''': '\'',
|
||||
'"': '"'
|
||||
})[tag] || tag);```
|
||||
const unescapeHTML = str =>
|
||||
str.replace(
|
||||
/&|<|>|'|"/g,
|
||||
tag =>
|
||||
({
|
||||
'&': '&',
|
||||
'<': '<',
|
||||
'>': '>',
|
||||
''': "'",
|
||||
'"': '"'
|
||||
}[tag] || tag)
|
||||
);
|
||||
```
|
||||
```js
|
||||
unescapeHTML('<a href="#">Me & you</a>'); // '<a href="#">Me & you</a>'
|
||||
```
|
||||
|
||||
@ -29,8 +29,8 @@ distinctValuesOfArray:array
|
||||
dropElements:array
|
||||
dropRight:array
|
||||
elementIsVisibleInViewport:browser
|
||||
escapeRegExp:string
|
||||
escapeHTML:string
|
||||
escapeRegExp:string
|
||||
everyNth:array
|
||||
extendHex:utility
|
||||
factorial:math
|
||||
|
||||
Reference in New Issue
Block a user