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.
- Host: GitHub
- URL: https://github.com/hugoalh-studio/underscore-path-js
- Owner: hugoalh-studio
- License: other
- Created: 2023-06-13T06:57:49.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2024-03-29T07:35:13.000Z (over 2 years ago)
- Last Synced: 2024-03-29T08:36:45.179Z (over 2 years ago)
- Topics: dirname, filename, javascript, js
- Language: TypeScript
- Homepage:
- Size: 367 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Contributing: .github/CONTRIBUTING.md
- License: LICENSE.md
- Code of conduct: .github/CODE_OF_CONDUCT.md
- Citation: CITATION.cff
- Codeowners: .github/CODEOWNERS
- Security: SECURITY.md
Awesome Lists containing this project
README
# __Path (JavaScript)
[**âī¸** MIT](./LICENSE.md)
**đī¸**
[](https://github.com/hugoalh-studio/underscore-path-js)
[](https://www.npmjs.com/package/@hugoalh/underscore-path)
**đ**  ()
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;
}
```