A really lightweight (≈81 lines of TypeScript, ≈500b gzipped js, with es5 support) url parser, which works both in node and on the web and without any dependencies
npm install --save pure-url
or yarn add pure-url
Parse the query using const url = PureUrl.parse('http://www.example.com')
, to get a new URL object. All properties are mutable and can be used to update the url
-
schema: the schema of the url, for instance
http
forhttp://example.com
orexample
forexample://demo
-
hostname: the hostname of the url, for instance
www.example.com
forhttp://www.example.com
-
path: the path of the url as a string, for instance
/foo/bar
forhttp://www.example.com/foo/bar
-
pathSegments: the path of the url as an array, for instance
['foo','bar']
forhttp://www.example.com/foo/bar
-
queryString: the query of the url as a string, for instance
?hello=world
forhttp://www.example.com?hello=world
-
query: the query of the url as an object, for instance
{ hello: 'world' }
forhttp://www.example.com?hello=world
- toString: takes the url, including all changes, and creates a url string