uris.js 596 B

123456789101112131415161718192021
  1. exports.uriToZipEntryName = uriToZipEntryName;
  2. exports.replaceFragment = replaceFragment;
  3. function uriToZipEntryName(base, uri) {
  4. if (uri.charAt(0) === "/") {
  5. return uri.substr(1);
  6. } else {
  7. // In general, we should check first and second for trailing and leading slashes,
  8. // but in our specific case this seems to be sufficient
  9. return base + "/" + uri;
  10. }
  11. }
  12. function replaceFragment(uri, fragment) {
  13. var hashIndex = uri.indexOf("#");
  14. if (hashIndex !== -1) {
  15. uri = uri.substring(0, hashIndex);
  16. }
  17. return uri + "#" + fragment;
  18. }