Package Exports
- filedirname
Readme
filedirname
Fetch the current file and directory path, no matter your environment (Deno, Node.js, Web Browsers, ESM, CJS)
Usage
Without Arguments
The following works for ESM (ECMAScript Modules) and CJS (CommonJS Modules) enviroments:
// for deno
import filedirname from 'https://unpkg.com/filedirname/edition-deno/index.ts'
// for web browsers
import filedirname from 'https://unpkg.com/filedirname'
// for node.js
import filedirname from 'filedirname'
// for commonjs
const filedirname = require('filedirname').default
// usage
const [__filename, __dirname] = filedirname()
console.log({ __filename, __dirname })
Via Error
The following works for ESM (ECMAScript Modules) and CJS (CommonJS Modules) environments:
// for deno
import filedirname from 'https://unpkg.com/filedirname/edition-deno/index.ts'
// for web browsers
import filedirname from 'https://unpkg.com/filedirname'
// for node.js
import filedirname from 'filedirname'
// for commonjs
const filedirname = require('filedirname').default
// usage
const [__filename, __dirname] = filedirname(new Error())
console.log({ __filename, __dirname })
Via import.meta.url
The following works only for ESM (ECMAScript Modules) environments and is the quickest solution:
// for deno
import filedirname from 'https://unpkg.com/filedirname/edition-deno/index.ts'
// for web browsers
import filedirname from 'https://unpkg.com/filedirname'
// for node.js
import filedirname from 'filedirname'
// usage
const [__filename, __dirname] = filedirname(import.meta.url)
console.log({ __filename, __dirname })
Install
- Install:
npm install --save filedirname
- Import:
import pkg from ('filedirname')
- Require:
const pkg = require('filedirname').default
Editions
This package is published with the following editions:
filedirname/source/index.ts
is TypeScript source code with Import for modulesfiledirname
aliasesfiledirname/edition-es2019/index.js
filedirname/edition-es2019/index.js
is TypeScript compiled against ES2019 for Node.js 10 || 12 || 14 || 16 with Require for modulesfiledirname/edition-es2019-esm/index.js
is TypeScript compiled against ES2019 for Node.js 12 || 14 || 16 with Import for modules
History
Discover the release history by heading on over to the HISTORY.md
file.
Contribute
Discover how you can contribute by heading on over to the CONTRIBUTING.md
file.
Backers
Maintainers
These amazing people are maintaining this project:
Sponsors
No sponsors yet! Will you be the first?
Contributors
These amazing people have contributed code to this project:
Discover how you can contribute by heading on over to the CONTRIBUTING.md
file.
License
Unless stated otherwise all works are:
- Copyright © 2020+ Benjamin Lupton
and licensed under: