Socket
Socket
Sign inDemoInstall

escalade

Package Overview
Dependencies
0
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 2.0.0 to 3.0.0

9

dist/index.js
const { dirname, resolve } = require('path');
const { readdir, stat } = require('fs');
const { promisify } = require('util');
const { homedir } = require('os');

@@ -10,5 +9,4 @@ const toStats = promisify(stat);

module.exports = async function (start, callback) {
let tmp, stop = homedir();
let dir = resolve('.', start);
let stats = await toStats(dir);
let tmp, stats = await toStats(dir);

@@ -19,7 +17,8 @@ if (!stats.isDirectory()) {

while (dir.startsWith(stop)) {
while (true) {
tmp = await callback(dir, await toRead(dir));
if (tmp) return resolve(dir, tmp);
dir = dirname(dir);
dir = dirname(tmp = dir);
if (tmp === dir) break;
}
}
{
"name": "escalade",
"version": "2.0.0",
"version": "3.0.0",
"repository": "lukeed/escalade",
"description": "A tiny (196B to 224B) and fast utility to ascend parent directories",
"description": "A tiny (183B to 210B) and fast utility to ascend parent directories",
"module": "dist/index.mjs",

@@ -7,0 +7,0 @@ "main": "dist/index.js",

# escalade [![CI](https://github.com/lukeed/escalade/workflows/CI/badge.svg)](https://github.com/lukeed/escalade/actions) [![codecov](https://badgen.now.sh/codecov/c/github/lukeed/escalade)](https://codecov.io/gh/lukeed/escalade)
> A tiny (196B to 224B) and [fast](#benchmarks) utility to ascend parent directories
> A tiny (183B to 210B) and [fast](#benchmarks) utility to ascend parent directories

@@ -8,5 +8,5 @@ With [escalade](https://en.wikipedia.org/wiki/Escalade), you can scale parent directories until you've found what you're looking for.<br>Given an input file or directory, `escalade` will continue executing your callback function until either:

1) the callback returns a truthy value
2) `escalade` has reached the `$HOME` directory ([`os.homedir()`](https://nodejs.org/api/os.html#os_os_homedir))
2) `escalade` has reached the system root directory (eg, `/`)
> **Important:**<br>Please note that `escalade` will never traverse _beyond_ the user's home directory.<br>Additionally, `escalade` only deals with direct ancestry – it will not dive into parents' sibling directories.
> **Important:**<br>Please note that `escalade` only deals with direct ancestry – it will not dive into parents' sibling directories.

@@ -26,3 +26,3 @@ ## Install

> **Node.js:** >= 8.x<br>
> **Size (gzip):** 224 bytes<br>
> **Size (gzip):** 210 bytes<br>
> **Availability:** [CommonJS](https://unpkg.com/escalade/dist/index.js), [ES Module](https://unpkg.com/escalade/dist/index.mjs)

@@ -34,3 +34,3 @@

> **Node.js:** >= 6.x<br>
> **Size (gzip):** 196 bytes<br>
> **Size (gzip):** 183 bytes<br>
> **Availability:** [CommonJS](https://unpkg.com/escalade/sync/index.js), [ES Module](https://unpkg.com/escalade/sync/index.mjs)

@@ -45,4 +45,2 @@

> Assume `process.cwd()` is `/Users/lukeed/oss/escalade`
```

@@ -98,7 +96,7 @@ /Users/lukeed

// Now search for "license"
// ~> Will never leave "/Users/lukeed/oss/escalade" directory
const license = await escalade(input, (dir, names) => {
// Now search for "missing123.txt"
// (Assume it doesn't exist anywhere!)
const missing = await escalade(input, (dir, names) => {
console.log('~> dir:', dir);
return names.includes('license') && 'license';
return names.includes('missing123.txt') && 'missing123.txt';
});

@@ -110,4 +108,8 @@

//~> dir: /Users/lukeed/oss/escalade
//~> dir: /Users/lukeed/oss
//~> dir: /Users/lukeed
//~> dir: /Users
//~> dir: /
console.log(license);
console.log(missing);
//=> undefined

@@ -161,5 +163,5 @@ ```

# Load Time
find-up 3.948ms
escalade 0.493ms
escalade/sync 0.327ms
find-up 3.891ms
escalade 0.485ms
escalade/sync 0.309ms

@@ -173,12 +175,12 @@ # Levels: 6 (target = "foo.txt"):

# Levels: 12 (target = "package.json"):
find-up x 27,024 ops/sec ±11.20% (68 runs sampled)
escalade x 72,625 ops/sec ±5.18% (79 runs sampled)
find-up.sync x 1,644 ops/sec ±1.16% (92 runs sampled)
escalade/sync x 4,556 ops/sec ±0.57% (94 runs sampled)
find-up x 29,300 ops/sec ±10.68% (70 runs sampled)
escalade x 73,685 ops/sec ± 5.66% (66 runs sampled)
find-up.sync x 1,707 ops/sec ± 0.58% (91 runs sampled)
escalade/sync x 4,667 ops/sec ± 0.68% (94 runs sampled)
# Levels: 16 (target = "missing123.txt"):
find-up x 29,964 ops/sec ±12.71% (76 runs sampled)
escalade x 72,445 ops/sec ±25.38% (29 runs sampled)
find-up.sync x 1,087 ops/sec ±0.57% (93 runs sampled)
escalade/sync x 2,342 ops/sec ±0.51% (94 runs sampled)
# Levels: 18 (target = "missing123.txt"):
find-up x 21,818 ops/sec ±17.37% (14 runs sampled)
escalade x 67,101 ops/sec ±21.60% (20 runs sampled)
find-up.sync x 1,037 ops/sec ± 2.86% (88 runs sampled)
escalade/sync x 1,248 ops/sec ± 0.50% (93 runs sampled)
```

@@ -185,0 +187,0 @@

const { dirname, resolve } = require('path');
const { readdirSync, statSync } = require('fs');
const { homedir } = require('os');
module.exports = function (start, callback) {
let tmp, stop = homedir();
let dir = resolve('.', start);
let stats = statSync(dir);
let tmp, stats = statSync(dir);

@@ -14,7 +12,8 @@ if (!stats.isDirectory()) {

while (dir.startsWith(stop)) {
while (true) {
tmp = callback(dir, readdirSync(dir));
if (tmp) return resolve(dir, tmp);
dir = dirname(dir);
dir = dirname(tmp = dir);
if (tmp === dir) break;
}
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc