Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR TYPESCRIPT

How to join all url segments to make a url in javascipt 30seconds of code

const URLJoin = (...args) =>
  args
    .join('/')
    .replace(/[/]+/g, '/')
    .replace(/^(.+)://, '$1://')
    .replace(/^file:/, 'file:/')
    .replace(//(?|&|#[^!])/g, '$1')
    .replace(/?/g, '&')
    .replace('&', '?');
Source by www.30secondsofcode.org #
 
PREVIOUS NEXT
Tagged: #How #join #url #segments #url #javascipt #code
ADD COMMENT
Topic
Name
4+7 =