https://github.com/xinchou16/emeta
A micro esm meta helper for import.meta data.
https://github.com/xinchou16/emeta
cjs dirname esm filename import meta url
Last synced: 3 months ago
JSON representation
A micro esm meta helper for import.meta data.
- Host: GitHub
- URL: https://github.com/xinchou16/emeta
- Owner: XinChou16
- License: mit
- Created: 2024-06-16T14:03:23.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2024-06-16T14:15:10.000Z (about 2 years ago)
- Last Synced: 2025-02-10T21:36:55.467Z (over 1 year ago)
- Topics: cjs, dirname, esm, filename, import, meta, url
- Language: JavaScript
- Homepage:
- Size: 1.95 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# emeta
A micro esm meta helper for `import.meta` data.
Requires Node 12.17.0 or Node 14.0.0.
Starting in [Node 20.11.0](https://github.com/nodejs/node/blob/main/doc/changelogs/CHANGELOG_V20.md#20.11.0) and [Node 21.2.0](https://github.com/nodejs/node/blob/main/doc/changelogs/CHANGELOG_V21.md#21.2.0) this is now built in: [`import.meta.dirname`](https://nodejs.org/api/esm.html#importmetadirname) / [`import.meta.filename`](https://nodejs.org/api/esm.html#importmetafilename)
## Install
```
npm install emeta
```
## Usage
```js
import emeta from 'emeta'
const meta = emeta(import.meta)
console.log(meta.filename)
```
or
```js
import emeta from 'emeta'
const { dirname, filename, join, require } = emeta(import.meta)
// OR
const meta = emeta(import.meta)
// same as CommonJS __dirname
console.log(meta.dirname)
// same as CommonJS __filename
console.log(meta.filename)
// same as CommonJS path.join(__dirname, 'pages')
console.log(join(import.meta.url, 'pages'))
// same as CommonJS path.join(__dirname, '..', 'pages')
console.log(join(import.meta.url, '..', 'pages'))
// same as CommonJS require
console.log(require('lodash'))
console.log(require.resolve('lodash'))
```
## License
MIT