{"size": 1333, "ext": "js", "max_stars_repo_path": "internal/pathWalk.js", "max_stars_repo_name": "richytong/servicio", "max_stars_repo_stars_event_min_datetime": "2020-11-11T21:55:42.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-25T16:20:56.000Z", "max_issues_repo_path": "internal/pathWalk.js", "max_issues_repo_name": "richytong/presidium", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "internal/pathWalk.js", "max_forks_repo_name": "richytong/presidium", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 6, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 22.2166666667, "max_line_length": 63, "alphanum_fraction": 0.5851462866}
const fs = require('fs/promises')
const rubico = require('rubico')
const pathResolve = require('./pathResolve')
const isArray = require('./isArray')

const {
  pipe, tap,
  switchCase, tryCatch,
  fork, assign, get, pick, omit,
  map, filter, reduce, transform, flatMap,
  and, or, not, any, all,
  eq, gt, lt, gte, lte,
  thunkify, always,
  curry, __,
} = rubico

/**
 * @name pathWalk
 *
 * @synopsis
 * ```coffeescript [specscript]
 * pathWalk(path, options? {
 *   ignore: Array<string>, // names or paths
 * }) -> Promise<Array<string>>
 * ```
 *
 * @description
 * ```javascript
 * pathWalk('./my/path/', {
 *   ignore: ['node_modules', '.github'],
 * }) // -> Promise<paths Array<string>>
 * ```
 */
const pathWalk = function (path, options) {
  const ignore = new Set(get('ignore', [])(options))
  return pipe([
    pathResolve,
    tryCatch(
      curry.arity(2, fs.readdir, __, { withFileTypes: true }),
      () => []),

    flatMap(dirent => {
      const direntName = dirent.name,
        direntPath = pathResolve(path, direntName)
      if (
        ignore.size > 0
          && (ignore.has(direntName) || ignore.has(direntPath))
      ) {
        return []
      }
      if (dirent.isDirectory()) {
        return pathWalk(direntPath)
      }
      return [direntPath]
    }),
  ])(path)
}

module.exports = pathWalk
