@wordpress/url
Advanced tools
Comparing version 2.4.0 to 2.5.0
@@ -13,2 +13,7 @@ /** | ||
* | ||
* @example | ||
* ```js | ||
* const isURL = isURL( 'https://wordpress.org' ); // true | ||
* ``` | ||
* | ||
* @return {boolean} Whether or not it looks like a URL. | ||
@@ -25,2 +30,8 @@ */ | ||
* | ||
* @example | ||
* ```js | ||
* const protocol1 = getProtocol( 'tel:012345678' ); // 'tel:' | ||
* const protocol2 = getProtocol( 'https://wordpress.org' ); // 'https:' | ||
* ``` | ||
* | ||
* @return {?string} The protocol part of the URL. | ||
@@ -41,2 +52,8 @@ */ | ||
* | ||
* @example | ||
* ```js | ||
* const isValid = isValidProtocol( 'https:' ); // true | ||
* const isNotValid = isValidProtocol( 'https :' ); // false | ||
* ``` | ||
* | ||
* @return {boolean} True if the argument is a valid protocol (e.g. http:, tel:). | ||
@@ -57,2 +74,8 @@ */ | ||
* | ||
* @example | ||
* ```js | ||
* const authority1 = getAuthority( 'https://wordpress.org/help/' ); // 'wordpress.org' | ||
* const authority2 = getAuthority( 'https://localhost:8080/test/' ); // 'localhost:8080' | ||
* ``` | ||
* | ||
* @return {?string} The authority part of the URL. | ||
@@ -73,2 +96,8 @@ */ | ||
* | ||
* @example | ||
* ```js | ||
* const isValid = isValidAuthority( 'wordpress.org' ); // true | ||
* const isNotValid = isValidAuthority( 'wordpress#org' ); // false | ||
* ``` | ||
* | ||
* @return {boolean} True if the argument contains a valid authority. | ||
@@ -89,2 +118,8 @@ */ | ||
* | ||
* @example | ||
* ```js | ||
* const path1 = getPath( 'http://localhost:8080/this/is/a/test?query=true' ); // 'this/is/a/test' | ||
* const path2 = getPath( 'https://wordpress.org/help/faq/' ); // 'help/faq' | ||
* ``` | ||
* | ||
* @return {?string} The path part of the URL. | ||
@@ -105,2 +140,8 @@ */ | ||
* | ||
* @example | ||
* ```js | ||
* const isValid = isValidPath( 'test/path/' ); // true | ||
* const isNotValid = isValidPath( '/invalid?test/path/' ); // false | ||
* ``` | ||
* | ||
* @return {boolean} True if the argument contains a valid path | ||
@@ -121,2 +162,8 @@ */ | ||
* | ||
* @example | ||
* ```js | ||
* const queryString1 = getQueryString( 'http://localhost:8080/this/is/a/test?query=true#fragment' ); // 'query=true' | ||
* const queryString2 = getQueryString( 'https://wordpress.org#fragment?query=false&search=hello' ); // 'query=false&search=hello' | ||
* ``` | ||
* | ||
* @return {?string} The query string part of the URL. | ||
@@ -137,2 +184,8 @@ */ | ||
* | ||
* @example | ||
* ```js | ||
* const isValid = isValidQueryString( 'query=true&another=false' ); // true | ||
* const isNotValid = isValidQueryString( 'query=true?another=false' ); // false | ||
* ``` | ||
* | ||
* @return {boolean} True if the argument contains a valid query string. | ||
@@ -153,2 +206,8 @@ */ | ||
* | ||
* @example | ||
* ```js | ||
* const fragment1 = getFragment( 'http://localhost:8080/this/is/a/test?query=true#fragment' ); // '#fragment' | ||
* const fragment2 = getFragment( 'https://wordpress.org#another-fragment?query=true' ); // '#another-fragment' | ||
* ``` | ||
* | ||
* @return {?string} The fragment part of the URL. | ||
@@ -169,2 +228,8 @@ */ | ||
* | ||
* @example | ||
* ```js | ||
* const isValid = isValidFragment( '#valid-fragment' ); // true | ||
* const isNotValid = isValidFragment( '#invalid-#fragment' ); // false | ||
* ``` | ||
* | ||
* @return {boolean} True if the argument contains a valid fragment. | ||
@@ -189,2 +254,7 @@ */ | ||
* | ||
* @example | ||
* ```js | ||
* const newURL = addQueryArgs( 'https://google.com', { q: 'test' } ); // https://google.com/?q=test | ||
* ``` | ||
* | ||
* @return {string} URL with arguments applied. | ||
@@ -221,2 +291,7 @@ */ | ||
* | ||
* @example | ||
* ```js | ||
* const foo = getQueryArg( 'https://wordpress.org?foo=bar&bar=baz', 'foo' ); // bar | ||
* ``` | ||
* | ||
* @return {Array|string} Query arg value. | ||
@@ -236,2 +311,7 @@ */ | ||
* | ||
* @example | ||
* ```js | ||
* const hasBar = hasQueryArg( 'https://wordpress.org?foo=bar&bar=baz', 'bar' ); // true | ||
* ``` | ||
* | ||
* @return {boolean} Whether or not the URL contains the query arg. | ||
@@ -249,2 +329,7 @@ */ | ||
* | ||
* @example | ||
* ```js | ||
* const newUrl = removeQueryArgs( 'https://wordpress.org?foo=bar&bar=baz&baz=foobar', 'foo', 'bar' ); // https://wordpress.org?baz=foobar | ||
* ``` | ||
* | ||
* @return {string} Updated URL | ||
@@ -272,2 +357,7 @@ */ | ||
* | ||
* @example | ||
* ```js | ||
* const actualURL = prependHTTP( 'wordpress.org' ); // http://wordpress.org | ||
* ``` | ||
* | ||
* @return {string} The updated URL | ||
@@ -289,2 +379,7 @@ */ | ||
* | ||
* @example | ||
* ```js | ||
* const badUri = safeDecodeURI( '%z' ); // does not throw an Error, simply returns '%z' | ||
* ``` | ||
* | ||
* @return {string} Decoded URI if possible. | ||
@@ -305,2 +400,7 @@ */ | ||
* | ||
* @example | ||
* ```js | ||
* const displayUrl = filterURLForDisplay( 'https://www.wordpress.org/gutenberg/' ); // wordpress.org/gutenberg | ||
* ``` | ||
* | ||
* @return {string} Displayed URL. | ||
@@ -307,0 +407,0 @@ */ |
@@ -39,2 +39,7 @@ "use strict"; | ||
* | ||
* @example | ||
* ```js | ||
* const isURL = isURL( 'https://wordpress.org' ); // true | ||
* ``` | ||
* | ||
* @return {boolean} Whether or not it looks like a URL. | ||
@@ -51,2 +56,8 @@ */ | ||
* | ||
* @example | ||
* ```js | ||
* const protocol1 = getProtocol( 'tel:012345678' ); // 'tel:' | ||
* const protocol2 = getProtocol( 'https://wordpress.org' ); // 'https:' | ||
* ``` | ||
* | ||
* @return {?string} The protocol part of the URL. | ||
@@ -68,2 +79,8 @@ */ | ||
* | ||
* @example | ||
* ```js | ||
* const isValid = isValidProtocol( 'https:' ); // true | ||
* const isNotValid = isValidProtocol( 'https :' ); // false | ||
* ``` | ||
* | ||
* @return {boolean} True if the argument is a valid protocol (e.g. http:, tel:). | ||
@@ -85,2 +102,8 @@ */ | ||
* | ||
* @example | ||
* ```js | ||
* const authority1 = getAuthority( 'https://wordpress.org/help/' ); // 'wordpress.org' | ||
* const authority2 = getAuthority( 'https://localhost:8080/test/' ); // 'localhost:8080' | ||
* ``` | ||
* | ||
* @return {?string} The authority part of the URL. | ||
@@ -102,2 +125,8 @@ */ | ||
* | ||
* @example | ||
* ```js | ||
* const isValid = isValidAuthority( 'wordpress.org' ); // true | ||
* const isNotValid = isValidAuthority( 'wordpress#org' ); // false | ||
* ``` | ||
* | ||
* @return {boolean} True if the argument contains a valid authority. | ||
@@ -119,2 +148,8 @@ */ | ||
* | ||
* @example | ||
* ```js | ||
* const path1 = getPath( 'http://localhost:8080/this/is/a/test?query=true' ); // 'this/is/a/test' | ||
* const path2 = getPath( 'https://wordpress.org/help/faq/' ); // 'help/faq' | ||
* ``` | ||
* | ||
* @return {?string} The path part of the URL. | ||
@@ -136,2 +171,8 @@ */ | ||
* | ||
* @example | ||
* ```js | ||
* const isValid = isValidPath( 'test/path/' ); // true | ||
* const isNotValid = isValidPath( '/invalid?test/path/' ); // false | ||
* ``` | ||
* | ||
* @return {boolean} True if the argument contains a valid path | ||
@@ -153,2 +194,8 @@ */ | ||
* | ||
* @example | ||
* ```js | ||
* const queryString1 = getQueryString( 'http://localhost:8080/this/is/a/test?query=true#fragment' ); // 'query=true' | ||
* const queryString2 = getQueryString( 'https://wordpress.org#fragment?query=false&search=hello' ); // 'query=false&search=hello' | ||
* ``` | ||
* | ||
* @return {?string} The query string part of the URL. | ||
@@ -170,2 +217,8 @@ */ | ||
* | ||
* @example | ||
* ```js | ||
* const isValid = isValidQueryString( 'query=true&another=false' ); // true | ||
* const isNotValid = isValidQueryString( 'query=true?another=false' ); // false | ||
* ``` | ||
* | ||
* @return {boolean} True if the argument contains a valid query string. | ||
@@ -187,2 +240,8 @@ */ | ||
* | ||
* @example | ||
* ```js | ||
* const fragment1 = getFragment( 'http://localhost:8080/this/is/a/test?query=true#fragment' ); // '#fragment' | ||
* const fragment2 = getFragment( 'https://wordpress.org#another-fragment?query=true' ); // '#another-fragment' | ||
* ``` | ||
* | ||
* @return {?string} The fragment part of the URL. | ||
@@ -204,2 +263,8 @@ */ | ||
* | ||
* @example | ||
* ```js | ||
* const isValid = isValidFragment( '#valid-fragment' ); // true | ||
* const isNotValid = isValidFragment( '#invalid-#fragment' ); // false | ||
* ``` | ||
* | ||
* @return {boolean} True if the argument contains a valid fragment. | ||
@@ -225,2 +290,7 @@ */ | ||
* | ||
* @example | ||
* ```js | ||
* const newURL = addQueryArgs( 'https://google.com', { q: 'test' } ); // https://google.com/?q=test | ||
* ``` | ||
* | ||
* @return {string} URL with arguments applied. | ||
@@ -258,2 +328,7 @@ */ | ||
* | ||
* @example | ||
* ```js | ||
* const foo = getQueryArg( 'https://wordpress.org?foo=bar&bar=baz', 'foo' ); // bar | ||
* ``` | ||
* | ||
* @return {Array|string} Query arg value. | ||
@@ -274,2 +349,7 @@ */ | ||
* | ||
* @example | ||
* ```js | ||
* const hasBar = hasQueryArg( 'https://wordpress.org?foo=bar&bar=baz', 'bar' ); // true | ||
* ``` | ||
* | ||
* @return {boolean} Whether or not the URL contains the query arg. | ||
@@ -288,2 +368,7 @@ */ | ||
* | ||
* @example | ||
* ```js | ||
* const newUrl = removeQueryArgs( 'https://wordpress.org?foo=bar&bar=baz&baz=foobar', 'foo', 'bar' ); // https://wordpress.org?baz=foobar | ||
* ``` | ||
* | ||
* @return {string} Updated URL | ||
@@ -312,2 +397,7 @@ */ | ||
* | ||
* @example | ||
* ```js | ||
* const actualURL = prependHTTP( 'wordpress.org' ); // http://wordpress.org | ||
* ``` | ||
* | ||
* @return {string} The updated URL | ||
@@ -330,2 +420,7 @@ */ | ||
* | ||
* @example | ||
* ```js | ||
* const badUri = safeDecodeURI( '%z' ); // does not throw an Error, simply returns '%z' | ||
* ``` | ||
* | ||
* @return {string} Decoded URI if possible. | ||
@@ -347,2 +442,7 @@ */ | ||
* | ||
* @example | ||
* ```js | ||
* const displayUrl = filterURLForDisplay( 'https://www.wordpress.org/gutenberg/' ); // wordpress.org/gutenberg | ||
* ``` | ||
* | ||
* @return {string} Displayed URL. | ||
@@ -349,0 +449,0 @@ */ |
{ | ||
"name": "@wordpress/url", | ||
"version": "2.4.0", | ||
"version": "2.5.0", | ||
"description": "WordPress URL utilities.", | ||
@@ -30,3 +30,3 @@ "author": "The WordPress Contributors", | ||
}, | ||
"gitHead": "80d228669adadb8dfcd24b8421517fed3be2d474" | ||
"gitHead": "1e024a20a20369af7bc9720a676fdd3837a3a105" | ||
} |
332
README.md
@@ -17,33 +17,55 @@ # URL | ||
### isURL | ||
<!-- START TOKEN(Autogenerated API docs) --> | ||
```js | ||
const isURL = isURL( 'https://wordpress.org' ); // true | ||
``` | ||
### addQueryArgs | ||
Checks whether the URL is an HTTP or HTTPS URL. | ||
[src/index.js#L242-L264](src/index.js#L242-L264) | ||
Appends arguments as querystring to the provided URL. If the URL already | ||
includes query arguments, the arguments are merged with (and take precedent | ||
over) the existing set. | ||
### getProtocol | ||
**Usage** | ||
```js | ||
const protocol1 = getProtocol( 'tel:012345678' ); // 'tel:' | ||
const protocol2 = getProtocol( 'https://wordpress.org' ); // 'https:' | ||
const newURL = addQueryArgs( 'https://google.com', { q: 'test' } ); // https://google.com/?q=test | ||
``` | ||
Returns the protocol part of the provided URL. | ||
**Parameters** | ||
- **url** `?string`: URL to which arguments should be appended. If omitted, only the resulting querystring is returned. | ||
- **args** `Object`: Query arguments to apply to URL. | ||
### isValidProtocol | ||
**Returns** | ||
`string`: URL with arguments applied. | ||
### filterURLForDisplay | ||
[src/index.js#L379-L389](src/index.js#L379-L389) | ||
Returns a URL for display. | ||
**Usage** | ||
```js | ||
const isValid = isValidProtocol( 'https:' ); // true | ||
const isNotValid = isValidProtocol( 'https :' ); // false | ||
const displayUrl = filterURLForDisplay( 'https://www.wordpress.org/gutenberg/' ); // wordpress.org/gutenberg | ||
``` | ||
Returns true if the provided protocol is valid. Returns false if the protocol contains invalid characters. | ||
**Parameters** | ||
- **url** `string`: Original URL. | ||
**Returns** | ||
`string`: Displayed URL. | ||
### getAuthority | ||
[src/index.js#L79-L84](src/index.js#L79-L84) | ||
Returns the authority part of the URL. | ||
**Usage** | ||
```js | ||
@@ -54,17 +76,39 @@ const authority1 = getAuthority( 'https://wordpress.org/help/' ); // 'wordpress.org' | ||
Returns the authority part of the provided URL. | ||
**Parameters** | ||
- **url** `string`: The full URL. | ||
### isValidAuthority | ||
**Returns** | ||
`?string`: The authority part of the URL. | ||
### getFragment | ||
[src/index.js#L199-L204](src/index.js#L199-L204) | ||
Returns the fragment part of the URL. | ||
**Usage** | ||
```js | ||
const isValid = isValidAuthority( 'wordpress.org' ); // true | ||
const isNotValid = isValidAuthority( 'wordpress#org' ); // false | ||
const fragment1 = getFragment( 'http://localhost:8080/this/is/a/test?query=true#fragment' ); // '#fragment' | ||
const fragment2 = getFragment( 'https://wordpress.org#another-fragment?query=true' ); // '#another-fragment' | ||
``` | ||
Returns true if the provided authority is valid. Returns false if the protocol contains invalid characters. | ||
**Parameters** | ||
- **url** `string`: The full URL | ||
**Returns** | ||
`?string`: The fragment part of the URL. | ||
### getPath | ||
[src/index.js#L119-L124](src/index.js#L119-L124) | ||
Returns the path part of the URL. | ||
**Usage** | ||
```js | ||
@@ -75,17 +119,60 @@ const path1 = getPath( 'http://localhost:8080/this/is/a/test?query=true' ); // 'this/is/a/test' | ||
Returns the path part of the provided URL. | ||
**Parameters** | ||
- **url** `string`: The full URL. | ||
### isValidPath | ||
**Returns** | ||
`?string`: The path part of the URL. | ||
### getProtocol | ||
[src/index.js#L39-L44](src/index.js#L39-L44) | ||
Returns the protocol part of the URL. | ||
**Usage** | ||
```js | ||
const isValid = isValidPath( 'test/path/' ); // true | ||
const isNotValid = isValidPath( '/invalid?test/path/' ); // false | ||
const protocol1 = getProtocol( 'tel:012345678' ); // 'tel:' | ||
const protocol2 = getProtocol( 'https://wordpress.org' ); // 'https:' | ||
``` | ||
Returns true if the provided path is valid. Returns false if the path contains invalid characters. | ||
**Parameters** | ||
- **url** `string`: The full URL. | ||
**Returns** | ||
`?string`: The protocol part of the URL. | ||
### getQueryArg | ||
[src/index.js#L279-L284](src/index.js#L279-L284) | ||
Returns a single query argument of the url | ||
**Usage** | ||
```js | ||
const foo = getQueryArg( 'https://wordpress.org?foo=bar&bar=baz', 'foo' ); // bar | ||
``` | ||
**Parameters** | ||
- **url** `string`: URL | ||
- **arg** `string`: Query arg name | ||
**Returns** | ||
`(Array|string)`: Query arg value. | ||
### getQueryString | ||
[src/index.js#L159-L164](src/index.js#L159-L164) | ||
Returns the query string part of the URL. | ||
**Usage** | ||
```js | ||
@@ -96,27 +183,80 @@ const queryString1 = getQueryString( 'http://localhost:8080/this/is/a/test?query=true#fragment' ); // 'query=true' | ||
Returns the query string part of the provided URL. | ||
**Parameters** | ||
- **url** `string`: The full URL. | ||
### isValidQueryString | ||
**Returns** | ||
`?string`: The query string part of the URL. | ||
### hasQueryArg | ||
[src/index.js#L299-L301](src/index.js#L299-L301) | ||
Determines whether the URL contains a given query arg. | ||
**Usage** | ||
```js | ||
const isValid = isValidQueryString( 'query=true&another=false' ); // true | ||
const isNotValid = isValidQueryString( 'query=true?another=false' ); // false | ||
const hasBar = hasQueryArg( 'https://wordpress.org?foo=bar&bar=baz', 'bar' ); // true | ||
``` | ||
Returns true if the provided query string is valid. Returns false if the query string contains invalid characters. | ||
**Parameters** | ||
- **url** `string`: URL | ||
- **arg** `string`: Query arg name | ||
### getFragment | ||
**Returns** | ||
`boolean`: Whether or not the URL contains the query arg. | ||
### isURL | ||
[src/index.js#L22-L24](src/index.js#L22-L24) | ||
Determines whether the given string looks like a URL. | ||
**Usage** | ||
```js | ||
const fragment1 = getFragment( 'http://localhost:8080/this/is/a/test?query=true#fragment' ); // '#fragment' | ||
const fragment2 = getFragment( 'https://wordpress.org#another-fragment?query=true' ); // '#another-fragment' | ||
const isURL = isURL( 'https://wordpress.org' ); // true | ||
``` | ||
Returns the fragment part of the provided URL. | ||
**Parameters** | ||
- **url** `string`: The string to scrutinise. | ||
**Returns** | ||
`boolean`: Whether or not it looks like a URL. | ||
### isValidAuthority | ||
[src/index.js#L99-L104](src/index.js#L99-L104) | ||
Checks for invalid characters within the provided authority. | ||
**Usage** | ||
```js | ||
const isValid = isValidAuthority( 'wordpress.org' ); // true | ||
const isNotValid = isValidAuthority( 'wordpress#org' ); // false | ||
``` | ||
**Parameters** | ||
- **authority** `string`: A string containing the URL authority. | ||
**Returns** | ||
`boolean`: True if the argument contains a valid authority. | ||
### isValidFragment | ||
[src/index.js#L219-L224](src/index.js#L219-L224) | ||
Checks for invalid characters within the provided fragment. | ||
**Usage** | ||
```js | ||
@@ -127,42 +267,101 @@ const isValid = isValidFragment( '#valid-fragment' ); // true | ||
Returns true if the provided fragment is valid. Returns false if the fragment contains invalid characters. | ||
**Parameters** | ||
- **fragment** `string`: The url fragment. | ||
### addQueryArgs | ||
**Returns** | ||
`boolean`: True if the argument contains a valid fragment. | ||
### isValidPath | ||
[src/index.js#L139-L144](src/index.js#L139-L144) | ||
Checks for invalid characters within the provided path. | ||
**Usage** | ||
```js | ||
const newURL = addQueryArgs( 'https://google.com', { q: 'test' } ); // https://google.com/?q=test | ||
const isValid = isValidPath( 'test/path/' ); // true | ||
const isNotValid = isValidPath( '/invalid?test/path/' ); // false | ||
``` | ||
Adds a query string argument to the provided URL. | ||
**Parameters** | ||
- **path** `string`: The URL path. | ||
### prependHTTP | ||
**Returns** | ||
`boolean`: True if the argument contains a valid path | ||
### isValidProtocol | ||
[src/index.js#L59-L64](src/index.js#L59-L64) | ||
Tests if a url protocol is valid. | ||
**Usage** | ||
```js | ||
const actualURL = prependHTTP( 'wordpress.org' ); // http://wordpress.org | ||
const isValid = isValidProtocol( 'https:' ); // true | ||
const isNotValid = isValidProtocol( 'https :' ); // false | ||
``` | ||
Prepends the provided partial URL with the http:// protocol. | ||
**Parameters** | ||
### getQueryArg | ||
- **protocol** `string`: The url protocol. | ||
**Returns** | ||
`boolean`: True if the argument is a valid protocol (e.g. http\:, tel:). | ||
### isValidQueryString | ||
[src/index.js#L179-L184](src/index.js#L179-L184) | ||
Checks for invalid characters within the provided query string. | ||
**Usage** | ||
```js | ||
const foo = getQueryArg( 'https://wordpress.org?foo=bar&bar=baz', 'foo' ); // bar | ||
const isValid = isValidQueryString( 'query=true&another=false' ); // true | ||
const isNotValid = isValidQueryString( 'query=true?another=false' ); // false | ||
``` | ||
Retrieve a query string argument from the provided URL. | ||
**Parameters** | ||
- **queryString** `string`: The query string. | ||
### hasQueryArg | ||
**Returns** | ||
`boolean`: True if the argument contains a valid query string. | ||
### prependHTTP | ||
[src/index.js#L338-L344](src/index.js#L338-L344) | ||
Prepends "http\://" to a url, if it looks like something that is meant to be a TLD. | ||
**Usage** | ||
```js | ||
const hasBar = hasQueryArg( 'https://wordpress.org?foo=bar&bar=baz', 'bar' ); // true | ||
const actualURL = prependHTTP( 'wordpress.org' ); // http://wordpress.org | ||
``` | ||
Checks whether a URL contains the given query string argument. | ||
**Parameters** | ||
- **url** `string`: The URL to test | ||
**Returns** | ||
`string`: The updated URL | ||
### removeQueryArgs | ||
[src/index.js#L316-L324](src/index.js#L316-L324) | ||
Removes arguments from the query string of the url | ||
**Usage** | ||
```js | ||
@@ -172,7 +371,20 @@ const newUrl = removeQueryArgs( 'https://wordpress.org?foo=bar&bar=baz&baz=foobar', 'foo', 'bar' ); // https://wordpress.org?baz=foobar | ||
Removes one or more query string arguments from the given URL. | ||
**Parameters** | ||
- **url** `string`: URL | ||
- **args** `...string`: Query Args | ||
**Returns** | ||
`string`: Updated URL | ||
### safeDecodeURI | ||
[src/index.js#L359-L365](src/index.js#L359-L365) | ||
Safely decodes a URI with `decodeURI`. Returns the URI unmodified if | ||
`decodeURI` throws an error. | ||
**Usage** | ||
```js | ||
@@ -182,12 +394,28 @@ const badUri = safeDecodeURI( '%z' ); // does not throw an Error, simply returns '%z' | ||
Safely decodes a URI with `decodeURI`. Returns the URI unmodified if `decodeURI` throws an Error. | ||
**Parameters** | ||
### filterURLForDisplay | ||
- **uri** `string`: URI to decode. | ||
```js | ||
const displayUrl = filterURLForDisplay( 'https://www.wordpress.org/gutenberg/' ); // wordpress.org/gutenberg | ||
``` | ||
**Returns** | ||
Returns a URL for display, without protocol, www subdomain, or trailing slash. | ||
`string`: Decoded URI if possible. | ||
### safeDecodeURIComponent | ||
[src/index.js#L399-L405](src/index.js#L399-L405) | ||
Safely decodes a URI component with `decodeURIComponent`. Returns the URI component unmodified if | ||
`decodeURIComponent` throws an error. | ||
**Parameters** | ||
- **uriComponent** `string`: URI component to decode. | ||
**Returns** | ||
`string`: Decoded URI component if possible. | ||
<!-- END TOKEN(Autogenerated API docs) --> | ||
<br/><br/><p align="center"><img src="https://s.w.org/style/images/codeispoetry.png?1" alt="Code is Poetry." /></p> |
100
src/index.js
@@ -15,2 +15,7 @@ /** | ||
* | ||
* @example | ||
* ```js | ||
* const isURL = isURL( 'https://wordpress.org' ); // true | ||
* ``` | ||
* | ||
* @return {boolean} Whether or not it looks like a URL. | ||
@@ -27,2 +32,8 @@ */ | ||
* | ||
* @example | ||
* ```js | ||
* const protocol1 = getProtocol( 'tel:012345678' ); // 'tel:' | ||
* const protocol2 = getProtocol( 'https://wordpress.org' ); // 'https:' | ||
* ``` | ||
* | ||
* @return {?string} The protocol part of the URL. | ||
@@ -42,2 +53,8 @@ */ | ||
* | ||
* @example | ||
* ```js | ||
* const isValid = isValidProtocol( 'https:' ); // true | ||
* const isNotValid = isValidProtocol( 'https :' ); // false | ||
* ``` | ||
* | ||
* @return {boolean} True if the argument is a valid protocol (e.g. http:, tel:). | ||
@@ -57,2 +74,8 @@ */ | ||
* | ||
* @example | ||
* ```js | ||
* const authority1 = getAuthority( 'https://wordpress.org/help/' ); // 'wordpress.org' | ||
* const authority2 = getAuthority( 'https://localhost:8080/test/' ); // 'localhost:8080' | ||
* ``` | ||
* | ||
* @return {?string} The authority part of the URL. | ||
@@ -72,2 +95,8 @@ */ | ||
* | ||
* @example | ||
* ```js | ||
* const isValid = isValidAuthority( 'wordpress.org' ); // true | ||
* const isNotValid = isValidAuthority( 'wordpress#org' ); // false | ||
* ``` | ||
* | ||
* @return {boolean} True if the argument contains a valid authority. | ||
@@ -87,2 +116,8 @@ */ | ||
* | ||
* @example | ||
* ```js | ||
* const path1 = getPath( 'http://localhost:8080/this/is/a/test?query=true' ); // 'this/is/a/test' | ||
* const path2 = getPath( 'https://wordpress.org/help/faq/' ); // 'help/faq' | ||
* ``` | ||
* | ||
* @return {?string} The path part of the URL. | ||
@@ -102,2 +137,8 @@ */ | ||
* | ||
* @example | ||
* ```js | ||
* const isValid = isValidPath( 'test/path/' ); // true | ||
* const isNotValid = isValidPath( '/invalid?test/path/' ); // false | ||
* ``` | ||
* | ||
* @return {boolean} True if the argument contains a valid path | ||
@@ -117,2 +158,8 @@ */ | ||
* | ||
* @example | ||
* ```js | ||
* const queryString1 = getQueryString( 'http://localhost:8080/this/is/a/test?query=true#fragment' ); // 'query=true' | ||
* const queryString2 = getQueryString( 'https://wordpress.org#fragment?query=false&search=hello' ); // 'query=false&search=hello' | ||
* ``` | ||
* | ||
* @return {?string} The query string part of the URL. | ||
@@ -132,2 +179,8 @@ */ | ||
* | ||
* @example | ||
* ```js | ||
* const isValid = isValidQueryString( 'query=true&another=false' ); // true | ||
* const isNotValid = isValidQueryString( 'query=true?another=false' ); // false | ||
* ``` | ||
* | ||
* @return {boolean} True if the argument contains a valid query string. | ||
@@ -147,2 +200,8 @@ */ | ||
* | ||
* @example | ||
* ```js | ||
* const fragment1 = getFragment( 'http://localhost:8080/this/is/a/test?query=true#fragment' ); // '#fragment' | ||
* const fragment2 = getFragment( 'https://wordpress.org#another-fragment?query=true' ); // '#another-fragment' | ||
* ``` | ||
* | ||
* @return {?string} The fragment part of the URL. | ||
@@ -162,2 +221,8 @@ */ | ||
* | ||
* @example | ||
* ```js | ||
* const isValid = isValidFragment( '#valid-fragment' ); // true | ||
* const isNotValid = isValidFragment( '#invalid-#fragment' ); // false | ||
* ``` | ||
* | ||
* @return {boolean} True if the argument contains a valid fragment. | ||
@@ -181,2 +246,7 @@ */ | ||
* | ||
* @example | ||
* ```js | ||
* const newURL = addQueryArgs( 'https://google.com', { q: 'test' } ); // https://google.com/?q=test | ||
* ``` | ||
* | ||
* @return {string} URL with arguments applied. | ||
@@ -214,2 +284,7 @@ */ | ||
* | ||
* @example | ||
* ```js | ||
* const foo = getQueryArg( 'https://wordpress.org?foo=bar&bar=baz', 'foo' ); // bar | ||
* ``` | ||
* | ||
* @return {Array|string} Query arg value. | ||
@@ -230,2 +305,7 @@ */ | ||
* | ||
* @example | ||
* ```js | ||
* const hasBar = hasQueryArg( 'https://wordpress.org?foo=bar&bar=baz', 'bar' ); // true | ||
* ``` | ||
* | ||
* @return {boolean} Whether or not the URL contains the query arg. | ||
@@ -243,2 +323,7 @@ */ | ||
* | ||
* @example | ||
* ```js | ||
* const newUrl = removeQueryArgs( 'https://wordpress.org?foo=bar&bar=baz&baz=foobar', 'foo', 'bar' ); // https://wordpress.org?baz=foobar | ||
* ``` | ||
* | ||
* @return {string} Updated URL | ||
@@ -261,2 +346,7 @@ */ | ||
* | ||
* @example | ||
* ```js | ||
* const actualURL = prependHTTP( 'wordpress.org' ); // http://wordpress.org | ||
* ``` | ||
* | ||
* @return {string} The updated URL | ||
@@ -278,2 +368,7 @@ */ | ||
* | ||
* @example | ||
* ```js | ||
* const badUri = safeDecodeURI( '%z' ); // does not throw an Error, simply returns '%z' | ||
* ``` | ||
* | ||
* @return {string} Decoded URI if possible. | ||
@@ -294,2 +389,7 @@ */ | ||
* | ||
* @example | ||
* ```js | ||
* const displayUrl = filterURLForDisplay( 'https://www.wordpress.org/gutenberg/' ); // wordpress.org/gutenberg | ||
* ``` | ||
* | ||
* @return {string} Displayed URL. | ||
@@ -296,0 +396,0 @@ */ |
Sorry, the diff of this file is not supported yet
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
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
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
115151
1573
415
1