Travis build: 1268
This commit is contained in:
31
README.md
31
README.md
@ -314,6 +314,7 @@ average(1, 2, 3);
|
||||
* [`toSnakeCase`](#tosnakecase)
|
||||
* [`truncateString`](#truncatestring)
|
||||
* [`unescapeHTML`](#unescapehtml)
|
||||
* [`URLJoin`](#urljoin)
|
||||
* [`words`](#words)
|
||||
|
||||
</details>
|
||||
@ -5118,6 +5119,36 @@ unescapeHTML('<a href="#">Me & you</a>'); // '<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
@ -6,7 +6,8 @@ Use `String.join('/')` to combine URL segments, then a series of `String.replace
|
||||
|
||||
```js
|
||||
const URLJoin = (...args) =>
|
||||
args.join('/')
|
||||
args
|
||||
.join('/')
|
||||
.replace(/[\/]+/g, '/')
|
||||
.replace(/^(.+):\//, '$1://')
|
||||
.replace(/^file:/, 'file:/')
|
||||
|
||||
Reference in New Issue
Block a user