Travis build: 1268

This commit is contained in:
30secondsofcode
2018-01-16 16:52:18 +00:00
parent 934bb0f079
commit d446ab4415
3 changed files with 50 additions and 8 deletions

View File

@ -314,6 +314,7 @@ average(1, 2, 3);
* [`toSnakeCase`](#tosnakecase)
* [`truncateString`](#truncatestring)
* [`unescapeHTML`](#unescapehtml)
* [`URLJoin`](#urljoin)
* [`words`](#words)
</details>
@ -5118,6 +5119,36 @@ unescapeHTML('&lt;a href=&quot;#&quot;&gt;Me &amp; you&lt;/a&gt;'); // '<a href=
<br>[⬆ Back to top](#table-of-contents)
### URLJoin
Joins all given URL segments together, then normalizes the resulting URL.
Use `String.join('/')` to combine URL segments, then a series of `String.replace()` calls with various regexps to normalize the resulting URL (remove double slashes, add proper slashes for protocol, remove slashes before parameters, combine parameters with `'&'` and normalize first parameter delimiter).
```js
const URLJoin = (...args) =>
args
.join('/')
.replace(/[\/]+/g, '/')
.replace(/^(.+):\//, '$1://')
.replace(/^file:/, 'file:/')
.replace(/\/(\?|&|#[^!])/g, '$1')
.replace(/\?/g, '&')
.replace('&', '?');
```
<details>
<summary>Examples</summary>
```js
URLJoin('http://www.google.com', 'a', '/b/cd', '?foo=123', '?bar=foo'); // 'http://www.google.com/a/b/cd?foo=123&bar=foo'
```
</details>
<br>[⬆ Back to top](#table-of-contents)
### words
Converts a given string into an array of words.

File diff suppressed because one or more lines are too long

View File

@ -6,13 +6,14 @@ Use `String.join('/')` to combine URL segments, then a series of `String.replace
```js
const URLJoin = (...args) =>
args.join('/')
.replace(/[\/]+/g,'/')
.replace(/^(.+):\//,'$1://')
.replace(/^file:/,'file:/')
.replace(/\/(\?|&|#[^!])/g, '$1')
.replace(/\?/g,'&')
.replace('&','?');
args
.join('/')
.replace(/[\/]+/g, '/')
.replace(/^(.+):\//, '$1://')
.replace(/^file:/, 'file:/')
.replace(/\/(\?|&|#[^!])/g, '$1')
.replace(/\?/g, '&')
.replace('&', '?');
```
```js