# directoree

> ## Installation:

Latest version **2.4.0** (published 2023-11-08) · ISC license · 0 weekly downloads

## Install

```sh
npm install directoree
pnpm add directoree
yarn add directoree
bun add directoree
```

## Health

**Score 30/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.4.0 |
| Published | 2023-11-08 |
| First published | 2023-11-07 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 12.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | bosari-a |
| Maintainers | bosari-a |
| Keywords | readdir, unix, tree, tree-directory, unix paths, recursive |

## Links

- npm: https://www.npmjs.com/package/directoree
- Repository: https://github.com/bosari-a/tree-directory
- Homepage: https://github.com/bosari-a/tree-directory#readme
- Issues: https://github.com/bosari-a/tree-directory/issues
- npm.io page: https://npm.io/package/directoree

## Alternatives

- [base64url](https://npm.io/package/base64url.md) — 6.1M weekly downloads
- [get-installed-path](https://npm.io/package/get-installed-path.md) — 502.9K weekly downloads
- [@uppy/url](https://npm.io/package/@uppy/url.md) — 185.8K weekly downloads
- [@d3fc/d3fc-shape](https://npm.io/package/@d3fc/d3fc-shape.md) — 16.2K weekly downloads
- [localizer](https://npm.io/package/localizer.md) — 226 weekly downloads

## Recent versions

- 2.4.0 (latest) — 2023-11-08
- 2.3.0 — 2023-11-07
- 2.2.0 — 2023-11-07
- 2.1.0 — 2023-11-07
- 2.0.0 — 2023-11-07
- 1.0.0 — 2023-11-07

## README

# Tree directory

## Installation:

`npm install directoree`

### unixreaddir

This function (the only one exported) in the package is meant to replace common general usecases for node's native `fs/promises` `readdir` module.

## The name

The name might suggest that this somehow only works in unix or something but it's for a different reason. This package was born out of my discontent with `win32` path conventions. In `win32` paths use `\` or `\\` instead of `/`. This package aims to read your input (whether it's a `win32` path or `unix` path) and output `unix` style paths.

## Recursive option

Setting `{ recursive : true }` when calling `unixreaddir` will generate a tree structure of the directory you are trying to access.

## Usage:

For these examples the directory structure looks like this:

```bash
$ tree parent
parent/
├── sibling0
│   ├── a
│   │   └── b
│   │       └── c
│   │           └── d.txt
│   ├── file1.txt
│   └── subdir
│       ├── file1.txt
│       └── file2.txt
├── sibling1
│   ├── file1.txt
│   └── file2.txt
└── sibling2
```

### Example 1. Basic `readdir` no options

```ts
import { unixreaddir } from "directoree";

unixreaddir("parent").then((result) => {
  console.dir(result, { depth: null });
});
/*
[ 'sibling0', 'sibling1', 'sibling2' ]
*/
```

### Example 2. `{ withFileTypes : true }`

```ts
import { unixreaddir } from "directoree";

unixreaddir("parent", { withFileTypes: true }).then((result) => {
  console.dir(result, { depth: null });
});
/*
[
  Dirent { name: 'sibling0', path: 'parent', [Symbol(type)]: 2 },
  Dirent { name: 'sibling1', path: 'parent', [Symbol(type)]: 2 },
  Dirent { name: 'sibling2', path: 'parent', [Symbol(type)]: 2 }
]
*/
```

Check [Dirent](https://nodejs.org/api/fs.html#class-fsdirent) for more details.

### Example 3. `{ recursive : true }`

```ts
import { unixreaddir } from "directoree";

unixreaddir("parent", { recursive: true }).then((tree) => {
  console.dir(tree, { depth: null });
});

/*
TreeNode {
  name: 'parent',
  path: '.',
  isFile: false,
  children: [
    TreeNode {
      name: 'sibling0',
      path: 'parent',
      isFile: false,
      children: [
        TreeNode {
          name: 'a',
          path: 'parent/sibling0',
          isFile: false,
          children: [
            TreeNode {
              name: 'b',
              path: 'parent/sibling0/a',
              isFile: false,
              children: [
                TreeNode {
                  name: 'c',
                  path: 'parent/sibling0/a/b',
                  isFile: false,
                  children: [
                    TreeNode {
                      name: 'd.txt',
                      path: 'parent/sibling0/a/b/c',
                      isFile: true,
                      children: undefined
                    }
                  ]
                }
              ]
            }
          ]
        },
        TreeNode {
          name: 'file1.txt',
          path: 'parent/sibling0',
          isFile: true,
          children: undefined
        },
        TreeNode {
          name: 'subdir',
          path: 'parent/sibling0',
          isFile: false,
          children: [
            TreeNode {
              name: 'file1.txt',
              path: 'parent/sibling0/subdir',
              isFile: true,
              children: undefined
            },
            TreeNode {
              name: 'file2.txt',
              path: 'parent/sibling0/subdir',
              isFile: true,
              children: undefined
            }
          ]
        }
      ]
    },
    TreeNode {
      name: 'sibling1',
      path: 'parent',
      isFile: false,
      children: [
        TreeNode {
          name: 'file1.txt',
          path: 'parent/sibling1',
          isFile: true,
          children: undefined
        },
        TreeNode {
          name: 'file2.txt',
          path: 'parent/sibling1',
          isFile: true,
          children: undefined
        }
      ]
    },
    TreeNode {
      name: 'sibling2',
      path: 'parent',
      isFile: false,
      children: []
    }
  ]
}
*/
```

## Documentation:

You can check [the docs](https://bosari-a.github.io/tree-directory/) for more details.

---
_Source: https://npm.io/package/directoree · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
