@wordpress/url
Advanced tools
Comparing version 2.5.0 to 2.6.0
@@ -25,2 +25,18 @@ /** | ||
/** | ||
* Determines whether the given string looks like an email. | ||
* | ||
* @param {string} email The string to scrutinise. | ||
* | ||
* @example | ||
* ```js | ||
* const isEmail = isEmail( 'hello@wordpress.org' ); // true | ||
* ``` | ||
* | ||
* @return {boolean} Whether or not it looks like an email. | ||
*/ | ||
export function isEmail(email) { | ||
return EMAIL_REGEXP.test(email); | ||
} | ||
/** | ||
* Returns the protocol part of the URL. | ||
@@ -27,0 +43,0 @@ * |
@@ -7,2 +7,3 @@ "use strict"; | ||
exports.isURL = isURL; | ||
exports.isEmail = isEmail; | ||
exports.getProtocol = getProtocol; | ||
@@ -52,2 +53,19 @@ exports.isValidProtocol = isValidProtocol; | ||
/** | ||
* Determines whether the given string looks like an email. | ||
* | ||
* @param {string} email The string to scrutinise. | ||
* | ||
* @example | ||
* ```js | ||
* const isEmail = isEmail( 'hello@wordpress.org' ); // true | ||
* ``` | ||
* | ||
* @return {boolean} Whether or not it looks like an email. | ||
*/ | ||
function isEmail(email) { | ||
return EMAIL_REGEXP.test(email); | ||
} | ||
/** | ||
* Returns the protocol part of the URL. | ||
@@ -54,0 +72,0 @@ * |
{ | ||
"name": "@wordpress/url", | ||
"version": "2.5.0", | ||
"version": "2.6.0", | ||
"description": "WordPress URL utilities.", | ||
@@ -24,3 +24,3 @@ "author": "The WordPress Contributors", | ||
"dependencies": { | ||
"@babel/runtime": "^7.3.1", | ||
"@babel/runtime": "^7.4.4", | ||
"qs": "^6.5.2" | ||
@@ -31,3 +31,3 @@ }, | ||
}, | ||
"gitHead": "1e024a20a20369af7bc9720a676fdd3837a3a105" | ||
"gitHead": "87f92f8f58a14a58b44beff0919734c546b3b975" | ||
} |
288
README.md
@@ -19,6 +19,4 @@ # URL | ||
### addQueryArgs | ||
<a name="addQueryArgs" href="#addQueryArgs">#</a> **addQueryArgs** | ||
[src/index.js#L242-L264](src/index.js#L242-L264) | ||
Appends arguments as querystring to the provided URL. If the URL already | ||
@@ -28,3 +26,3 @@ includes query arguments, the arguments are merged with (and take precedent | ||
**Usage** | ||
_Usage_ | ||
@@ -35,18 +33,16 @@ ```js | ||
**Parameters** | ||
_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. | ||
- _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. | ||
**Returns** | ||
_Returns_ | ||
`string`: URL with arguments applied. | ||
- `string`: URL with arguments applied. | ||
### filterURLForDisplay | ||
<a name="filterURLForDisplay" href="#filterURLForDisplay">#</a> **filterURLForDisplay** | ||
[src/index.js#L379-L389](src/index.js#L379-L389) | ||
Returns a URL for display. | ||
**Usage** | ||
_Usage_ | ||
@@ -57,17 +53,15 @@ ```js | ||
**Parameters** | ||
_Parameters_ | ||
- **url** `string`: Original URL. | ||
- _url_ `string`: Original URL. | ||
**Returns** | ||
_Returns_ | ||
`string`: Displayed URL. | ||
- `string`: Displayed URL. | ||
### getAuthority | ||
<a name="getAuthority" href="#getAuthority">#</a> **getAuthority** | ||
[src/index.js#L79-L84](src/index.js#L79-L84) | ||
Returns the authority part of the URL. | ||
**Usage** | ||
_Usage_ | ||
@@ -79,17 +73,15 @@ ```js | ||
**Parameters** | ||
_Parameters_ | ||
- **url** `string`: The full URL. | ||
- _url_ `string`: The full URL. | ||
**Returns** | ||
_Returns_ | ||
`?string`: The authority part of the URL. | ||
- `?string`: The authority part of the URL. | ||
### getFragment | ||
<a name="getFragment" href="#getFragment">#</a> **getFragment** | ||
[src/index.js#L199-L204](src/index.js#L199-L204) | ||
Returns the fragment part of the URL. | ||
**Usage** | ||
_Usage_ | ||
@@ -101,17 +93,15 @@ ```js | ||
**Parameters** | ||
_Parameters_ | ||
- **url** `string`: The full URL | ||
- _url_ `string`: The full URL | ||
**Returns** | ||
_Returns_ | ||
`?string`: The fragment part of the URL. | ||
- `?string`: The fragment part of the URL. | ||
### getPath | ||
<a name="getPath" href="#getPath">#</a> **getPath** | ||
[src/index.js#L119-L124](src/index.js#L119-L124) | ||
Returns the path part of the URL. | ||
**Usage** | ||
_Usage_ | ||
@@ -123,17 +113,15 @@ ```js | ||
**Parameters** | ||
_Parameters_ | ||
- **url** `string`: The full URL. | ||
- _url_ `string`: The full URL. | ||
**Returns** | ||
_Returns_ | ||
`?string`: The path part of the URL. | ||
- `?string`: The path part of the URL. | ||
### getProtocol | ||
<a name="getProtocol" href="#getProtocol">#</a> **getProtocol** | ||
[src/index.js#L39-L44](src/index.js#L39-L44) | ||
Returns the protocol part of the URL. | ||
**Usage** | ||
_Usage_ | ||
@@ -145,17 +133,15 @@ ```js | ||
**Parameters** | ||
_Parameters_ | ||
- **url** `string`: The full URL. | ||
- _url_ `string`: The full URL. | ||
**Returns** | ||
_Returns_ | ||
`?string`: The protocol part of the URL. | ||
- `?string`: The protocol part of the URL. | ||
### getQueryArg | ||
<a name="getQueryArg" href="#getQueryArg">#</a> **getQueryArg** | ||
[src/index.js#L279-L284](src/index.js#L279-L284) | ||
Returns a single query argument of the url | ||
**Usage** | ||
_Usage_ | ||
@@ -166,18 +152,16 @@ ```js | ||
**Parameters** | ||
_Parameters_ | ||
- **url** `string`: URL | ||
- **arg** `string`: Query arg name | ||
- _url_ `string`: URL | ||
- _arg_ `string`: Query arg name | ||
**Returns** | ||
_Returns_ | ||
`(Array|string)`: Query arg value. | ||
- `(Array|string)`: Query arg value. | ||
### getQueryString | ||
<a name="getQueryString" href="#getQueryString">#</a> **getQueryString** | ||
[src/index.js#L159-L164](src/index.js#L159-L164) | ||
Returns the query string part of the URL. | ||
**Usage** | ||
_Usage_ | ||
@@ -189,17 +173,15 @@ ```js | ||
**Parameters** | ||
_Parameters_ | ||
- **url** `string`: The full URL. | ||
- _url_ `string`: The full URL. | ||
**Returns** | ||
_Returns_ | ||
`?string`: The query string part of the URL. | ||
- `?string`: The query string part of the URL. | ||
### hasQueryArg | ||
<a name="hasQueryArg" href="#hasQueryArg">#</a> **hasQueryArg** | ||
[src/index.js#L299-L301](src/index.js#L299-L301) | ||
Determines whether the URL contains a given query arg. | ||
**Usage** | ||
_Usage_ | ||
@@ -210,18 +192,34 @@ ```js | ||
**Parameters** | ||
_Parameters_ | ||
- **url** `string`: URL | ||
- **arg** `string`: Query arg name | ||
- _url_ `string`: URL | ||
- _arg_ `string`: Query arg name | ||
**Returns** | ||
_Returns_ | ||
`boolean`: Whether or not the URL contains the query arg. | ||
- `boolean`: Whether or not the URL contains the query arg. | ||
### isURL | ||
<a name="isEmail" href="#isEmail">#</a> **isEmail** | ||
[src/index.js#L22-L24](src/index.js#L22-L24) | ||
Determines whether the given string looks like an email. | ||
_Usage_ | ||
```js | ||
const isEmail = isEmail( 'hello@wordpress.org' ); // true | ||
``` | ||
_Parameters_ | ||
- _email_ `string`: The string to scrutinise. | ||
_Returns_ | ||
- `boolean`: Whether or not it looks like an email. | ||
<a name="isURL" href="#isURL">#</a> **isURL** | ||
Determines whether the given string looks like a URL. | ||
**Usage** | ||
_Usage_ | ||
@@ -232,17 +230,15 @@ ```js | ||
**Parameters** | ||
_Parameters_ | ||
- **url** `string`: The string to scrutinise. | ||
- _url_ `string`: The string to scrutinise. | ||
**Returns** | ||
_Returns_ | ||
`boolean`: Whether or not it looks like a URL. | ||
- `boolean`: Whether or not it looks like a URL. | ||
### isValidAuthority | ||
<a name="isValidAuthority" href="#isValidAuthority">#</a> **isValidAuthority** | ||
[src/index.js#L99-L104](src/index.js#L99-L104) | ||
Checks for invalid characters within the provided authority. | ||
**Usage** | ||
_Usage_ | ||
@@ -254,17 +250,15 @@ ```js | ||
**Parameters** | ||
_Parameters_ | ||
- **authority** `string`: A string containing the URL authority. | ||
- _authority_ `string`: A string containing the URL authority. | ||
**Returns** | ||
_Returns_ | ||
`boolean`: True if the argument contains a valid authority. | ||
- `boolean`: True if the argument contains a valid authority. | ||
### isValidFragment | ||
<a name="isValidFragment" href="#isValidFragment">#</a> **isValidFragment** | ||
[src/index.js#L219-L224](src/index.js#L219-L224) | ||
Checks for invalid characters within the provided fragment. | ||
**Usage** | ||
_Usage_ | ||
@@ -276,17 +270,15 @@ ```js | ||
**Parameters** | ||
_Parameters_ | ||
- **fragment** `string`: The url fragment. | ||
- _fragment_ `string`: The url fragment. | ||
**Returns** | ||
_Returns_ | ||
`boolean`: True if the argument contains a valid fragment. | ||
- `boolean`: True if the argument contains a valid fragment. | ||
### isValidPath | ||
<a name="isValidPath" href="#isValidPath">#</a> **isValidPath** | ||
[src/index.js#L139-L144](src/index.js#L139-L144) | ||
Checks for invalid characters within the provided path. | ||
**Usage** | ||
_Usage_ | ||
@@ -298,17 +290,15 @@ ```js | ||
**Parameters** | ||
_Parameters_ | ||
- **path** `string`: The URL path. | ||
- _path_ `string`: The URL path. | ||
**Returns** | ||
_Returns_ | ||
`boolean`: True if the argument contains a valid path | ||
- `boolean`: True if the argument contains a valid path | ||
### isValidProtocol | ||
<a name="isValidProtocol" href="#isValidProtocol">#</a> **isValidProtocol** | ||
[src/index.js#L59-L64](src/index.js#L59-L64) | ||
Tests if a url protocol is valid. | ||
**Usage** | ||
_Usage_ | ||
@@ -320,17 +310,15 @@ ```js | ||
**Parameters** | ||
_Parameters_ | ||
- **protocol** `string`: The url protocol. | ||
- _protocol_ `string`: The url protocol. | ||
**Returns** | ||
_Returns_ | ||
`boolean`: True if the argument is a valid protocol (e.g. http\:, tel:). | ||
- `boolean`: True if the argument is a valid protocol (e.g. http\:, tel:). | ||
### isValidQueryString | ||
<a name="isValidQueryString" href="#isValidQueryString">#</a> **isValidQueryString** | ||
[src/index.js#L179-L184](src/index.js#L179-L184) | ||
Checks for invalid characters within the provided query string. | ||
**Usage** | ||
_Usage_ | ||
@@ -342,17 +330,15 @@ ```js | ||
**Parameters** | ||
_Parameters_ | ||
- **queryString** `string`: The query string. | ||
- _queryString_ `string`: The query string. | ||
**Returns** | ||
_Returns_ | ||
`boolean`: True if the argument contains a valid query string. | ||
- `boolean`: True if the argument contains a valid query string. | ||
### prependHTTP | ||
<a name="prependHTTP" href="#prependHTTP">#</a> **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** | ||
_Usage_ | ||
@@ -363,17 +349,15 @@ ```js | ||
**Parameters** | ||
_Parameters_ | ||
- **url** `string`: The URL to test | ||
- _url_ `string`: The URL to test | ||
**Returns** | ||
_Returns_ | ||
`string`: The updated URL | ||
- `string`: The updated URL | ||
### removeQueryArgs | ||
<a name="removeQueryArgs" href="#removeQueryArgs">#</a> **removeQueryArgs** | ||
[src/index.js#L316-L324](src/index.js#L316-L324) | ||
Removes arguments from the query string of the url | ||
**Usage** | ||
_Usage_ | ||
@@ -384,19 +368,17 @@ ```js | ||
**Parameters** | ||
_Parameters_ | ||
- **url** `string`: URL | ||
- **args** `...string`: Query Args | ||
- _url_ `string`: URL | ||
- _args_ `...string`: Query Args | ||
**Returns** | ||
_Returns_ | ||
`string`: Updated URL | ||
- `string`: Updated URL | ||
### safeDecodeURI | ||
<a name="safeDecodeURI" href="#safeDecodeURI">#</a> **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** | ||
_Usage_ | ||
@@ -407,24 +389,22 @@ ```js | ||
**Parameters** | ||
_Parameters_ | ||
- **uri** `string`: URI to decode. | ||
- _uri_ `string`: URI to decode. | ||
**Returns** | ||
_Returns_ | ||
`string`: Decoded URI if possible. | ||
- `string`: Decoded URI if possible. | ||
### safeDecodeURIComponent | ||
<a name="safeDecodeURIComponent" href="#safeDecodeURIComponent">#</a> **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** | ||
_Parameters_ | ||
- **uriComponent** `string`: URI component to decode. | ||
- _uriComponent_ `string`: URI component to decode. | ||
**Returns** | ||
_Returns_ | ||
`string`: Decoded URI component if possible. | ||
- `string`: Decoded URI component if possible. | ||
@@ -431,0 +411,0 @@ |
@@ -27,2 +27,18 @@ /** | ||
/** | ||
* Determines whether the given string looks like an email. | ||
* | ||
* @param {string} email The string to scrutinise. | ||
* | ||
* @example | ||
* ```js | ||
* const isEmail = isEmail( 'hello@wordpress.org' ); // true | ||
* ``` | ||
* | ||
* @return {boolean} Whether or not it looks like an email. | ||
*/ | ||
export function isEmail( email ) { | ||
return EMAIL_REGEXP.test( email ); | ||
} | ||
/** | ||
* Returns the protocol part of the URL. | ||
@@ -29,0 +45,0 @@ * |
@@ -11,2 +11,3 @@ /** | ||
isURL, | ||
isEmail, | ||
getProtocol, | ||
@@ -57,2 +58,34 @@ isValidProtocol, | ||
describe( 'isEmail', () => { | ||
it( 'returns true when given things that look like an email', () => { | ||
const emails = [ | ||
'simple@wordpress.org', | ||
'very.common@wordpress.org', | ||
'disposable.style.email.with+symbol@wordpress.org', | ||
'other.email-with-hyphen@wordpress.org', | ||
'fully-qualified-domain@wordpress.org', | ||
'user.name+tag+sorting@wordpress.org', | ||
'x@wordpress.org', | ||
'wordpress-indeed@strange-wordpress.org', | ||
'wordpress@s.wordpress', | ||
]; | ||
expect( every( emails, isEmail ) ).toBe( true ); | ||
} ); | ||
it( 'returns false when given things that don\'t look like an email', () => { | ||
const emails = [ | ||
'Abc.wordpress.org', | ||
'A@b@c@wordpress.org', | ||
'a"b(c)d,e:f;g<h>i[j\k]l@wordpress.org', | ||
'just"not"right@wordpress.org', | ||
'this is"not\allowed@wordpress.org', | ||
'this\ still\"not\\allowed@wordpress.org', | ||
'1234567890123456789012345678901234567890123456789012345678901234+x@wordpress.org', | ||
]; | ||
expect( every( emails, isEmail ) ).toBe( false ); | ||
} ); | ||
} ); | ||
describe( 'getProtocol', () => { | ||
@@ -59,0 +92,0 @@ it( 'returns the protocol part of a URL', () => { |
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
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
118505
1648
0
395
Updated@babel/runtime@^7.4.4