Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/sant123/cjs
A Deno implementation to create variables like __dirname and __filename of Node.js
https://github.com/sant123/cjs
commonjs commonjs-deno deno dirname filename
Last synced: about 1 month ago
JSON representation
A Deno implementation to create variables like __dirname and __filename of Node.js
- Host: GitHub
- URL: https://github.com/sant123/cjs
- Owner: sant123
- License: mit
- Created: 2020-12-22T23:30:30.000Z (almost 4 years ago)
- Default Branch: master
- Last Pushed: 2022-07-21T06:57:58.000Z (over 2 years ago)
- Last Synced: 2024-04-14T10:16:07.400Z (7 months ago)
- Topics: commonjs, commonjs-deno, deno, dirname, filename
- Language: TypeScript
- Homepage:
- Size: 217 KB
- Stars: 12
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# cjs [![Deno](https://github.com/sant123/cjs/actions/workflows/deno.yml/badge.svg)](https://github.com/sant123/cjs/actions/workflows/deno.yml)
Create variables like `__dirname` and `__filename` in Deno. Their behavior is
the same as Node.js variables.## Usage
```ts
// example.ts
import { getDirname, getFilename } from "https://deno.land/x/cjs/mod.ts";const __dirname = getDirname(import.meta.url);
const __filename = getFilename(import.meta.url);// Your code here...
```## API
### getDirname(importMetaUrl: string): string
Returns the directory of the current module.
### getFilename(importMetaUrl: string): string
Returns the filename of the current module.
## Node.js support
This should work with the
[stable](https://nodejs.org/dist/latest-v15.x/docs/api/esm.html#esm_modules_ecmascript_modules)
Ecmascript modules implementation of Node.js. See this
[link](https://nodejs.org/dist/latest-v15.x/docs/api/esm.html#esm_no_filename_or_dirname)
for more information.## Testing
This library is highly tested to provide the same variables behavior of Node.js.
If you see something is missing or ¿did you find a bug? pull requests are really
welcome.## Benchmark
Tested with Deno v1.24.0:
![](benchmark/get_dirname.png)