UNPKG

urlite

Version:

A very small, fast, dependency free url parser and formatter for nodejs and the web

12 lines (11 loc) 403 B
var pattern = require('./lib/pattern') var fragments = require('./lib/fragments') module.exports = function parse (url) { var parts = {} parts.href = url var matches = url.match(pattern) var l = fragments.length while (l--) { parts[fragments[l]] = matches[l + 1] } parts.path = parts.search ? (parts.pathname ? parts.pathname + parts.search : parts.search) : parts.pathname return parts }