Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ratson/is-main
Check if current module is main module.
https://github.com/ratson/is-main
esm esmodules main main-module require-main
Last synced: about 1 month ago
JSON representation
Check if current module is main module.
- Host: GitHub
- URL: https://github.com/ratson/is-main
- Owner: ratson
- Created: 2018-04-09T15:41:51.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2023-01-30T18:17:16.000Z (almost 2 years ago)
- Last Synced: 2024-11-29T12:24:11.040Z (about 1 month ago)
- Topics: esm, esmodules, main, main-module, require-main
- Language: TypeScript
- Size: 26.4 KB
- Stars: 4
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# is-main
Check if current module is main module.
## Installation
```
npm install is-main --save
```## Usage
```js
import { isMain } from 'is-main'if (isMain(import.meta)) {
console.log('is main')
}
``````js
const { isMain } = require('is-main')if (isMain(module)) {
console.log('is main')
}
```## Note
While it is useful to put main script with the module code in the same file,
move main script into a separate file is often better,
given there is no standard way for detecting main script.See this [Node issue](https://github.com/nodejs/node/issues/15760) for more information.
## Related
- [esmeta](https://github.com/ratson/esmeta) - Handy function to handle import.meta