{"id":19453249,"url":"https://github.com/prantlf/js-main","last_synced_at":"2026-02-07T19:34:05.019Z","repository":{"id":262097300,"uuid":"886210795","full_name":"prantlf/js-main","owner":"prantlf","description":"Checks if the current module is the main executed module. Works with Bun, Deno and Node.js.","archived":false,"fork":false,"pushed_at":"2024-11-10T19:05:26.000Z","size":14,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-28T11:21:18.168Z","etag":null,"topics":["bun","deno","executable","main","node-js","nodejs"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/prantlf.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGES.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-11-10T13:48:38.000Z","updated_at":"2024-11-10T19:05:29.000Z","dependencies_parsed_at":"2024-11-10T14:38:08.587Z","dependency_job_id":"e79cf7a3-4cfe-489d-bbaa-6605ed7ce76f","html_url":"https://github.com/prantlf/js-main","commit_stats":null,"previous_names":["prantlf/js-main"],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/prantlf%2Fjs-main","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/prantlf%2Fjs-main/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/prantlf%2Fjs-main/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/prantlf%2Fjs-main/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/prantlf","download_url":"https://codeload.github.com/prantlf/js-main/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248976054,"owners_count":21192317,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bun","deno","executable","main","node-js","nodejs"],"created_at":"2024-11-10T17:03:07.469Z","updated_at":"2026-02-07T19:33:59.987Z","avatar_url":"https://github.com/prantlf.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"## js-main\n\nChecks if the current module is the main executed module.\n\n* Supports both ES and CJS modules.\n* Works with Bun, Deno and Node.js.\n* Includes TypeScript types.\n* Zero dependencies.\n* As efficient as possible depending on the completeness of `import.meta`.\n* Tiny size - 503 B original, 295 B minified, 216 B gzipped, 193 B brotlied.\n\nNode.js version 14 and newer is supported.\n\n## Synopsis\n\n### ES\n\n```js\nimport { isMain } from 'js-main'\n\nif (isMain(import.meta)) {\n  // this module has been executed\n}\n```\n\n### CJS\n\n```js\nconst { isMain } = require('js-main')\n\nif (isMain(module)) {\n  // this module has been executed\n}\n```\n\n## Installation\n\nYou can install this package using your favourite package manager:\n\n```sh\nnpm i -D js-main\nyarn add -D js-main\npnpm i -D js-main\nbun i -D js-main\n```\n\n## API\n\nThis package exports one named function:\n\n```ts\nfunction isMain(import.meta | module): boolean\n```\n\nIt expects the expression `import.meta` as the first parameter in an ES module and `module` in a CJS module. It returns a boolean, which will be `true` if the current module is the main executed module.\n\n### Importing\n\nES or CJS export will be chosen according to the `type` from `package.json` of the importing package. The ES export type can be enforced by the path suffix `/es`:\n\n```js\nimport { isMain } from 'js-main'\nimport { isMain } from 'js-main/es'\n```\n\nThe CJS export type can be enforced by the path suffix `/cjs`:\n\n```js\nconst { isMain } = require('js-main')\nconst { isMain } = require('js-main/cjs')\n```\n\n## About CJS\n\nIf you use only CJS modules, you can use the following code without depending on this or any other package:\n\n```js\nif (require.main === module) {\n  // this module has been executed\n}\n```\n\n## Contributing\n\nIn lieu of a formal styleguide, take care to maintain the existing coding style. Lint and test your code:\n\n    git clone https://github.com/prantlf/js-main.git\n    bun i --frozen-lockfile\n    bun run lint\n    bun run test\n\n## License\n\nCopyright (c) 2024 Ferdinand Prantl\n\nLicensed under the MIT license.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fprantlf%2Fjs-main","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fprantlf%2Fjs-main","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fprantlf%2Fjs-main/lists"}