hyperdrive icon indicating copy to clipboard operation
hyperdrive copied to clipboard

add path normalization

Open juliangruber opened this issue 9 years ago • 3 comments

As mentioned in https://github.com/juliangruber/hyperdrive-import-files/pull/23#issuecomment-253499239, it would make sense to me to fully treat entry.name as a path and thus also apply normalisation if necessary. Currently it's only treated as a String, and eg there could be two entries /entry and ./entry. This should help the modules depending on this to simplify their path logic.

juliangruber avatar Oct 27 '16 09:10 juliangruber

great idea. do you know a module that helps with this?

mafintosh avatar Oct 27 '16 10:10 mafintosh

this seems to work well:

const normalize = p => path.resolve('/', p)

Normalizes like this:

  • / -> /
  • . -> /
  • ./foo -> /foo
  • foo/bar -> /foo/bar
  • foo/bar/ -> /foo/bar

juliangruber avatar Oct 27 '16 11:10 juliangruber

Cool. In addition to that it should normalize windows paths to unix ones. \ --> /

mafintosh avatar Oct 27 '16 11:10 mafintosh