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

@aboviq/readdir-recursive

v1.3.0

Published

Customizeable async recursive fs.readdir with no dependencies and sane defaults

Downloads

37

Readme

@aboviq/readdir-recursive

Build status NPM version XO code style

Customizeable async recursive fs.readdir with no dependencies and sane defaults

Why?

  • No dependencies / Small
  • Asynchronous, i.e. returns a promise (uses async/await under the hood)
  • Provides a syncronous version as well
  • Sane defaults, i.e. does not recurse into node_modules by default
  • Fully customizable, with options to decide in which folders to recurse into and what files and information to include in the results, with full access to each file's Stats information

Installation

Install @aboviq/readdir-recursive using npm:

npm install @aboviq/readdir-recursive

Usage

Module usage

const readdirRecursive = require('@aboviq/readdir-recursive');

const files = await readdirRecursive('a/path');
/*
[
  "/full-path/a/path/filename.ext",
  "/full-path/a/path/nested/folders/another.ext",
  ...
]
*/

const files = readdirRecursive.sync('a/path');
/*
[
  "/full-path/a/path/filename.ext",
  "/full-path/a/path/nested/folders/another.ext",
  ...
]
*/

API

readdirRecursive(dir, options)

| Name | Type | Description | | ------- | -------- | ------------------------------------------------------------------------------------- | | dir | String | The folder to read files recursively in, either relative to cwd or an absolute path | | options | Object | Options for filtering, recursion and transformation |

Returns: Promise<Array>, all found files transformed according to the transformer and that has not been filtered out

readdirRecursive.sync(dir, options)

| Name | Type | Description | | ------- | -------- | ------------------------------------------------------------------------------------- | | dir | String | The folder to read files recursively in, either relative to cwd or an absolute path | | options | Object | Options for filtering, recursion and transformation |

Returns: Array, all found files transformed according to the transformer and that has not been filtered out

Options

Note: all function options can be asynchronous (return promises) when using the async version of readdirRecursive, but not with the sync version.

options.filter

Type: Function
Signature: filter :: Object -> Boolean
Default: () => true

The filter option is used to decide if a file should be included in the resulting array of files or not. A file is included if the filter function returns a truthy value.

The Object passed to the filter function has the following properties:

| Name | Type | Description | | ----- | ------------------- | -------------------------------------------------------------------- | | file | String | The file name, e.g. "file.txt" | | path | String | The full path to the file, e.g. "/your/folder/sub-folder/file.txt" | | stats | Stats | A stats object providing information about the file |

options.transform

Type: Function
Signature: transform :: Object -> String
Default: a function returing the full path of each file

The transform option is used to transform file information into something useful. Every file that passes the filter function will be transformed before being included in the resulting array.

The Object passed to the transform function has the following properties:

| Name | Type | Description | | ----- | ------------------- | -------------------------------------------------------------------- | | file | String | The file name, e.g. "file.txt" | | path | String | The full path to the file, e.g. "/your/folder/sub-folder/file.txt" | | stats | Stats | A stats object providing information about the file |

options.recurse

Type: Function
Signature: recurse :: Object -> Boolean
Default: a function which won't recurse node_modules

The recurse option is used to decide if a folder should be recursed into or not. A folder is recursed if the recurse function returns a truthy value.

The Object passed to the recurse function has the following properties:

| Name | Type | Description | | ----- | ------------------- | ------------------------------------------------------------- | | dir | String | The folder name, e.g. "src" | | path | String | The full path to the folder, e.g. "/your/folder/sub-folder" | | stats | Stats | A stats object providing information about the folder |

Contributing

See Contribution Guidelines and our Code Of Conduct.

License

MIT © Aboviq AB