An open API service indexing awesome lists of open source software.

https://github.com/hugoalh-studio/underscore-path-js

A JavaScript module to bring back `__dirname` and `__filename` within 2 lines of code.
https://github.com/hugoalh-studio/underscore-path-js

dirname filename javascript js

Last synced: about 1 year ago
JSON representation

A JavaScript module to bring back `__dirname` and `__filename` within 2 lines of code.

Awesome Lists containing this project

README

          

# __Path (JavaScript)

[**âš–ī¸** MIT](./LICENSE.md)

**đŸ—‚ī¸**
[![GitHub: hugoalh-studio/underscore-path-js](https://img.shields.io/badge/hugoalh--studio/underscore--path--js-181717?logo=github&logoColor=ffffff&style=flat "GitHub: hugoalh-studio/underscore-path-js")](https://github.com/hugoalh-studio/underscore-path-js)
[![NPM: @hugoalh/underscore-path](https://img.shields.io/badge/@hugoalh/underscore--path-CB3837?logo=npm&logoColor=ffffff&style=flat "NPM: @hugoalh/underscore-path")](https://www.npmjs.com/package/@hugoalh/underscore-path)

**🆙** ![Latest Release Version](https://img.shields.io/github/release/hugoalh-studio/underscore-path-js?sort=semver&color=2187C0&label=&style=flat "Latest Release Version") (![Latest Release Date](https://img.shields.io/github/release-date/hugoalh-studio/underscore-path-js?color=2187C0&label=&style=flat "Latest Release Date"))

A JavaScript module to bring back `__dirname` and `__filename` within 2 lines of code.

```js
/* â˜šī¸ */
import { dirname } from "node:path";
import { fileURLToPath } from "node:url";
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
```

```js
/* 🙂 */
import { underscorePath } from "@hugoalh/underscore-path";
const { __dirname, __filename } = underscorePath(import.meta.url);
```

## đŸŽ¯ Target

- Bun ^ v1.0.0
- Cloudflare Workers
- Deno >= v1.34.0
> **đŸ›Ąī¸ Require Permission**
>
> *N/A*
- NodeJS >= v16.13.0

## 🔰 Usage

### Via Installation

> **đŸŽ¯ Supported Target**
>
> - Cloudflare Workers
> - NodeJS

1. Install via console/shell/terminal:
- Via NPM
```sh
npm install @hugoalh/underscore-path[@]
```
- Via PNPM
```sh
pnpm add @hugoalh/underscore-path[@]
```
- Via Yarn
```sh
yarn add @hugoalh/underscore-path[@]
```
2. Import at the script (`.js`):
```js
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 `package.json`](./package.json) property `exports` for available sub paths.

### Via NPM Specifier

> **đŸŽ¯ Supported Target**
>
> - Bun
> - Deno

1. Import at the script (`.js`):
```js
import ... from "npm:@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 `package.json`](./package.json) property `exports` for available sub paths.

## 🧩 API

- ```ts
function underscorePath(importMetaURL: string): UnderscorePathOutput;
```
- ```ts
interface UnderscorePathOutput {
__dirname: string;
__filename: string;
}
```