🎩 You're Invited:Meet the Socket team at Black Hat in Las Vegas, August 3-6.RSVP
Sign In

empathic

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

empathic - npm Package Compare versions

Comparing version
1.1.0
to
2.0.0-next.0
+1
-0
access.js

@@ -0,1 +1,2 @@

// re-export existsSync?
const { accessSync, constants } = require("node:fs");

@@ -2,0 +3,0 @@ /**

@@ -0,1 +1,2 @@

// re-export existsSync?
import { accessSync, constants } from "node:fs";

@@ -2,0 +3,0 @@ /**

@@ -20,1 +20,23 @@ import type { Options } from "empathic/walk";

export declare function any(names: string[], options?: Options): string | undefined;
/**
* Find a file by name, walking parent directories until found.
*
* > [NOTE]
* > This function only returns a value for file matches.
* > A directory match with the same name will be ignored.
*
* @param name The file name to find.
* @returns The absolute path to the file, if found.
*/
export declare function file(name: string, options?: Options): string | undefined;
/**
* Find a directory by name, walking parent directories until found.
*
* > [NOTE]
* > This function only returns a value for directory matches.
* > A file match with the same name will be ignored.
*
* @param name The directory name to find.
* @returns The absolute path to the file, if found.
*/
export declare function dir(name: string, options?: Options): string | undefined;
+44
-2
const { join } = require("node:path");
const { existsSync } = require("node:fs");
const { existsSync, statSync } = require("node:fs");
const walk = require("empathic/walk");

@@ -37,4 +37,46 @@ /**

}
/**
* Find a file by name, walking parent directories until found.
*
* > [NOTE]
* > This function only returns a value for file matches.
* > A directory match with the same name will be ignored.
*
* @param name The file name to find.
* @returns The absolute path to the file, if found.
*/
function file(name, options) {
let dir, tmp;
let start = options && options.cwd || "";
for (dir of walk.up(start, options)) {
try {
tmp = join(dir, name);
if (statSync(tmp).isFile()) return tmp;
} catch {}
}
}
/**
* Find a directory by name, walking parent directories until found.
*
* > [NOTE]
* > This function only returns a value for directory matches.
* > A file match with the same name will be ignored.
*
* @param name The directory name to find.
* @returns The absolute path to the file, if found.
*/
function dir(name, options) {
let dir, tmp;
let start = options && options.cwd || "";
for (dir of walk.up(start, options)) {
try {
tmp = join(dir, name);
if (statSync(tmp).isDirectory()) return tmp;
} catch {}
}
}
exports.up = up;
exports.any = any;
exports.any = any;
exports.file = file;
exports.dir = dir;
import { join } from "node:path";
import { existsSync } from "node:fs";
import { existsSync, statSync } from "node:fs";
import * as walk from "empathic/walk";

@@ -37,1 +37,41 @@ /**

}
/**
* Find a file by name, walking parent directories until found.
*
* > [NOTE]
* > This function only returns a value for file matches.
* > A directory match with the same name will be ignored.
*
* @param name The file name to find.
* @returns The absolute path to the file, if found.
*/
export function file(name, options) {
let dir, tmp;
let start = options && options.cwd || "";
for (dir of walk.up(start, options)) {
try {
tmp = join(dir, name);
if (statSync(tmp).isFile()) return tmp;
} catch {}
}
}
/**
* Find a directory by name, walking parent directories until found.
*
* > [NOTE]
* > This function only returns a value for directory matches.
* > A file match with the same name will be ignored.
*
* @param name The directory name to find.
* @returns The absolute path to the file, if found.
*/
export function dir(name, options) {
let dir, tmp;
let start = options && options.cwd || "";
for (dir of walk.up(start, options)) {
try {
tmp = join(dir, name);
if (statSync(tmp).isDirectory()) return tmp;
} catch {}
}
}
+1
-1

@@ -26,3 +26,3 @@ import * as find from "empathic/find";

export declare function cache(name: string, options?: find.Options & {
create?: boolean
create?: boolean;
}): string | undefined;

@@ -39,2 +39,4 @@ const { env } = require("node:process");

let exists = existsSync(mods);
// exit cuz exists but not writable
// or cuz missing but parent not writable
if (!writable(exists ? mods : dir)) return;

@@ -41,0 +43,0 @@ dir = join(mods, ".cache");

{
"name": "empathic",
"version": "1.1.0",
"version": "2.0.0-next.0",
"repository": "lukeed/empathic",

@@ -5,0 +5,0 @@ "description": "A set of small and fast Node.js utilities to understand your pathing needs.",

@@ -39,2 +39,4 @@ import { env } from "node:process";

let exists = existsSync(mods);
// exit cuz exists but not writable
// or cuz missing but parent not writable
if (!writable(exists ? mods : dir)) return;

@@ -41,0 +43,0 @@ dir = join(mods, ".cache");

@@ -51,3 +51,3 @@ # empathic [![CI](https://github.com/lukeed/empathic/workflows/CI/badge.svg)](https://github.com/lukeed/empathic/actions?query=workflow%3ACI) [![licenses](https://licenses.dev/b/npm/empathic)](https://licenses.dev/npm/empathic)

> [Source](/src/find.ts) · [Benchmark](/benchmarks.md#find) · **Size:** `321b`
> [Source](/src/find.ts) · [Benchmark](/benchmarks.md#find) · **Size:** `569b`

@@ -70,5 +70,5 @@ Find files and/or directories by walking up parent directories.

> [Source](/src/walk.ts) · [Benchmark](/benchmarks.md#walk) · **Size:** `218b`
> [Source](/src/walk.ts) · [Benchmark](/benchmarks.md#walk) · **Size:** `208b`
Collect all the parent directories of a target. Controlled via `cwd` and `stop` options.
Collect all the parent directories of a target. Controlled via `cwd` and `last` options.

@@ -75,0 +75,0 @@

@@ -17,2 +17,4 @@ const { createRequire } = require("node:module");

try {
// NOTE: dirs need a trailing "/" OR filename. With "/" route,
// Node adds "noop.js" as main file, so just do "noop.js" anyway.
let r = root instanceof URL || root.startsWith("file://") ? join(fileURLToPath(root), "noop.js") : join(absolute(root), "noop.js");

@@ -19,0 +21,0 @@ return createRequire(r).resolve(ident);

@@ -17,2 +17,4 @@ import { createRequire } from "node:module";

try {
// NOTE: dirs need a trailing "/" OR filename. With "/" route,
// Node adds "noop.js" as main file, so just do "noop.js" anyway.
let r = root instanceof URL || root.startsWith("file://") ? join(fileURLToPath(root), "noop.js") : join(absolute(root), "noop.js");

@@ -19,0 +21,0 @@ return createRequire(r).resolve(ident);

@@ -6,16 +6,16 @@ export type Options = {

*/
cwd?: string
cwd?: string;
/**
* The directory to stop at.
* The last directory to traverse.
*
* > [NOTE]
* > This directory WILL NOT be included in the results.
* > This directory is INCLUSIVE.
*
* @default <none> (continue to system root)
* @default "/"
*/
stop?: string
last?: string;
};
/**
* Get all parent directories of {@link base}.
* Stops at {@link Options['stop']} else system root ("/").
* Stops after {@link Options['last']} is processed.
*

@@ -22,0 +22,0 @@ * @returns An array of absolute paths of all parent directories.

@@ -5,3 +5,3 @@ const { dirname } = require("node:path");

* Get all parent directories of {@link base}.
* Stops at {@link Options['stop']} else system root ("/").
* Stops after {@link Options['last']} is processed.
*

@@ -11,7 +11,7 @@ * @returns An array of absolute paths of all parent directories.

function up(base, options) {
let { stop, cwd } = options || {};
let tmp = absolute(base, cwd), root = !stop;
let { last, cwd } = options || {};
let tmp = absolute(base, cwd);
let root = absolute(last || "/", cwd);
let prev, arr = [];
if (stop) stop = absolute(stop, cwd);
while (root || tmp !== stop) {
while (prev !== root) {
arr.push(tmp);

@@ -18,0 +18,0 @@ tmp = dirname(prev = tmp);

@@ -5,3 +5,3 @@ import { dirname } from "node:path";

* Get all parent directories of {@link base}.
* Stops at {@link Options['stop']} else system root ("/").
* Stops after {@link Options['last']} is processed.
*

@@ -11,7 +11,7 @@ * @returns An array of absolute paths of all parent directories.

export function up(base, options) {
let { stop, cwd } = options || {};
let tmp = absolute(base, cwd), root = !stop;
let { last, cwd } = options || {};
let tmp = absolute(base, cwd);
let root = absolute(last || "/", cwd);
let prev, arr = [];
if (stop) stop = absolute(stop, cwd);
while (root || tmp !== stop) {
while (prev !== root) {
arr.push(tmp);

@@ -18,0 +18,0 @@ tmp = dirname(prev = tmp);