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.

path-arg.js 730B

1234567891011121314151617181920212223242526272829
  1. const platform = process.env.__TESTING_MKDIRP_PLATFORM__ || process.platform
  2. const { resolve, parse } = require('path')
  3. const pathArg = path => {
  4. if (/\0/.test(path)) {
  5. // simulate same failure that node raises
  6. throw Object.assign(
  7. new TypeError('path must be a string without null bytes'),
  8. {
  9. path,
  10. code: 'ERR_INVALID_ARG_VALUE',
  11. }
  12. )
  13. }
  14. path = resolve(path)
  15. if (platform === 'win32') {
  16. const badWinChars = /[*|"<>?:]/
  17. const {root} = parse(path)
  18. if (badWinChars.test(path.substr(root.length))) {
  19. throw Object.assign(new Error('Illegal characters in path.'), {
  20. path,
  21. code: 'EINVAL',
  22. })
  23. }
  24. }
  25. return path
  26. }
  27. module.exports = pathArg