Skip to content

Instantly share code, notes, and snippets.

@inodaf
Last active September 25, 2016 01:36
Show Gist options
  • Save inodaf/d4d418736a0b7d9437c1ac6d7a769880 to your computer and use it in GitHub Desktop.
Save inodaf/d4d418736a0b7d9437c1ac6d7a769880 to your computer and use it in GitHub Desktop.
Check if a string is an URI.
;(function(obj) {
'use strict';
/*
* @name: isURL
* @description: Checks if a String is an URI
*
* @param String : The string to be checked
*/
function isURI(string) {
// Set a variable name that will be
// defined when the operation return true
let result;
// Set an array of URI References
let uriRefs = [
'https://',
'http://',
'ftp://',
'data:'
];
// Maps the `uriRefs` array and call a function
// passing as an argument it's values.
// Then do a verification that checks if
// the value of the `string` argument includes an item of the
// `uriRefs` array. If is true, define the `result` to be true;
uriRefs.map(ref => {
if (string.includes(ref)) result = true;
});
// Return the `result` with a `true` or `false` value
return result;
}
obj.isURI = isURI;
}(window));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment