@hugoalh/underscore-path
v2.0.2
Published
A module to bring back `__dirname` and `__filename` within 2 lines of code.
Downloads
64
Maintainers
Readme
__Path (ES)
An ES (JavaScript & TypeScript) module to bring back __dirname
and __filename
within 2 lines of code.
/* ☹️ */
import { dirname } from "node:path";
import { fileURLToPath } from "node:url";
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
/* 🙂 */
import { underscorePath } from "jsr:@hugoalh/underscore-path";
const { __dirname, __filename } = underscorePath(import.meta.url);
🎯 Target
- Bun ^ v1.0.0
- Cloudflare Workers
- Deno >= v1.34.0 / >= v1.41.1 (For JSR Only)
🛡️ Require Permission
N/A
- NodeJS >= v16.13.0
🔰 Usage
Via JSR With node_modules
🎯 Supported Target
- Bun
- Cloudflare Workers
- NodeJS
- Install via:
- Bun
bunx jsr add @hugoalh/underscore-path[@${Tag}]
- NPM
npx jsr add @hugoalh/underscore-path[@${Tag}]
- PNPM
pnpm dlx jsr add @hugoalh/underscore-path[@${Tag}]
- Yarn
yarn dlx jsr add @hugoalh/underscore-path[@${Tag}]
- Bun
- Import at the script:
import ... from "@hugoalh/underscore-path";
ℹ️ Note
- Although it is recommended to import the entire module, it is also able to import part of the module with sub path if available, please visit file
jsr.jsonc
propertyexports
for available sub paths.- It is recommended to import the module with tag for immutability.
Via JSR With Specifier
🎯 Supported Target
- Deno
- Import at the script:
import ... from "jsr:@hugoalh/underscore-path[@${Tag}]";
ℹ️ Note
- Although it is recommended to import the entire module, it is also able to import part of the module with sub path if available, please visit file
jsr.jsonc
propertyexports
for available sub paths.- It is recommended to import the module with tag for immutability.
Via NPM With node_modules
🎯 Supported Target
- Cloudflare Workers
- NodeJS
- Install via:
- NPM
npm install @hugoalh/underscore-path[@${Tag}]
- PNPM
pnpm add @hugoalh/underscore-path[@${Tag}]
- Yarn
yarn add @hugoalh/underscore-path[@${Tag}]
- NPM
- Import at the script:
import ... from "@hugoalh/underscore-path";
ℹ️ Note
- Although it is recommended to import the entire module, it is also able to import part of the module with sub path if available, please visit file
jsr.jsonc
propertyexports
for available sub paths.- It is recommended to import the module with tag for immutability.
Via NPM With Specifier
🎯 Supported Target
- Bun
- Deno
- Import at the script:
import ... from "npm:@hugoalh/underscore-path[@${Tag}]";
ℹ️ Note
- Although it is recommended to import the entire module, it is also able to import part of the module with sub path if available, please visit file
jsr.jsonc
propertyexports
for available sub paths.- It is recommended to import the module with tag for immutability.
Via Remote Import
🎯 Supported Target
- Deno
- Import at the script:
/* Via GitHub Raw (Require Tag) */ import ... from "https://raw.githubusercontent.com/hugoalh-studio/underscore-path-es/${Tag}/mod.ts";
ℹ️ Note
Although it is recommended to import the entire module with the main path
mod.ts
, it is also able to import part of the module with sub path if available, but do not import if:
- it's file path has an underscore prefix (e.g.:
_foo.ts
,_util/bar.ts
), or- it is a benchmark or test file (e.g.:
foo.bench.ts
,foo.test.ts
), or- it's symbol has an underscore prefix (e.g.:
export function _baz() {}
).These elements are not considered part of the public API, thus no stability is guaranteed for them.
Although there have 3rd party services which provide enhanced, equal, or similar methods/ways to remote import the module, beware these services maybe inject unrelated elements and thus affect the security.
🧩 API
function underscorePath(importMetaURL: string): UnderscorePathOutput;
interface UnderscorePathOutput { __dirname: string; __filename: string; }
ℹ️ Note
For the prettier documentation, can visit via: