A tiny package for parsing file paths, with the same output as Node@18.19.0's path.parse
function.
npm install tiny-path-parse
import parse from 'tiny-path-parse'; // Implementation depending on the current platform
import posix from 'nanopath/posix'; // Implementation for POSIX paths
import win32 from 'nanopath/win32'; // Implementation for Windows paths
// Let's parse a path with automatic posix/win32 flavor detection, based on process.platform
parse ( '/foo/bar.baz' ); // => { root: '/', dir: '/foo', base: 'bar.baz', name: 'bar', ext: '.baz' }
// Let's parse a path with the posix flavor
parse.posix ( '/foo/bar.baz' ); // => { root: '/', dir: '/foo', base: 'bar.baz', name: 'bar', ext: '.baz' }
// Let's parse a path with the win32 flavor
parse.win32 ( 'C:\\foo\\bar.baz' ); // => { root: 'C:\\', dir: 'C:\\foo', base: 'bar.baz', name: 'bar', ext: '.baz' }
MIT © Fabio Spampinato