{"size": 614, "ext": "js", "max_stars_repo_path": "lib/mkdirp.js", "max_stars_repo_name": "hduarte/bagbak", "max_stars_repo_stars_event_min_datetime": "2019-11-04T06:45:42.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-31T15:44:57.000Z", "max_issues_repo_path": "lib/mkdirp.js", "max_issues_repo_name": "hduarte/bagbak", "max_issues_repo_issues_event_min_datetime": "2019-11-05T12:28:55.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-18T10:09:48.000Z", "max_forks_repo_path": "lib/mkdirp.js", "max_forks_repo_name": "hduarte/bagbak", "max_forks_repo_forks_event_min_datetime": "2019-11-04T07:11:37.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-28T01:24:46.000Z"}
{"max_stars_count": 548, "max_issues_count": 46, "max_forks_count": 94, "avg_line_length": 21.1724137931, "max_line_length": 74, "alphanum_fraction": 0.5928338762}
const path = require('path')
const fs = require('fs').promises

const _0777 = parseInt('0777', 8) & (~process.umask())

/**
 * @return {Promise<boolean>} made
 */
async function mkdirp(p, mode=_0777) {
  const abs = path.resolve(p)
  try {
    return await fs.mkdir(abs, mode)
  } catch(err) {
    if (err.code === 'ENOENT') {
      return mkdirp(path.dirname(abs), mode).then(() => mkdirp(abs, mode))
    } else {
      const stat = await fs.stat(abs)
      if (!stat.isDirectory())
        throw err
    }
  }
}

module.exports = mkdirp

// async function test() {
//   await mkdirp('/tmp/foo/bar/aaa/bbb')
// }
