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 🙏

© 2026 – Pkg Stats / Ryan Hefner

walktree

v0.2.1

Published

Converts recursive directory listing to an array or json object.

Downloads

5

Readme

Walktree

A easy to use module to convert recursive directory listing into an array or json object.

Install

npm install walktree

Usage

    var walktree = require('walktree');
    console.log(walktree.arraySync())
    // list of all files recursively (root folder: './')

Functions

    // Synchronously fetch all files in string array format
    // if no parameter is provided the default values are used.
    walktree.arraySync()
        //  output: 
        //      ['anotherFolder', 'file1.txt', 'file2.txt', 'picture1.jpg']
        
    walktree.jsonSync(): Synchronously fetch all files in string array format
        //  output:
        //      [
        //        {
        //            parent: './',
        //            name: 'anotherFolder'
        //            stats: [fsObject stats],
        //            isFile: false,
        //            isDirectory: true
        //        },
        //      {
        //            parent: './',
        //            name: 'file1.txt'
        //            stats: [fsObject stats],
        //            isFile: true,
        //            isDirectory: false
        //        },
        //        {
        //            parent: './',
        //            name: 'file2.txt'
        //            stats: [fsObject stats],
        //            isFile: true,
        //            isDirectory: false
        //        },
        //        {
        //            parent: './',
        //            name: 'picture1.txt'
        //            stats: [fsObject stats],
        //            isFile: true,
        //            isDirectory: false
        //        }
        //    ]

Options

  walktree.arraySync([
    {
        ['root': root], // String = './'
        ['junk': junk], // Boolean = false
        ['junkRegExp': junkRegExp], // RegExp = RegExp in "junk" dependency module 
        ['type': type], // String = 'filesAndFolders'
        ['recursively': recursively], // Boolean = true
        ['extended': extended], // Boolean = true
        ['filter': filter],  // Stribg = '*'
    }
  ])

####The json option is not required, in those cases "walkdir" will use the default configuration.

  1. root Is the root folder to start the walk.

        type: String
        default value: './'
        issue: in this version root can only point to current script execution directory './'
               or one of his childrens (for example './node_modules',  './views/templates',
               './scripts/bundle', etc.).
        example: 
            walktree = required('walktree')
            var w = walktree.arraySync({'root': './templates'})
            console.log(w)
            // Retrieve all files in "templates" folder (relative to the path of the 
            // caller script in your app) recursively as an array of string.
  2. junk Should we fetch junk files too? (for example ".thumbnails", ".DS_Store", etc).

        type: Boolean
        default value: false
        example: 
            walktree.arraySync({
                'root': './images', 
                junk: true 
            })
            // Retrieve all files inside "images" folder without getting thumbs.db (junk files) in the array.
  3. junkRegexp regExp field to customize the junk filter

        type: RegExp
        default value: /^npm-debug\.log$|^\..*\.swp$|^\.DS_Store|^\.AppleDouble$|^\.LSOverride$|^Icon[\r\?]?|^\._.*|^.Spotlight-V100$|\.Trashes|^__MACOSX$|~$|^Thumbs\.db$|^ehthumbs\.db$|^Desktop\.ini$/
        example: 
            walktree.arraySync({
                'root': './', 
                junkRegexp: /^.idea$|^.git$/
            })
  4. type (TODO: not yet implemented) Modality of the walk, retrieve files and folders, only files or only folders

        type: String
        default value: 'filesAndFolders'
        possible values: 'files' | 'folders' | 'filesAndFolders'
        example: 
            walktree.arraySync({
                'root': './', 
                'type': 'files'
            })
            // Retrieve only files
  5. recursively boolean: default = true; should we look inside every folder too?

        type: Boolean
        default value: true
        example: 
            walktree.arraySync({
                'recursively': false
            })
            // Retrieve only files in the folder specified but in the sub folders. In this
            // case because no folder is specified in the parameters, the folder that will 
            // be used is './'
  6. extended Should we retrieve detailed properties of each file? (like isFile and isFolder)

        type: Boolean
        default value: true
        example: 
            walktree.jsonSync({
                'extended': false
            })
            // Set it to false if you want to return the json structure with only "parent", 
            // "name" and "stat" fields.
  7. filter RegExp | wildcard string default: '*'

    var walktree = require('walktree');
    
    var w = walktree.jsonSync(
        {
            root: './templates'
          , filter: '*.html'
      //  , junk: true
        }
    );
    // will show only html files inside template folder. If you have more than one filter
    // you can use curly braces to separate them of example: 
    walktree.jsonSync(
        {
            root: './templates'
          , filter: '{*.html}{*.js}{*.css}'
        }
    );
    // This usage of filter will retrieve all html, javascript and cascade style files.

License

Copyright (c) 2014, Amilcar Calles [email protected]

Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.