getFilenameFromUri.js 918 B

1234567891011121314151617181920212223242526272829303132
  1. import Uri from "../ThirdParty/Uri.js";
  2. import defined from "./defined.js";
  3. import DeveloperError from "./DeveloperError.js";
  4. /**
  5. * Given a URI, returns the last segment of the URI, removing any path or query information.
  6. * @function getFilenameFromUri
  7. *
  8. * @param {String} uri The Uri.
  9. * @returns {String} The last segment of the Uri.
  10. *
  11. * @example
  12. * //fileName will be"simple.czml";
  13. * const fileName = Cesium.getFilenameFromUri('/Gallery/simple.czml?value=true&example=false');
  14. */
  15. function getFilenameFromUri(uri) {
  16. //>>includeStart('debug', pragmas.debug);
  17. if (!defined(uri)) {
  18. throw new DeveloperError("uri is required.");
  19. }
  20. //>>includeEnd('debug');
  21. const uriObject = new Uri(uri);
  22. uriObject.normalize();
  23. let path = uriObject.path();
  24. const index = path.lastIndexOf("/");
  25. if (index !== -1) {
  26. path = path.substr(index + 1);
  27. }
  28. return path;
  29. }
  30. export default getFilenameFromUri;