@flupkejs/escalade 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json ADDED
@@ -0,0 +1,2 @@
1
+ {"name":"@flupkejs/escalade","version":"1.0.0","main":"src/index.js","types":"src/index.d.ts","files":["src"],"exports": { ".": { "types": "./src/index.d.ts", "default": "./src/index.js" }, "./package.json": "./package.json" },
2
+ "license":"MIT"}
package/src/index.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ declare function escalade(dir: string, cb: (dir: string, files: string[]) => string | false | void | Promise<string | false | void>): Promise<string | undefined>;
2
+ export = escalade;
package/src/index.js ADDED
@@ -0,0 +1,13 @@
1
+ const path = require('node:path');
2
+ const fs = require('node:fs');
3
+ module.exports = async function escalade(dir, cb) {
4
+ dir = path.resolve(dir);
5
+ while (true) {
6
+ const files = fs.readdirSync(dir);
7
+ const result = await cb(dir, files);
8
+ if (result) return path.resolve(dir, result);
9
+ const parent = path.dirname(dir);
10
+ if (parent === dir) return;
11
+ dir = parent;
12
+ }
13
+ };