Convert API

toPath()

Converts a URL string to a path.

  • Accepts an argument as a string.
  • Returns a string with a path.
Example:
toPath('https://site.com/page?sort=asc&value=1#hash');
// '/page?sort=asc&value=1#hash'

toPath('https://site.com/page');
// '/page'

toPath('http://site.com/page');
// '/page'

toPath('//site.com/page');
// '/page'

toPath('/page');
// '/page'

toPath('/site.com/page');
// '/site.com/page'

toPath('site.com/page');
// '/site.com/page'