Publish Vulpes Preview 15 sources for desktop, Android and Tundra
Share Gaia assets and adapters, keep private profiles and development documents local, and update both public READMEs.
This commit is contained in:
parent
93e3a48004
commit
b38dea0597
25901 changed files with 9982925 additions and 369 deletions
58
gaia/apps/calendar/js/utils/uri.js
Executable file
58
gaia/apps/calendar/js/utils/uri.js
Executable file
|
|
@ -0,0 +1,58 @@
|
|||
define(function(require, exports) {
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* Get the port of the url.
|
||||
* @param {string} url full url.
|
||||
* @return {?number} port number, null if none found.
|
||||
*/
|
||||
exports.getPort = function(url) {
|
||||
var parts = url.split(':');
|
||||
if (parts.length < 2) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// If we found a port and path, it's the last part
|
||||
var candidate = parts[parts.length - 1];
|
||||
parts = candidate.split('/');
|
||||
|
||||
// If we found a port, it's the first part
|
||||
candidate = parts[0];
|
||||
if (!isInteger(candidate)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return parseInt(candidate, 10);
|
||||
};
|
||||
|
||||
/**
|
||||
* Get the scheme of the url. Note that this only detects http and https.
|
||||
* @param {string} url full url.
|
||||
* @return {?string} uri scheme (ie http), null if none found.
|
||||
*/
|
||||
exports.getScheme = function(url) {
|
||||
var parts = url.split(':');
|
||||
if (parts.length < 2) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
// If we found a scheme, it's the first part
|
||||
var candidate = parts[0];
|
||||
if (candidate !== 'http' && candidate !== 'https') {
|
||||
return null;
|
||||
}
|
||||
|
||||
return candidate;
|
||||
};
|
||||
|
||||
/**
|
||||
* Decide whether or not this string represents an integer.
|
||||
* @param {string} str some string.
|
||||
* @param {boolean} whether or not str represents an integer.
|
||||
*/
|
||||
function isInteger(str) {
|
||||
return (/^\d+$/).test(str);
|
||||
}
|
||||
|
||||
});
|
||||
Loading…
Reference in a new issue