Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
url-toolkit
Advanced tools
Readme
Lightweight library to build an absolute URL from a base URL and a relative URL, written from the spec (RFC 1808). Initially part of HLS.JS.
URL()
The JS URL() function also lets you calculate a new URL from a base and relative one.
That uses the URL Living Standard which is slightly different to RFC 1808 that this library implements.
One of the key differences is that the URL Living Standard has the concept of a 'special url' and 'special scheme'. For these special URL's, such as a URL with the http
scheme, they normalise them in a way that results in http:///example.com/something
becoming http://example.com/something
. This library does not do that and parseURL()
would give you //
as the netLoc
and /example.com
as the path.
buildAbsoluteURL(baseURL, relativeURL, opts={})
Build an absolute URL from a relative and base one.
URLToolkit.buildAbsoluteURL('http://a.com/b/cd', 'e/f/../g'); // => http://a.com/b/e/g
If you want to ensure that the URL is treated as a relative one you should prefix it with ./
.
URLToolkit.buildAbsoluteURL('http://a.com/b/cd', 'a:b'); // => a:b
URLToolkit.buildAbsoluteURL('http://a.com/b/cd', './a:b'); // => http://a.com/b/a:b
By default the paths will not be normalized unless necessary, according to the spec. However you can ensure paths are always normalized by setting the opts.alwaysNormalize
option to true
.
URLToolkit.buildAbsoluteURL('http://a.com/b/cd', '/e/f/../g'); // => http://a.com/e/f/../g
URLToolkit.buildAbsoluteURL('http://a.com/b/cd', '/e/f/../g', {
alwaysNormalize: true,
}); // => http://a.com/e/g
normalizePath(url)
Normalizes a path.
URLToolkit.normalizePath('a/b/../c'); // => a/c
parseURL(url)
Parse a URL into its separate components.
URLToolkit.parseURL('http://a/b/c/d;p?q#f'); // =>
/* {
scheme: 'http:',
netLoc: '//a',
path: '/b/c/d',
params: ';p',
query: '?q',
fragment: '#f'
} */
buildURLFromParts(parts)
Puts all the parts from parseURL()
back together into a string.
var URLToolkit = require('url-toolkit');
var url = URLToolkit.buildAbsoluteURL(
'https://a.com/b/cd/e.m3u8?test=1#something',
'../z.ts?abc=1#test'
);
console.log(url); // 'https://a.com/b/z.ts?abc=1#test'
This can also be used in the browser thanks to jsDelivr:
<head>
<script
type="text/javascript"
src="https://cdn.jsdelivr.net/npm/url-toolkit@2"
></script>
<script type="text/javascript">
var url = URLToolkit.buildAbsoluteURL(
'https://a.com/b/cd/e.m3u8?test=1#something',
'../z.ts?abc=1#test'
);
console.log(url); // 'https://a.com/b/z.ts?abc=1#test'
</script>
</head>
FAQs
Build an absolute URL from a base URL and a relative URL (RFC 1808). No dependencies!
The npm package url-toolkit receives a total of 355,473 weekly downloads. As such, url-toolkit popularity was classified as popular.
We found that url-toolkit 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
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.