fileurl2path

A tiny function for converting a file URL to a file path.

MIT 2 个版本
安装
npm install fileurl2path
yarn add fileurl2path
pnpm add fileurl2path
bun add fileurl2path
README

fileurl2path

A tiny function for converting a file URL to a path.

Install

npm install fileurl2path

Usage

import fileurl2path from 'fileurl2path';

// Let's convert a file URL, automatically detecting the OS

const url = 'file:///Users/fabio/Desktop/fileurl2path/index.js';
const path = fileurl2path ( url ); // => '/Users/fabio/Desktop/fileurl2path/index.js'

// Let's convert a file URL, explicitly using the algorithm for POSIX paths

const url = 'file:///Users/fabio/Desktop/fileurl2path/index.js';
const path = fileurl2path.posix ( url ); // => '/Users/fabio/Desktop/fileurl2path/index.js'

// Let's convert a file URL, explicitly using the algorithm for ~~wrong~~ Windows paths

const url = 'file:///C:/Users/fabio/Desktop/fileurl2path/index.js';
const path = fileurl2path.win32 ( url ); // => 'C:\\Users\\fabio\\Desktop\\fileurl2path\\index.js'

License

MIT © Fabio Spampinato

版本列表
1.0.1 2025-01-17
1.0.0 2023-12-11