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 🙏

© 2025 – Pkg Stats / Ryan Hefner

chew-dir

v0.2.2

Published

Chew through a directory processing files

Downloads

114

Readme

chew-dir pipeline statuscoverage report

Chew through a directory processing files as you go!

Note that this package is inteded to be used for ad-hoc scripts churning through a directory worth of files converting them to some other form. For your production needs you might want to look elsewhere.

Usage

  • All options have a default. Prints files from the working directory to the console, unless either the process or processAll function is specified.
  • Supports async behavior returning a Promise where applicable.
  • You'll find further examples in the /examples directory.

Example

Deep scan directory for all SVGs and copy them to target flattened and lower cased.

await chewDir({
  source: 'examples/source',
  target: 'examples/target',
  deep: true,
  include: /\.svg$/i,
  process: async ({ absolutePath, base }, api) => {
    await api.copy(absolutePath, base.toLowerCase());
    console.log(`Copied ${base} as ${base.toLowerCase()}`);
  }
});

API

See type definitions for docs.

type ChewOptions<T> = {
  /** Source dir to process. Uses 'process.cwd()' as root for relative path. */
  source?: string,
  /** Target dir used by the convenience API. Uses 'process.cwd()' as root for relative path. */
  target?: string,
  /** Enable deep (recursive) traversal of 'source'. False by default. */
  deep?: boolean,
  /** Empty target first. False by default. */
  cleanTarget?: boolean,
  /** Include dirs in processed files. False by default. */
  includeDirectories?: boolean,
  /** Only include results matched by the pattern(s). String and RegExp uses 'relativeName' of results. */
  include?: Pattern | Pattern[],
  /** Exclude results matched by the pattern(s). String and RegExp uses 'relativeName' of results. Takes precedence over 'include'. */
  exclude?: Pattern | Pattern[],
    /** Process files all at once. Takes precedence over process */
	processAll?: (files: ChewFile[], api: ProcessApi) => T | Promise<T> | void,
  /** Process files one by one. */
  process?: (file: ChewFile, api: ProcessApi) => T | Promise<T> | void,
  /** Set amount of retries on common temporary file system errors. 3 by default.*/
  retries?: number,
  /** Set milliseconds to wait between retries. 50 by default. */
  retryInterval?: number,
  /** Error predicate to check if failed fs operation should be retried. Matches 'EBUSY', 'ENOENT' by default. */
  retryWhen?: (err: Error) => boolean
  /** Error predicate to check what to ignore. Matches 'EEXIST' by default. */
  ignoreWhen?: any,
};

type ChewFile = {
  /** Base file or dir name. Eg.: "package.json" */
  base: string,
  /** Extension of a file or empty string for dir. Eg.: ".json" */
  ext: string,
  /** Name of a file or dir. Eg.: "package" */
  name: string,
  /** Absolute path in POSIX format. Eg.: "d:/workspaces/chew-dir/package.json" */
  absolutePath: string,
  /** Path relative to the 'source' option in POSIX format. Eg.: "chew-dir/package.json" */
  relativePath: string,
  /** Name relative to the 'source' option in POSIX format. Eg.: "chew-dir/package" */
  relativeName: string,
  /** Path to parent dir relative to the 'source' option in POSIX format. Eg.: "chew-dir" */
  relativeParent: string,
  isDirectory: boolean,
  isFile: boolean,
  /** Stats returned by fs-extra */
  stats: Stats,
  /** Read contents using fs-extra readFile with UTF-8 encoding. Only for files. */
	read?: () => Promise<string>,
  /** Creates read stream using fs-extra createReadStream. Only for files. */
	readStream?: () => Promise<string>,
};

type ProcessApi = {
  /** Same as fs-extra copy that can also be called with a single file argument. */
  copy: typeof copy,
  /** Same as fs-extra outputFile with encoding set to UTF-8 by default. */
  outputFile: typeof outputFile,
};

type Pattern = string | RegExp | ((el: ChewFile) => boolean);