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

recrawl

v2.2.1

Published

[![npm](https://img.shields.io/npm/v/recrawl.svg)](https://www.npmjs.com/package/recrawl) [![ci](https://github.com/aleclarson/recrawl/actions/workflows/release.yml/badge.svg)](https://github.com/aleclarson/recrawl/actions/workflows/release.yml) [![codeco

Downloads

10,664

Readme

recrawl

npm ci codecov Bundle size Code style: Prettier Donate

Collect the descendants of a directory.

import { recrawl } from 'recrawl'

// Create a crawl function.
// These are the default options.
const crawl = recrawl({
  only: [],
  skip: [],
  deep: true,
  follow: false,
})

// The result is an array when `follow` is false, else an object.
const files = crawl(root)

// Provide your own array/object.
crawl(root, files)

// Provide an iterator.
crawl(root, (file, link) => {
  // The `file` argument is relative to the root.
  // The `link` argument is null for non-symlinks. It will be absolute if the target is outside the root.
})

You can use the crawl() export if you don't want to reuse the configured crawler.

import { crawl } from 'recrawl'

crawl(root, {
  only: [],
  skip: [],
  deep: true,
  follow: false,
})

Options

  • only?: (string|RegExp)[]
  • skip?: (string|RegExp)[]
  • absolute?: boolean
  • deep?: boolean
  • depth?: number
  • enter?: function
  • filter?: function
  • follow?: boolean|number|function
  • adapter?: FileAdapter

The only and skip options should be self-explanatory. Paths matching any of the only patterns are good. When only is an empty array, all paths are good. Paths matching any of the skip patterns are bad. When skip is an empty array, no paths are bad. The skip patterns override the only patterns.

The absolute option converts matching file paths into their absolute form.

To avoid crawling sub-directories, set deep to false or depth to 0. You should never define both deep and depth, because the depth option implies deep when it's greater than zero. If neither deep nor depth are defined, the default depth is infinite.

The enter option is called whenever a directory is encountered. It's passed the directory path and the current depth. You may return a falsy value to avoid crawling a directory.

The filter option is called whenever a filename is encountered. It's passed the filename and its basename. You may return a falsy value to skip a filename. The only and skip options are applied before this option is called.

To follow all symlinks, set follow to true. For greater control, use a function. It's called whenever a symlink is encountered. You may return a falsy value to avoid following a symlink. It's passed the symlink path and the current link depth. If you only need to limit the link depth, you can set follow to a number, where zero is equivalent to false.

The adapter option lets you provide your own filesystem.

Gotchas

  • Directory symlinks are treated the same as real directories
  • Directories are not affected by the only option

Pattern syntax

Recrawl has its own take on globbing.

  1. When a path has no separators (/), only the basename is matched.
'*.js' // matches 'a.js' and 'a/b.js'
  1. Recursivity is implicit.
'a/b' // identical to '**/a/b'
  1. Use a leading separator to match against the root.
'/*.js' // matches 'a.js' not 'a/b.js'
  1. Use a trailing separator to match all descendants.
'foo/' // matches 'foo/bar' and 'foo/bar/baz' etc
  1. Regular expression syntax is supported. (except dot-all)
'*.jsx?' // matches 'a.js' and 'b.jsx'
'*.(js|ts)' // matches 'a.js' and 'b.ts'
  1. Recursive globbing is supported.
'foo/**/bar' // matches 'foo/bar' and 'foo/a/b/c/bar' etc