# directory-structure-json

> Getting directory structures and traversing them in JSON

Latest version **1.0.0** (published 2016-05-10) · ISC license · 0 weekly downloads

## Install

```sh
npm install directory-structure-json
pnpm add directory-structure-json
yarn add directory-structure-json
bun add directory-structure-json
```

## Health

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

Positive: has types package; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2016-05-10 |
| First published | 2016-03-15 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | separate (@types/directory-structure-json) |
| Module format | CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 8 |
| Author | atracaelus@gmail.com |
| Maintainers | atracaelus |

## Links

- npm: https://www.npmjs.com/package/directory-structure-json
- Repository: https://github.com/MistAEGIS/Directory-Structure-JSON
- Homepage: https://github.com/MistAEGIS/Directory-Structure-JSON#readme
- Issues: https://github.com/MistAEGIS/Directory-Structure-JSON/issues
- npm.io page: https://npm.io/package/directory-structure-json

## Dependencies (1)

- [path](https://npm.io/package/path.md) ^0.12.7

## Recent versions

- 1.0.0 (latest) — 2016-05-10
- 0.0.2 — 2016-03-16
- 0.0.1 — 2016-03-15

## README

Directory Structure JSON
========================

This module exposes functions with which you can:

* Get a JSON structure of a folder (including subdirectories and files), note that you have specify the `filesystem` to use yourself
* Traverse a structure, giving callbacks to execute when a file or folder is found

## Installation
    npm install --save directory-structure-json

## Example of a directory structure output
``` json
 [
    {
        "type": "file",
        "name": "index.js"
    },
    {
        "name": "node_modules",
        "type": "folder",
        "children": [
            {
                "name": "path",
                "type": "folder",
                "children": [
                    {
                        "type": "file",
                        "name": "path.js"
                    },
                    {
                        "type": "file",
                        "name": "package.json"
                    },
                    {
                        "type": "file",
                        "name": "README.md"
                    }
                ]
            }
        ]
    }
]
```

## Get directory structure
``` javascript
var DirectoryStructureJSON = require('directory-structure-json');
var basepath = 'path/to/some/folder';
var fs = require('fs'); // you can select any filesystem as long as it implements the same functions that native fs uses.

DirectoryStructureJSON.getStructure(fs, basepath, function (err, structure, total) {
    if (err) console.log(err);

    console.log('there are a total of: ', total.folders, ' folders and ', total.files, ' files');
    console.log('the structure looks like: ', JSON.stringify(structure, null, 4));
});
```

## Traverse structure
The structure retrieved from the example above can be traversed.


``` javascript
var DirectoryStructureJSON = require('directory-structure-json');
var basepath = 'path/to/some/folder'; // this will be prepended to the paths found in the structure

DirectoryStructureJSON.traverseStructure(structure, basepath,
function (folder, path) {
    console.log('folder found: ', folder.name, 'at path: ', path);
},
function (file, path) {
    console.log('file found: ', file.name, 'at path: ', path);
});
```

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