dirplus
v0.0.3
Published
Lightweight ESM-only utility for resolving absolute paths in Node.js.
Maintainers
Readme
Dirplus
Lightweight ESM-only utilities for resolving absolute paths in Node.js.
dirplus gives you two tiny helpers to handle paths safely:
dirname(meta, ...paths)→ resolve paths relative to the script file (ESM-friendly__dirname)cwd(...paths)→ resolve paths relative to where Node.js was executed
Features ✨
- 🔹 Simple API – One-call path resolution.
- 🌐 ESM-only – Built for modern Node.js.
- ⚡ Zero dependencies – Tiny, fast, reliable.
- 🔄 Flexible – Combine multiple path segments.
Installation 💿
# npm
npm install dirplus
# pnpm
pnpm add dirplus
# yarn
yarn add dirplusUsage 📦
import { dirname, cwd } from 'dirplus';
// dirname → relative to the script
console.log(dirname(import.meta));
// => /absolute/path/to/script
console.log(dirname(import.meta, 'data', 'file.json'));
// => /absolute/path/to/script/data/file.json
// cwd → relative to where Node was started
console.log(cwd());
// => /absolute/path/where/node/was/run
console.log(cwd('data', 'file.json'));
// => /absolute/path/where/node/was/run/data/file.jsonAPI
dirname(meta: ImportMeta, ...paths: string[]): stringResolves paths relative to the script's directory. You must passimport.metaas the first argument.cwd(...paths: string[]): stringResolves paths relative to the current working directory.
License 📄
MIT – see LICENSE.
Author: Estarlin R · estarlincito.com
