utils.js 519 B

1234567891011121314151617
  1. const postfixRE = /[?#].*$/;
  2. export function cleanUrl(url) {
  3. return url.replace(postfixRE, '');
  4. }
  5. export function extractQueryWithoutFragment(url) {
  6. const questionMarkIndex = url.indexOf('?');
  7. if (questionMarkIndex === -1) {
  8. return '';
  9. }
  10. const fragmentIndex = url.indexOf('#', questionMarkIndex); // Search for # after ?
  11. if (fragmentIndex === -1) {
  12. return url.substring(questionMarkIndex);
  13. }
  14. else {
  15. return url.substring(questionMarkIndex, fragmentIndex);
  16. }
  17. }