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

easy-recurse

v1.0.2

Published

Let you use recursion in javascript easier. 让你更容易的使用 javascript 递归。

Readme

easy-recurse

language license npm version workflow npm bundle size (scoped)

Let you use recursion in javascript easier. 让你更容易的使用 javascript 递归。

Important / 重要

  • callback must return array. 回调必须返回数组。
  • To prevent dead loop, the default recursion depth is 10000. 为防止死循环,默认限制递归深度为 10000。

Installation / 安装

npm i easy-recurse

import / 导入

import easyRecurse from "easy-recurse";

Usage / 使用

Recurse directory / 递归目录

import fs from "node:fs";
import path from "node:path";

await easyRecurse("./test", (filepath, parent, i) => {
  let stat = fs.statSync(filepath);
  console.log(filepath);
  if (!stat.isDirectory()) {
    return;
  }
  let paths = fs.readdirSync(filepath);
  return paths.map((v) => path.join(filepath || "", v));
});

Recurse directory and ignore node_modules / 递归目录并跳过 node_modules

import fs from "node:fs";
import path from "node:path";

await easyRecurse("./", (filepath, parent, i) => {
  let stat = fs.statSync(filepath);
  console.log(filepath);
  if (filepath.endsWith("node_modules")) {
    return;
  }
  if (!stat.isDirectory()) {
    return;
  }
  let paths = fs.readdirSync(filepath);
  return paths.map((v) => path.join(filepath || "", v));
});

Recurse DOM tree upward / 向上递归 DOM 树

Must return array. 必须返回数组。

await easyRecurse(document.querySelector("div"), async (item) => {
  console.log(item);
  return item.parent && [item.parent]; // must return array
});

Start from an array / 从数组开始

const start = document.body.children;
await easyRecurse(start, async (item) => {
  return item === start ? [...start] : item.children;
});

API

easyRecurse

  • easyRecurse: (entry, callback, options) => Promise<void>
    • entry: entry data. 入口数据。
    • callback: (item: any, parent: any, i: number) => return
      • item: current item. 当前项。
      • parent: parent item. 父项。
      • i: number, index in parent's children. 当前项在父项子集中的索引。
      • return: T[]|any[] | null | undefined | false | Promise<T[]|any[] | null | undefined | false>.
        • Return next recursion item. Must be an array. If the next recursion item is only one, you can wrap it in an array. 返回下次递归的项。必须是数组,如果下次递归的项只有一个,可以用数组包裹。
        • If return null or undefined, it will ignore current item's children. For example, you can skip a directory. 如果返回nullundefined,它将忽略当前项的子项。例如,你可以跳过一个目录。
        • If return false, it will stop recursion. 如果返回false,它将停止递归。
        • Can return Promise. 可以返回 Promise.
    • options: { depth?: number, concurrency?: number }
      • async: boolean, default is false. 是否异步,默认关闭。
      • maxRecurDepth: number, default is 10000. Use 0 to disable. If overflow, it will throw an error. 最大递归深度,默认 10000。使用0禁用。如果超过限制,会抛出错误。

License

MIT