Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

hlx-url-rewriter

Package Overview
Dependencies
Maintainers
1
Versions
25
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

hlx-url-rewriter - npm Package Compare versions

Comparing version 0.0.1 to 0.0.2

56

default.js

@@ -26,12 +26,56 @@ const {URL} = require('url');

function defaultFunc(url) {
function getUrlType(url) {
if (tryCatch(
() => {
url = new URL(url);
return true;
},
() => {
return false;
}
)) {
return 'absolute';
}
if (url.startsWith('//')) {
return 'scheme-relative';
}
if (url.startsWith('/')) {
return 'path-absolute';
}
return 'path-relative';
}
let baseHostName = '';
function defaultFunc(url, saveAsBaseUrl) {
if (saveAsBaseUrl) {
baseHostName = '';
}
// Convert absolute urls into relative paths
const obj = getUrlObj(url);
if (!obj) {
// url is already a relative path
return url;
let type = getUrlType(url);
if (type === 'scheme-relative') {
url = `http:${url}`;
type = 'absolute';
}
return `/${obj.hostname}${obj.pathname}${obj.search}${obj.hash}`;
if (type === 'absolute') {
const obj = getUrlObj(url);
if (saveAsBaseUrl) {
baseHostName = obj.hostname;
}
return `/${obj.hostname}${obj.pathname}${obj.search}${obj.hash}`;
}
if (type === 'path-absolute' && baseHostName) {
return `/${baseHostName}${url}`;
}
return url;
}
module.exports = defaultFunc;

3

package.json
{
"name": "hlx-url-rewriter",
"version": "0.0.1",
"version": "0.0.2",
"description": "A transform stream to modify URLs contained in HLS playlists",

@@ -38,2 +38,3 @@ "main": "index.js",

"capitalized-comments": 0,
"camelcase": 0,
"dot-notation": 0,

@@ -40,0 +41,0 @@ "indent": 0,

@@ -11,3 +11,3 @@ [![Build Status](https://travis-ci.org/hlxjs/hlx-url-rewriter.svg?branch=master)](https://travis-ci.org/hlxjs/hlx-url-rewriter)

## Features
* Being used with other [`hls-streams`](https://github.com/hls-streams) objects, it provides a functionality to filter every playlists and rewrite the urls in them based on the `rules`.
* Being used with other [`hlx`](https://github.com/hlxjs) objects, it provides a functionality to filter every playlists and rewrite the urls in them based on the `rules`.

@@ -14,0 +14,0 @@ ## Install

@@ -20,6 +20,7 @@ const stream = require('stream');

function rewrite(playlist, rewriteFunc) {
function rewriteUrl(item = {}) {
const {uri} = item;
if (uri) {
item.uri = rewriteFunc(uri);
function rewriteUrl(item = {}, isBase) {
const {uri, __hlx_url_rewriter_visited__: visited} = item;
if (uri && !visited) {
item.uri = rewriteFunc(uri, isBase);
item.__hlx_url_rewriter_visited__ = true;
}

@@ -34,3 +35,3 @@ }

}
rewriteUrl(playlist);
rewriteUrl(playlist, true);
if (playlist.isMasterPlaylist) {

@@ -37,0 +38,0 @@ const {variants, sessionDataList, sessionKeyList} = playlist;

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc