
Product
Introducing Rust Support in Socket
Socket now supports Rust and Cargo, offering package search for all users and experimental SBOM generation for enterprise projects.
easy-recurse
Advanced tools
Let you use recursion in javascript easier. 让你更容易的使用 javascript 递归。
npm i easy-recurse
import easyRecurse from "easy-recurse";
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));
});
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));
});
Must return array. 必须返回数组。
await easyRecurse(document.querySelector("div"), async (item) => {
console.log(item);
return item.parent && [item.parent]; // must return array
});
const start = document.body.children;
await easyRecurse(start, async (item) => {
return item === start ? [...start] : item.children;
});
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>
.
null
or undefined
, it will ignore current item's children. For example, you can skip a directory. 如果返回null
或undefined
,它将忽略当前项的子项。例如,你可以跳过一个目录。false
, it will stop recursion. 如果返回false
,它将停止递归。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
禁用。如果超过限制,会抛出错误。FAQs
Let you use recursion in javascript easier. 让你更容易的使用 javascript 递归。
We found that easy-recurse demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket now supports Rust and Cargo, offering package search for all users and experimental SBOM generation for enterprise projects.
Product
Socket’s precomputed reachability slashes false positives by flagging up to 80% of vulnerabilities as irrelevant, with no setup and instant results.
Product
Socket is launching experimental protection for Chrome extensions, scanning for malware and risky permissions to prevent silent supply chain attacks.