url.ts 566 B

12345678910111213141516
  1. /**
  2. * Copyright (c) 2018 mol* contributors, licensed under MIT, See LICENSE file for more info.
  3. *
  4. * @author Alexander Rose <alexander.rose@weirdbyte.de>
  5. */
  6. export function urlQueryParameter (id: string) {
  7. if (typeof window === 'undefined') return undefined;
  8. const a = new RegExp(`${id}=([^&#=]*)`);
  9. const m = a.exec(window.location.search);
  10. return m ? decodeURIComponent(m[1]) : undefined;
  11. }
  12. export function urlCombine(base: string, query: string) {
  13. return `${base}${base[base.length - 1] === '/' || query[0] === '/' ? '' : '/'}${query}`;
  14. }