Skip to content

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

License

Notifications You must be signed in to change notification settings

fabiospampinato/fileurl2path

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

fileurl2path

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

Install

npm install --save fileurl2path

Usage

import fileurl2path from 'fileurl2path';

// Converting a URL, automatically detecting the OS

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

// Converting a 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'

// Converting a 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