Security News
The Unpaid Backbone of Open Source: Solo Maintainers Face Increasing Security Demands
Solo open source maintainers face burnout and security challenges, with 60% unpaid and 60% considering quitting.
Performant utilities for URL resolution and parsing built on core url.
This module provides many tools for working with Objects parsed with url.parse()
. It also performs faster because it avoids the need to constantly reparse URL Strings during multiple operations.
URL components used in comparison operations.
component.NOTHING
component.PROTOCOL
or components.SCHEME
component.TLD
component.DOMAIN
component.SUB_DOMAIN
component.HOSTNAME
component.PORT
component.HOST
component.AUTH
component.DIRECTORY
component.FILENAME
component.PATHNAME
component.QUERY
or components.SEARCH
component.PATH
component.HASH
or components.FRAGMENT
HOST PATH
___|___ _______|______
/ \ / \
AUTH HOSTNAME PORT PATHNAME QUERY HASH
_______|_______ ______|______ | __________|_________ ____|____ |
/ \ / \ / \ / \ / \ / \
foo://username:password@www.example.com:123/hello/world/there.html?name=ferret#foo
\_/ \_/ \_____/ \_/ \_________/ \________/
| | | | | |
PROTOCOL SUB_DOMAIN | TLD DIRECTORY FILENAME
|
DOMAIN
Note: there are a few breaks in the linearity of these values:
AUTH
is prioritized after HOST
because matching authentication on a different domain is pointlessTLD
is prioritized before DOMAIN
because matching a domain on a different top-level domain is pointlessSUB_DOMAIN
is prioritized after DOMAIN
URL types used for discerning input.
type.UNKNOWN
type.ABSOLUTE
type.PROTOCOL_RELATIVE
type.ROOT_RELATIVE
type.DIRECTORY_RELATIVE
type.FILENAME_RELATIVE
type.QUERY_RELATIVE
type.EMPTY
type.HASH_RELATIVE
The following methods will accept URLs as Strings and/or Objects.
Converts a URL Object
to a formatted URL String
. Is merely an alias to core url.format()
.
Normalizes and minifies a URL with the following options:
clone
; when set to true
, the function will return a copy of url
instead of mutating the original.defaultPorts
; a map of default ports for various protocols. Default value: {ftp:21, gopher:70, http:80, https:443}
.directoryIndexes
; a list of filenames that are expected to be treated as directory indexes. Default value: ["index.html"]
.removeAuth
; when set to true
, it will remove authentication information. Default value: false
.removeDefaultPorts
; when set to true
, it will remove ports that match any found in defaultPorts
. Default value: true
.removeDirectoryIndexes
; when set to true
, it will remove filenames that match any found in directoryIndexes
. Default value: true
.removeEmptyQueries
; when set to true
, it will remove empty query data such as "?"
, "?var="
and "&="
. Default value: false
.removeRootTrailingSlash
; when set to true
, it will remove trailing slashes such as "http://domain.com/?var"
. Default value: true
.If url
is an Object, it will be mutated/modified.
Resolves dot segments ("../"
, "./"
) in a URL's path, removes port if it is default and removes empty queries ("path/?"
).
Options:
defaultPorts
; a map of default ports for various protocols. Default value: {ftp:21, gopher:70, http:80, https:443}
.slashesDenoteHost
; when set to true
, it will parse "//domain.com/"
as a URL instead of a path. Default value: false
.If url
is an Object, it will be mutated/modified.
Parses (or re-parses) a URL into an Object containing its URL components with the following options:
defaultPorts
; a map of default ports for various protocols. Default value: {ftp:21, gopher:70, http:80, https:443}
.directoryIndexes
; a list of filenames that are expected to be treated as directory indexes. Default value: ["index.html"]
.parseQueryString
; when set to true
, it will parse the query string into an object. Default value: false
.slashesDenoteHost
; when set to true
, it will parse "//domain.com/"
as a URL instead of a path. Default value: false
.If url
is an Object, it will be mutated/modified.
Returns a Number defining the relation between two URLs. That number corresponds to the value of a URL component in components
.
Because the value returned is a Number, more complex comparisons are possible:
var relation = urlobj.relation(url1, url2);
if (relation >= urlobj.components.HOST) {
console.log("same server!");
}
Resolves a URL with a base URL like a browser would for an anchor tag. If to
is an Object, it will be mutated/modified.
Options:
defaultPorts
; a map of default ports for various protocols. Default value: {ftp:21, gopher:70, http:80, https:443}
.ignoreWww
; when set to true
, it will treat "www.domain.com"
and "domain.com"
as the same host. Default value: false
.Compares two directory Arrays to see if their paths are the same. leadingSlash1
and leadingSlash2
denote that the corresponding path is absolute and not relative. Input should first be normalized.
Compares two query Objects to see if their data is the same. Order does not matter.
Joins all directories of a directory Array into a String. leadingSlash
denotes that the path is absolute and not relative.
Joins all keys of an Object into a query String.
When skipEmpties
is true
, empty query data such as "?var="
and "&="
will be excluded. Its default value is false
.
Resolves dot segments ("../"
, "./"
) in a directory Array and returns a new Array (within an Object). leadingSlash
denotes that the path is absolute and not relative. This method will attempt to resolve to a root. If none is found, the parent-most dot segment will remain.
Examples using Strings instead of Arrays:
"/dir1/dir2/../"
into "/dir1/"
"dir/../"
into ""
"/../dir/"
into "/dir/"
"../dir/"
untouched"../../dir/"
untouchedParses a path String into an Object containing a directory Array and a filename String.
Resolves a base directory Array to another directory Array and returns a new, normalized Array (within an Object). fromLeadingSlash
and toLeadingSlash
denote that the corresponding path is absolute and not relative.
FAQs
Performant utilities for URL resolution and parsing built on core url.
The npm package urlobj receives a total of 9,648 weekly downloads. As such, urlobj popularity was classified as popular.
We found that urlobj demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Solo open source maintainers face burnout and security challenges, with 60% unpaid and 60% considering quitting.
Security News
License exceptions modify the terms of open source licenses, impacting how software can be used, modified, and distributed. Developers should be aware of the legal implications of these exceptions.
Security News
A developer is accusing Tencent of violating the GPL by modifying a Python utility and changing its license to BSD, highlighting the importance of copyleft compliance.