You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
39 lines
984 B
JavaScript
39 lines
984 B
JavaScript
import Uri from "../ThirdParty/Uri.js";
|
|
import defined from "./defined.js";
|
|
import DeveloperError from "./DeveloperError.js";
|
|
|
|
/**
|
|
* Given a URI, returns the extension of the URI.
|
|
* @function getExtensionFromUri
|
|
*
|
|
* @param {String} uri The Uri.
|
|
* @returns {String} The extension of the Uri.
|
|
*
|
|
* @example
|
|
* //extension will be "czml";
|
|
* var extension = Cesium.getExtensionFromUri('/Gallery/simple.czml?value=true&example=false');
|
|
*/
|
|
function getExtensionFromUri(uri) {
|
|
//>>includeStart('debug', pragmas.debug);
|
|
if (!defined(uri)) {
|
|
throw new DeveloperError("uri is required.");
|
|
}
|
|
//>>includeEnd('debug');
|
|
|
|
var uriObject = new Uri(uri);
|
|
uriObject.normalize();
|
|
var path = uriObject.path;
|
|
var index = path.lastIndexOf("/");
|
|
if (index !== -1) {
|
|
path = path.substr(index + 1);
|
|
}
|
|
index = path.lastIndexOf(".");
|
|
if (index === -1) {
|
|
path = "";
|
|
} else {
|
|
path = path.substr(index + 1);
|
|
}
|
|
return path;
|
|
}
|
|
export default getExtensionFromUri;
|