@jupyterlab/coreutils
Advanced tools
Comparing version 2.0.3 to 2.1.0
@@ -43,3 +43,3 @@ /** | ||
/** | ||
* Get the base url for a Jupyter application. | ||
* Get the base url for a Jupyter application, or the base url of the page. | ||
*/ | ||
@@ -54,3 +54,3 @@ function getBaseUrl(): string; | ||
/** | ||
* Get the base websocket url for a Jupyter application. | ||
* Get the base websocket url for a Jupyter application, or an empty string. | ||
*/ | ||
@@ -57,0 +57,0 @@ function getWsUrl(baseUrl?: string): string; |
@@ -10,2 +10,3 @@ "use strict"; | ||
const minimist_1 = __importDefault(require("minimist")); | ||
const path_1 = require("./path"); | ||
const url_1 = require("./url"); | ||
@@ -95,13 +96,6 @@ /** | ||
/** | ||
* Get the base url for a Jupyter application. | ||
* Get the base url for a Jupyter application, or the base url of the page. | ||
*/ | ||
function getBaseUrl() { | ||
let baseUrl = getOption('baseUrl'); | ||
if (!baseUrl || baseUrl === '/') { | ||
baseUrl = | ||
typeof location === 'undefined' | ||
? 'http://localhost:8888/' | ||
: location.origin + '/'; | ||
} | ||
return url_1.URLExt.parse(baseUrl).toString(); | ||
return url_1.URLExt.normalize(getOption('baseUrl') || '/'); | ||
} | ||
@@ -116,16 +110,13 @@ PageConfig.getBaseUrl = getBaseUrl; | ||
const base = getBaseUrl(); | ||
const page = getOption('pageUrl'); | ||
const tree = getOption('treeUrl'); | ||
const defaultWorkspace = getOption('defaultWorkspace'); | ||
const workspaces = getOption('workspacesUrl'); | ||
const workspace = getOption('workspace'); | ||
const includeWorkspace = !!options.workspace; | ||
if (includeWorkspace && workspace) { | ||
return url_1.URLExt.join(base, workspaces, workspace, 'tree'); | ||
} | ||
else { | ||
return url_1.URLExt.join(base, page, 'tree'); | ||
} | ||
return !!options.workspace && workspace && workspace !== defaultWorkspace | ||
? url_1.URLExt.join(base, workspaces, path_1.PathExt.basename(workspace), 'tree') | ||
: url_1.URLExt.join(base, tree); | ||
} | ||
PageConfig.getTreeUrl = getTreeUrl; | ||
/** | ||
* Get the base websocket url for a Jupyter application. | ||
* Get the base websocket url for a Jupyter application, or an empty string. | ||
*/ | ||
@@ -135,14 +126,9 @@ function getWsUrl(baseUrl) { | ||
if (!wsUrl) { | ||
baseUrl = baseUrl || getBaseUrl(); | ||
baseUrl = baseUrl ? url_1.URLExt.normalize(baseUrl) : getBaseUrl(); | ||
if (baseUrl.indexOf('http') !== 0) { | ||
if (typeof location !== 'undefined') { | ||
baseUrl = url_1.URLExt.join(location.origin, baseUrl); | ||
} | ||
else { | ||
baseUrl = url_1.URLExt.join('http://localhost:8888/', baseUrl); | ||
} | ||
return ''; | ||
} | ||
wsUrl = 'ws' + baseUrl.slice(4); | ||
} | ||
return url_1.URLExt.parse(wsUrl).toString(); | ||
return url_1.URLExt.normalize(wsUrl); | ||
} | ||
@@ -149,0 +135,0 @@ PageConfig.getWsUrl = getWsUrl; |
@@ -15,2 +15,6 @@ import { JSONObject } from '@phosphor/coreutils'; | ||
/** | ||
* Normalize a url. | ||
*/ | ||
function normalize(url: string): string; | ||
/** | ||
* Join a sequence of url components and normalizes as in node `path.join`. | ||
@@ -17,0 +21,0 @@ * |
@@ -31,2 +31,9 @@ "use strict"; | ||
/** | ||
* Normalize a url. | ||
*/ | ||
function normalize(url) { | ||
return url && parse(url).toString(); | ||
} | ||
URLExt.normalize = normalize; | ||
/** | ||
* Join a sequence of url components and normalizes as in node `path.join`. | ||
@@ -39,15 +46,26 @@ * | ||
function join(...parts) { | ||
// Adapted from url-join. | ||
// Copyright (c) 2016 José F. Romaniello, MIT License. | ||
// https://github.com/jfromaniello/url-join/blob/v1.1.0/lib/url-join.js | ||
let str = [].slice.call(parts, 0).join('/'); | ||
// make sure protocol is followed by two slashes | ||
str = str.replace(/:\//g, '://'); | ||
// remove consecutive slashes | ||
str = str.replace(/([^:\s])\/+/g, '$1/'); | ||
// remove trailing slash before parameters or hash | ||
str = str.replace(/\/(\?|&|#[^!])/g, '$1'); | ||
// replace ? in parameters with & | ||
str = str.replace(/(\?.+)\?/g, '$1&'); | ||
return str; | ||
parts = parts || []; | ||
// Isolate the top element. | ||
const top = parts[0] || ''; | ||
// Check whether protocol shorthand is being used. | ||
const shorthand = top.indexOf('//') === 0; | ||
// Parse the top element into a header collection. | ||
const header = top.match(/(\w+)(:)(\/\/)?/); | ||
const protocol = header && header[1]; | ||
const colon = protocol && header[2]; | ||
const slashes = colon && header[3]; | ||
// Construct the URL prefix. | ||
const prefix = shorthand | ||
? '//' | ||
: [protocol, colon, slashes].filter(str => str).join(''); | ||
// Construct the URL body omitting the prefix of the top value. | ||
const body = [top.indexOf(prefix) === 0 ? top.replace(prefix, '') : top] | ||
// Filter out top value if empty. | ||
.filter(str => str) | ||
// Remove leading slashes in all subsequent URL body elements. | ||
.concat(parts.slice(1).map(str => str.replace(/^\//, ''))) | ||
.join('/') | ||
// Replace multiple slashes with one. | ||
.replace(/\/+/g, '/'); | ||
return prefix + body; | ||
} | ||
@@ -54,0 +72,0 @@ URLExt.join = join; |
{ | ||
"name": "@jupyterlab/coreutils", | ||
"version": "2.0.3", | ||
"version": "2.1.0", | ||
"description": "JupyterLab - Core Utilities", | ||
@@ -5,0 +5,0 @@ "homepage": "https://github.com/jupyterlab/jupyterlab", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
239273
3591