You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

25 lines
517 B

4 years ago
  1. 'use strict'
  2. const path = require('path')
  3. // get drive on windows
  4. function getRootPath (p) {
  5. p = path.normalize(path.resolve(p)).split(path.sep)
  6. if (p.length > 0) return p[0]
  7. return null
  8. }
  9. // http://stackoverflow.com/a/62888/10333 contains more accurate
  10. // TODO: expand to include the rest
  11. const INVALID_PATH_CHARS = /[<>:"|?*]/
  12. function invalidWin32Path (p) {
  13. const rp = getRootPath(p)
  14. p = p.replace(rp, '')
  15. return INVALID_PATH_CHARS.test(p)
  16. }
  17. module.exports = {
  18. getRootPath,
  19. invalidWin32Path
  20. }