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

cspell-io

Package Overview
Dependencies
Maintainers
1
Versions
278
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cspell-io - npm Package Compare versions

Comparing version 8.8.4 to 8.9.0-alpha.0

33

dist/esm/node/file/url.d.ts

@@ -0,35 +1,5 @@

export { basenameOfUrlPathname, isFileURL, isURL, isUrlLike, toFileURL, toURL, urlBasename, urlParent as urlDirname, } from '@cspell/url';
export declare function isZipped(filename: string | URL): boolean;
export declare function isUrlLike(filename: string | URL): boolean;
export declare function isSupportedURL(url: URL): boolean;
export declare function isFileURL(url: URL): boolean;
/**
* Try to make a file URL.
* - if filenameOrUrl is already a URL, it is returned as is.
* -
* @param filenameOrUrl
* @param relativeTo - optional URL, if given, filenameOrUrl will be parsed as relative.
* @returns a URL
*/
export declare function toFileURL(filenameOrUrl: string | URL, relativeTo?: string | URL): URL;
/**
* Try to make a URL.
* @param filenameOrUrl
* @param relativeTo - optional URL, if given, filenameOrUrl will be parsed as relative.
* @returns a URL
*/
export declare function toURL(filenameOrUrl: string | URL, relativeTo?: string | URL): URL;
/**
* Try to determine the base name of a URL.
* @param url
* @returns the base name of a URL, including the trailing `/` if present.
*/
export declare function urlBasename(url: string | URL): string;
/**
* Try to determine the parent directory URL of the uri.
* If it is not a hierarchical URL, then it will return the URL.
* @param url - url to extract the dirname from.
* @returns a URL
*/
export declare function urlDirname(url: string | URL): URL;
/**
* return the basename of a path, removing the trailing `/` if present.

@@ -40,3 +10,2 @@ * @param path

export declare function basename(path: string): string;
export declare function normalizePathForUrl(filePath: string): string;
//# sourceMappingURL=url.d.ts.map

@@ -1,6 +0,4 @@

import path from 'node:path';
import { pathToFileURL } from 'node:url';
import { basenameOfUrlPathname } from '@cspell/url';
export { basenameOfUrlPathname, isFileURL, isURL, isUrlLike, toFileURL, toURL, urlBasename, urlParent as urlDirname, } from '@cspell/url';
const isZippedRegExp = /\.gz($|[?#])/i;
const isURLRegExp = /^([\w-]{2,64}:\/|data:)/i;
const isWindowsPath = /^[a-z]:[\\/]/i;
const supportedProtocols = { 'file:': true, 'http:': true, 'https:': true };

@@ -11,79 +9,6 @@ export function isZipped(filename) {

}
export function isUrlLike(filename) {
return filename instanceof URL || isURLRegExp.test(filename);
}
export function isSupportedURL(url) {
return !!supportedProtocols[url.protocol];
}
export function isFileURL(url) {
return url.protocol === 'file:';
}
/**
* Try to make a file URL.
* - if filenameOrUrl is already a URL, it is returned as is.
* -
* @param filenameOrUrl
* @param relativeTo - optional URL, if given, filenameOrUrl will be parsed as relative.
* @returns a URL
*/
export function toFileURL(filenameOrUrl, relativeTo) {
if (typeof filenameOrUrl !== 'string')
return filenameOrUrl;
return isUrlLike(filenameOrUrl)
? new URL(filenameOrUrl)
: relativeTo && isUrlLike(relativeTo)
? new URL(normalizePathForUrl(filenameOrUrl), relativeTo)
: relativeTo
? pathToFileURL(path.resolve(relativeTo.toString(), filenameOrUrl))
: pathToFileURL(filenameOrUrl);
}
/**
* Try to make a URL.
* @param filenameOrUrl
* @param relativeTo - optional URL, if given, filenameOrUrl will be parsed as relative.
* @returns a URL
*/
export function toURL(filenameOrUrl, relativeTo) {
return filenameOrUrl instanceof URL ? filenameOrUrl : new URL(filenameOrUrl, relativeTo);
}
const regMatchFilename = /filename=([^;,]*)/;
/**
* Try to determine the base name of a URL.
* @param url
* @returns the base name of a URL, including the trailing `/` if present.
*/
export function urlBasename(url) {
function guessDataUrlName(header) {
const filenameMatch = header.match(regMatchFilename);
if (filenameMatch)
return filenameMatch[1];
const mime = header.split(';', 1)[0];
return mime.replaceAll(/\W/g, '.');
}
url = toURL(url);
if (url.protocol === 'data:') {
return guessDataUrlName(url.pathname.split(',', 1)[0]);
}
const suffix = url.pathname.endsWith('/') ? '/' : '';
return basename(url.pathname) + suffix;
}
/**
* Try to determine the parent directory URL of the uri.
* If it is not a hierarchical URL, then it will return the URL.
* @param url - url to extract the dirname from.
* @returns a URL
*/
export function urlDirname(url) {
url = toURL(url);
if (url.protocol === 'data:') {
return url;
}
try {
return new URL(url.pathname.endsWith('/') ? '..' : '.', url);
}
catch {
return url;
}
}
/**
* return the basename of a path, removing the trailing `/` if present.

@@ -94,15 +19,5 @@ * @param path

export function basename(path) {
path = path.endsWith('/') ? path.slice(0, -1) : path;
const idx = path.lastIndexOf('/');
return idx >= 0 ? path.slice(idx + 1) : path;
const base = basenameOfUrlPathname(path);
return base.endsWith('/') && !base.endsWith(':/') ? base.slice(0, -1) : base;
}
export function normalizePathForUrl(filePath) {
const pathname = filePath.replaceAll('\\', '/');
const raw = pathname.replace(isWindowsPath, '/$&');
return raw
.split('/')
.map(encodeURIComponent)
.join('/')
.replace(/^\/([a-z])%3A/i, '/$1:');
}
//# sourceMappingURL=url.js.map

7

package.json
{
"name": "cspell-io",
"version": "8.8.4",
"version": "8.9.0-alpha.0",
"description": "A library of useful I/O functions used across various cspell tools.",

@@ -55,5 +55,6 @@ "type": "module",

"dependencies": {
"@cspell/cspell-service-bus": "8.8.4"
"@cspell/cspell-service-bus": "8.9.0-alpha.0",
"@cspell/url": "8.9.0-alpha.0"
},
"gitHead": "e1df92825ed0dacedb1830eeb6d918f01690c69a"
"gitHead": "700ed688420d2f3e784c05e2709ad33953aadadc"
}
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