npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

tree-parser

v1.2.4

Published

A small directory tree parser

Downloads

78

Readme

tree-parser

Circle CI Build Status npm version

tree-parser helps you to create JavaScript objects representing the structure of a given directory.

If you pass additional parameters as strings representing the names of JSON files inside your directories, tree-parser will parse their content, and will include it in the output as a regular object inside its parent directory, as you can see in the example below.

Usage

var parser = require('tree-parser');

var tree = parser('directory-path', [, files]);

tree-parser accepts two arguments:

  • directory-path: string - A string representing the absolute or relative path for the target directory.
  • [, files]: Array<string> - An optional list of comma separated file-names to be excluded from the _content list of files and included as an object in the current tree level.

Note: the files to be excluded can only be JSON files.

Sample Project

This is a sample project where you can find a lot of directories and files. Also you will find some JSON files named as `_data``, this files can be included in the output object as a regular JavaScript object exposing all its inner data.

You can use the path to this directory together with the name of the JSON file(s) to be parse.

.
├── README.md
├── build
│   ├── css
│   │   ├── styles.css
│   │   └── styles.min.css
│   ├── img
│   │   ├── banner.png
│   │   ├── burguer-icon.svg
│   │   ├── chevron-icon.svg
│   │   ├── hero.png
│   │   └── logo.svg
│   ├── index.html
│   └── js
│       ├── app.js
│       ├── app.min.js
│       └── vendor
├── circle.yml
├── package.json
├── src
│   ├── _data.json               <-- JSON file to be included as Object
│   ├── index.js
│   ├── main.scss
│   ├── modules
│   │   ├── app.js
│   │   ├── commands.js
│   │   ├── data.js
│   │   └── parser.js
│   └── scss
│       ├── base.scss
│       ├── fonts.scss
│       ├── functions
│       │   ├── colors.scss
│       │   └── metrics.scss
│       ├── grid.scss
│       └── themes.scss
├── tests
│   ├── _data.json               <-- JSON file to be included as Object
│   ├── index.spec.js
│   └── modules
│       ├── app.spec.js
│       ├── commands.spec.js
│       ├── data.spec.js
│       └── parser.spec.js
└── webpack.config.js

The Output

For an input like parser('directory-path', '_data'); using the directory structure we can find above, the output will be:

{
  _contents: [ 'README.md', 'app.js', 'circle.yml', 'package.json', 'webpack.config.js' ],
  build: {
    _contents: [ 'index.html' ],
    css: {
      _contents: [ 'styles.css', 'styles.min.css' ]
    },
    img: {
      _contents: [ 'banner.png', 'burguer-icon.svg', 'chevron-icon.svg', 'hero.png', 'logo.svg' ]
    },
    js: {
      _contents: [ 'app.js', 'app.min.js' ],
      vendor: {
        _contents: [ ]
      }
    }
  },
  src: {
    _contents: [ 'index.js', 'main.scss' ],
    _data: {                                          <-- This is the JSON file after beign parsed
      appName: 'The Application Name',
      description: 'Application's description',
      module: 'src'
    },
    modules: {
      _contents: [ 'app.js', 'commands.js', 'data.js', 'parser.js' ]
    },
    scss: {
      _contents: [ 'base.scss', 'fonts.scss', 'grid.scss', 'themes.scss' ],
      functions: {
        _contents: [ 'colors.scss', 'metrics.scss' ]
      }
    }
  },
  tests: {
    _contents: [ 'index.spec.js' ],
    _data: {                                          <-- This is the JSON file after beign parsed
      testingFramework: 'Tape',
      description: 'This is a test JSON file',
      version: '1.0.0'
    },
    modules: {
      _contents: [ 'app.spec.js', 'commands.spec.js', 'data.spec.js', 'parser.spec.js' ]
    }
  }
}

Note how the _data.json file was included in its directory tree level with the file content exposed as an object.