/
getExtensionFromUri.js
46 lines (43 loc) · 1.18 KB
/
getExtensionFromUri.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
define([
'../ThirdParty/Uri',
'./defined',
'./DeveloperError'
], function(
Uri,
defined,
DeveloperError) {
'use strict';
/**
* Given a URI, returns the extension of the URI.
* @exports 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;
}
return getExtensionFromUri;
});