+76
| # empathic [](https://github.com/lukeed/empathic/actions?query=workflow%3ACI) [](https://licenses.dev/npm/empathic) | ||
| > A set of small and [fast](/benchmarks.md) Node.js utilities to understand your pathing needs. | ||
| Multiple submodules (eg, `empathic/find`) are offered, _each of which_ are: | ||
| * **fast** — 8x to 40x faster than popular alternatives | ||
| * **modern** — based on of newer `node:*` native APIs | ||
| * **small** — ranging from 200b to 500b in size | ||
| * **safe** — zero-dependency & easy to read | ||
| ## Install | ||
| ```sh | ||
| $ npm install empathic | ||
| ``` | ||
| ## Usage | ||
| ```ts | ||
| import { resolve } from 'node:path'; | ||
| import * as find from 'empathic/find'; | ||
| import * as pkg from 'empathic/package'; | ||
| // Assumed example structure: | ||
| let cwd = resolve('path/to/acme/websites/dashboard'); | ||
| // Find closest "foobar.config.js" file | ||
| let file = find.up('foobar.config.js', { cwd }); | ||
| //=> "/.../path/to/acme/foobar.config.js" | ||
| // Find closest "package.json" file | ||
| let pkgfile = pkg.up({ cwd }); | ||
| //=> "/.../path/to/acme/package.json" | ||
| // Construct (optionally create) "foobar" cache dir | ||
| let cache = pkg.cache('foobar', { cwd, create: true }); | ||
| //=> "/.../path/to/acme/node_modules/.cache/foobar" | ||
| ``` | ||
| ## API | ||
| ### `empathic/access` | ||
| > [Source](/src/access.ts) · **Size:** `259b` | ||
| Check for file access/permissions. Named [`fs.accessSync`](https://nodejs.org/docs/latest/api/fs.html#fsaccesssyncpath-mode) shortcuts. | ||
| ### `empathic/find` | ||
| > [Source](/main/src/find.ts) · [Benchmark](/benchmarks.md#find) · **Size:** `321b` | ||
| Find files and/or directories by walking up parent directories. | ||
| ### `empathic/package` | ||
| > [Source](/src/package.ts) · [Benchmark](/benchmarks.md#package) · **Size:** `505b` | ||
| Convenience helpers for dealing with `package.json` files and/or `node_modules` packages. | ||
| ### `empathic/resolve` | ||
| > [Source](/src/resolve.ts) · [Benchmark](/benchmarks.md#resolve) · **Size:** `419b` | ||
| Resolve absolute paths to package identifiers, relative paths, file URL, and/or from other root directories. | ||
| ### `empathic/walk` | ||
| > [Source](/src/walk.ts) · [Benchmark](/benchmarks.md#walk) · **Size:** `218b` | ||
| Collect all the parent directories of a target. Controlled via `cwd` and `stop` options. | ||
| ## License | ||
| MIT © [Luke Edwards](https://lukeed.com) |
+2
-2
| { | ||
| "name": "empathic", | ||
| "version": "0.0.1", | ||
| "version": "0.0.2", | ||
| "repository": "lukeed/empathic", | ||
| "description": "A set of small Node.js utilities to understand your pathing needs.", | ||
| "description": "A set of small and fast Node.js utilities to understand your pathing needs.", | ||
| "license": "MIT", | ||
@@ -7,0 +7,0 @@ "author": { |
+1
-1
| export type Options = { | ||
| cwd?: string; | ||
| limit?: string; | ||
| stop?: string; | ||
| }; | ||
| export declare function up(base: string, options?: Options): string[]; |
+6
-5
| import { dirname } from "node:path"; | ||
| import { absolute } from "empathic/resolve"; | ||
| export function up(base, options) { | ||
| let { limit, cwd } = options || {}; | ||
| let tmp = absolute(base, cwd); | ||
| let { stop, cwd } = options || {}; | ||
| let tmp = absolute(base, cwd), root = !stop; | ||
| let prev, arr = []; | ||
| if (limit) limit = absolute(limit, cwd); | ||
| while (true) { | ||
| if (stop) stop = absolute(stop, cwd); | ||
| while (root || tmp !== stop) { | ||
| arr.push(tmp); | ||
| tmp = dirname(prev = tmp); | ||
| if (tmp === (limit || prev)) return arr; | ||
| if (tmp === prev) break; | ||
| } | ||
| return arr; | ||
| } |
No README
QualityPackage does not have a README. This may indicate a failed publish or a low quality package.
8411
39.35%13
8.33%98
1.03%0
-100%77
Infinity%