{"id":15834466,"url":"https://github.com/kaelzhang/require-esmodule","last_synced_at":"2025-07-19T23:34:40.552Z","repository":{"id":57147227,"uuid":"206910544","full_name":"kaelzhang/require-esmodule","owner":"kaelzhang","description":"require a compiled es6 module and handle exports.default ","archived":false,"fork":false,"pushed_at":"2019-09-07T04:21:01.000Z","size":5,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-07-05T09:16:33.472Z","etag":null,"topics":["es6","esmodule","require"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kaelzhang.png","metadata":{"files":{"readme":"README.md","changelog":"HISTORY.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-09-07T03:32:36.000Z","updated_at":"2019-09-07T04:21:03.000Z","dependencies_parsed_at":"2022-09-06T12:52:51.744Z","dependency_job_id":null,"html_url":"https://github.com/kaelzhang/require-esmodule","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/kaelzhang/require-esmodule","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kaelzhang%2Frequire-esmodule","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kaelzhang%2Frequire-esmodule/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kaelzhang%2Frequire-esmodule/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kaelzhang%2Frequire-esmodule/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kaelzhang","download_url":"https://codeload.github.com/kaelzhang/require-esmodule/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kaelzhang%2Frequire-esmodule/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":264650723,"owners_count":23643981,"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":["es6","esmodule","require"],"created_at":"2024-10-05T14:01:31.487Z","updated_at":"2025-07-19T23:34:40.528Z","avatar_url":"https://github.com/kaelzhang.png","language":"JavaScript","readme":"[![Build Status](https://travis-ci.org/kaelzhang/require-esmodule.svg?branch=master)](https://travis-ci.org/kaelzhang/require-esmodule)\n[![Coverage](https://codecov.io/gh/kaelzhang/require-esmodule/branch/master/graph/badge.svg)](https://codecov.io/gh/kaelzhang/require-esmodule)\n\u003c!-- optional appveyor tst\n[![Windows Build Status](https://ci.appveyor.com/api/projects/status/github/kaelzhang/require-esmodule?branch=master\u0026svg=true)](https://ci.appveyor.com/project/kaelzhang/require-esmodule)\n--\u003e\n\u003c!-- optional npm version\n[![NPM version](https://badge.fury.io/js/require-esmodule.svg)](http://badge.fury.io/js/require-esmodule)\n--\u003e\n\u003c!-- optional npm downloads\n[![npm module downloads per month](http://img.shields.io/npm/dm/require-esmodule.svg)](https://www.npmjs.org/package/require-esmodule)\n--\u003e\n\u003c!-- optional dependency status\n[![Dependency Status](https://david-dm.org/kaelzhang/require-esmodule.svg)](https://david-dm.org/kaelzhang/require-esmodule)\n--\u003e\n\n# require-esmodule\n\nrequire a compiled es6 module and handle exports.default.\n\n## Install\n\n```sh\n$ npm i require-esmodule\n```\n\n## Usage\n\n```js\n// foo.js\nObject.defineProperty(exports, '__esModule', {value: true})\n\nexports.default = {\n  foo: 'default-foo'\n}\n\nexports.foo = 'foo'\n```\n\n```js\n// bar.js\nmodule.exports = {\n  default: {\n    bar: 'default-bar'\n  },\n  bar: 'bar'\n}\n```\n\n```js\n// baz.js\nmodule.exports = null\n```\n\n```js\n// qux.js\nconst {\n  requireModule,\n  getExports\n} = require('require-esmodule')\n\nconsole.log(requireModule('/path/to/foo').foo)         // 'default-foo'\n\nconsole.log(requireModule('/path/to/foo', false).foo)  // 'foo'\n\nconsole.log(requireModule('/path/to/bar').bar)         // 'bar'\n// bar.js is not a es6 module\n\nconsole.log(requireModule('/path/to/baz'))             // null\n```\n\n## requireModule(id: string, requireDefault? : boolean = true)\n\n- **id** `string` **ABSOLUTE** path of the module\n- **requireDefault?** `boolean=true` whether should require export default. Defaults to `true`.\n\nReturns `any` the module exports\n\n### `requireDefault` as `false`\n\n```js\nconst foo = requireModule('./foo', false)\n```\n\nis equivalent to:\n\n```js\nimport * as foo from './foo'\n```\n\nwhile\n\n```js\nconst foo = requireModule('./foo')\n```\n\nis equivalent to:\n\n```js\nimport foo from './foo'\n```\n\nThe purpose of `require-esmodule` is to detect and make it easier to get the **default export**s of es modules, so the default value of `requireDefault` is set to `true`\n\n## getExports(exports: any, requireDefault?)\n\nDetect and get the **real** exports from the return value of `require(id)`\n\n## License\n\n[MIT](LICENSE)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkaelzhang%2Frequire-esmodule","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkaelzhang%2Frequire-esmodule","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkaelzhang%2Frequire-esmodule/lists"}