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