Security News
Cloudflare Adds Security.txt Setup Wizard
Cloudflare has launched a setup wizard allowing users to easily create and manage a security.txt file for vulnerability disclosure on their websites.
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
var 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
$ npm install --global file-url
$ file-url --help
Usage
file-url [path]
Example
file-url
file:///Users/sindresorhus/dev/file-url
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 471,682 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
Cloudflare has launched a setup wizard allowing users to easily create and manage a security.txt file for vulnerability disclosure on their websites.
Security News
The Socket Research team breaks down a malicious npm package targeting the legitimate DOMPurify library. It uses obfuscated code to hide that it is exfiltrating browser and crypto wallet data.
Security News
ENISA’s 2024 report highlights the EU’s top cybersecurity threats, including rising DDoS attacks, ransomware, supply chain vulnerabilities, and weaponized AI.