GitHub 6219★

Normalize file path slashes

JavaScript version

const normalizePath = (path) => path.replace(/[\\/]+/g, '/');

TypeScript version

const normalizePath = (path: string): string => path.replace(/[\\/]+/g, '/');

Examples

normalizePath('\\foo\\bar\\baz\\'); // /foo/bar/baz/
normalizePath('.//foo//bar///////baz/'); // ./foo/bar/baz/
Follow me on and to get more useful contents.