1const platform = process.env.__TESTING_MKDIRP_PLATFORM__ || process.platform
2const { resolve, parse } = require('path')
3const 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
15  path = resolve(path)
16  if (platform === 'win32') {
17    const badWinChars = /[*|"<>?:]/
18    const {root} = parse(path)
19    if (badWinChars.test(path.substr(root.length))) {
20      throw Object.assign(new Error('Illegal characters in path.'), {
21        path,
22        code: 'EINVAL',
23      })
24    }
25  }
26
27  return path
28}
29module.exports = pathArg
30