Security News
NVD Backlog Tops 20,000 CVEs Awaiting Analysis as NIST Prepares System Updates
NVD’s backlog surpasses 20,000 CVEs as analysis slows and NIST announces new system updates to address ongoing delays.
Convert a path to a file url: `unicorn.jpg` → `file:///Users/sindresorhus/unicorn.jpg`
The file-url npm package is a utility that converts file paths to file URLs. This can be particularly useful when working with file systems in Node.js and needing to generate URLs that can be used in web contexts.
Convert file path to file URL
This feature allows you to convert a given file path to a file URL. The resulting URL can be used in web contexts where a file URL is required.
const fileUrl = require('file-url');
const url = fileUrl('/path/to/file');
console.log(url); // Outputs: 'file:///path/to/file'
Convert file path to file URL with custom options
This feature allows you to convert a file path to a file URL with additional options. For example, the 'resolve' option can be used to resolve the file path to an absolute path before converting it to a URL.
const fileUrl = require('file-url');
const url = fileUrl('/path/to/file', { resolve: true });
console.log(url); // Outputs: 'file:///absolute/path/to/file'
The url package is a core Node.js module that provides utilities for URL resolution and parsing. While it is more general-purpose and not specifically focused on file URLs, it can be used to achieve similar results with more manual effort.
The file-uri-to-path package does the reverse of file-url by converting file URLs back to file paths. It can be used in conjunction with file-url for bidirectional conversions between file paths and URLs.
Convert a path to a file url:
unicorn.jpg
→file:///Users/sindresorhus/unicorn.jpg
$ npm install --save file-url
const fileUrl = require('file-url');
fileUrl('unicorn.jpg');
//=> 'file:///Users/sindresorhus/dev/file-url/unicorn.jpg'
fileUrl('/Users/pony/pics/unicorn.jpg');
//=> 'file:///Users/pony/pics/unicorn.jpg'
// passing {resolve: false} will make it not call path.resolve() on the path
fileUrl('unicorn.jpg', {resolve: false});
//=> 'file:///unicorn.jpg'
MIT © Sindre Sorhus
FAQs
Convert a file path to a file url: `unicorn.jpg` → `file:///Users/sindresorhus/unicorn.jpg`
The npm package file-url receives a total of 432,305 weekly downloads. As such, file-url popularity was classified as popular.
We found that file-url 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
NVD’s backlog surpasses 20,000 CVEs as analysis slows and NIST announces new system updates to address ongoing delays.
Security News
Research
A malicious npm package disguised as a WhatsApp client is exploiting authentication flows with a remote kill switch to exfiltrate data and destroy files.
Security News
PyPI now supports digital attestations, enhancing security and trust by allowing package maintainers to verify the authenticity of Python packages.