{"_id":"module-compat","_rev":"4-4f8809959b56ac88595eccbe22b17865","name":"module-compat","dist-tags":{"latest":"0.1.3"},"versions":{"0.1.0":{"name":"module-compat","version":"0.1.0","keywords":["module","esm","cjs","commonjs","import","require","compatibility","loader"],"author":{"url":"https://github.com/kmalakoff","name":"Kevin Malakoff","email":"kmalakoff@gmail.com"},"license":"MIT","_id":"module-compat@0.1.0","maintainers":[{"name":"kmalakoff","email":"kmalakoff@gmail.com"}],"homepage":"https://github.com/kmalakoff/module-compat","bugs":{"url":"https://github.com/kmalakoff/module-compat/issues"},"dist":{"shasum":"00bc9b1e246e42fabe3246bd542adfbe6108df56","tarball":"https://registry.npmjs.org/module-compat/-/module-compat-0.1.0.tgz","fileCount":68,"integrity":"sha512-LsKcheKcOEcyYkc/JTFval5wYSDTO+F5MX9t+1tyjHLidSgGyo/w/anUks/ix10FQwKNQ+IjV9ApEh0L7Rvk3A==","signatures":[{"sig":"MEYCIQDbqufSPlumu6xdBSk3vIZ5Av6C9qA3mHJuobxkcf6xOgIhAL96xD2wHjHgrW43qJbmEoOABE4BHOOzdYn9PIV+vrjv","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":57768},"main":"dist/cjs/index.js","type":"module","types":"dist/cjs/index.d.ts","source":"src/index.ts","engines":{"node":">=0.8"},"exports":{".":{"import":"./dist/esm/index.js","require":"./dist/cjs/index.js"},"./package.json":"./package.json"},"gitHead":"4af5b6792c1da8ac4e5fcf026894589f70661542","scripts":{"test":"tsds test:node --no-timeouts","build":"tsds build","format":"tsds format","version":"tsds version","test:engines":"nvu engines tsds test:node --no-timeouts","prepublishOnly":"tsds validate"},"_npmUser":{"name":"kmalakoff","email":"kmalakoff@gmail.com"},"repository":{"url":"git+ssh://git@github.com/kmalakoff/module-compat.git","type":"git"},"_npmVersion":"11.7.0","description":"Module type detection and loading for CJS and ESM compatibility","directories":{},"_nodeVersion":"24.12.0","dependencies":{"module-root-sync":"*"},"_hasShrinkwrap":false,"devDependencies":{"@types/node":"*","tsds-config":"*","@types/mocha":"*","ts-dev-stack":"*","node-version-use":"*"},"_npmOperationalInternal":{"tmp":"tmp/module-compat_0.1.0_1766122528058_0.48802703410899184","host":"s3://npm-registry-packages-npm-production"}},"0.1.1":{"name":"module-compat","version":"0.1.1","keywords":["module","esm","cjs","commonjs","import","require","compatibility","loader"],"author":{"url":"https://github.com/kmalakoff","name":"Kevin Malakoff","email":"kmalakoff@gmail.com"},"license":"MIT","_id":"module-compat@0.1.1","maintainers":[{"name":"kmalakoff","email":"kmalakoff@gmail.com"}],"homepage":"https://github.com/kmalakoff/module-compat","bugs":{"url":"https://github.com/kmalakoff/module-compat/issues"},"dist":{"shasum":"21f4d714b86c63ead8acfcd0c5d7eb9377d0ccab","tarball":"https://registry.npmjs.org/module-compat/-/module-compat-0.1.1.tgz","fileCount":68,"integrity":"sha512-gKf1rXe56bHXcXK6vSkhgvS5ODuqyUsJErnv35pb2CS2CRR9K2ALrp3B4Ck5Qm4SPnWlKs+VVei4Xjk/p5yPvA==","signatures":[{"sig":"MEUCIFEbBR8TRkZ4dheDBxgnGOyXg1T2VS82vAeRPihtSA5+AiEAlwpBGnWzfZCsZiRjsFnsKoYCl8hRNX4ugzRK5U6sK4o=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":58765},"main":"dist/cjs/index.js","type":"module","types":"dist/cjs/index.d.ts","source":"src/index.ts","engines":{"node":">=0.8"},"exports":{".":{"import":"./dist/esm/index.js","require":"./dist/cjs/index.js"},"./package.json":"./package.json"},"gitHead":"6a3f4823c3cdbf4d264a7f68ec4be12eca153aea","scripts":{"test":"tsds test:node --no-timeouts","build":"tsds build","format":"tsds format","version":"tsds version","test:engines":"nvu engines tsds test:node --no-timeouts","prepublishOnly":"tsds validate"},"_npmUser":{"name":"kmalakoff","email":"kmalakoff@gmail.com"},"repository":{"url":"git+ssh://git@github.com/kmalakoff/module-compat.git","type":"git"},"_npmVersion":"11.7.0","description":"Module type detection and loading for CJS and ESM compatibility","directories":{},"_nodeVersion":"24.12.0","dependencies":{"module-root-sync":"*"},"_hasShrinkwrap":false,"devDependencies":{"@types/node":"*","is-absolute":"^1.0.0","tsds-config":"*","@types/mocha":"*","ts-dev-stack":"*","node-version-use":"*"},"_npmOperationalInternal":{"tmp":"tmp/module-compat_0.1.1_1766125670205_0.28236008229055787","host":"s3://npm-registry-packages-npm-production"}},"0.1.2":{"name":"module-compat","version":"0.1.2","keywords":["module","esm","cjs","commonjs","import","require","compatibility","loader"],"author":{"url":"https://github.com/kmalakoff","name":"Kevin Malakoff","email":"kmalakoff@gmail.com"},"license":"MIT","_id":"module-compat@0.1.2","maintainers":[{"name":"kmalakoff","email":"kmalakoff@gmail.com"}],"homepage":"https://github.com/kmalakoff/module-compat","bugs":{"url":"https://github.com/kmalakoff/module-compat/issues"},"dist":{"shasum":"23def9f4b0be9740732fec3fc59f320dd71e7fdf","tarball":"https://registry.npmjs.org/module-compat/-/module-compat-0.1.2.tgz","fileCount":68,"integrity":"sha512-SoZCp5V6fsax8TR7hBHlgSEChreSg5E3qLm5Y2iaYYWwm/H+Dbn50LfAUoBoU9ocg/8kq/rPiN3joFbNHtzy/A==","signatures":[{"sig":"MEUCIQCrvS8K7lXY/UzIqx2qAnq7iX0SKgJLEj66ehbefVkpTgIgLu+ILz3hBFNF2jCqYreGMeUb48LBCMxjcvg0EtBR/DQ=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":58666},"main":"dist/cjs/index.js","type":"module","types":"dist/cjs/index.d.ts","source":"src/index.ts","engines":{"node":">=0.8"},"exports":{".":{"import":"./dist/esm/index.js","require":"./dist/cjs/index.js"},"./package.json":"./package.json"},"gitHead":"05c63f786f065a2a150bda4a2727fc38aa9d6108","scripts":{"test":"tsds test:node --no-timeouts","build":"tsds build","format":"tsds format","version":"tsds version","test:engines":"nvu engines tsds test:node --no-timeouts","prepublishOnly":"tsds validate"},"_npmUser":{"name":"kmalakoff","email":"kmalakoff@gmail.com"},"repository":{"url":"git+ssh://git@github.com/kmalakoff/module-compat.git","type":"git"},"_npmVersion":"11.19.0","description":"Module type detection and loading for CJS and ESM compatibility","directories":{},"_nodeVersion":"26.7.0","dependencies":{"module-root-sync":"*"},"_hasShrinkwrap":false,"devDependencies":{"@types/node":"*","is-absolute":"^1.0.0","tsds-config":"*","@types/mocha":"*","ts-dev-stack":"*","node-version-use":"*","@types/is-absolute":"^1.0.2"},"_npmOperationalInternal":{"tmp":"tmp/module-compat_0.1.2_1787530515053_0.6997625677643093","host":"s3://npm-registry-packages-npm-production"}},"0.1.3":{"_id":"module-compat@0.1.3","bugs":{"url":"https://github.com/kmalakoff/module-compat/issues"},"dist":{"shasum":"db25d6460f4cff95dab262296d41a056e67636cf","tarball":"https://registry.npmjs.org/module-compat/-/module-compat-0.1.3.tgz","fileCount":68,"integrity":"sha512-iKy8VbejhJRfRm3Nt30RcRL4A1LFAtFUh4kiedbTmxwFtjvVcdjNJCeRhT4Aj3d60I6TXkcs7GVSa5Hdgj6Zlg==","signatures":[{"sig":"MEYCIQDAzzlsoHB9b1JFp34SkhILr9s5a5WlorIIyYuUw24wJQIhAKgJog59FXEnk9CIEr+nsBYMViaJwwVHQN8iv+7XOo9y","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"},{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCICOsArwEpm2WIy2yb4bumD1o7+7qfqKrWrcjbojjQmLZAiEA/2SJgfVHWKntMR6JFxys5FHkRXD1A+SK4bC6bgvsHBI="}],"unpackedSize":59120},"main":"dist/cjs/index.js","name":"module-compat","type":"module","types":"dist/cjs/index.d.ts","author":{"url":"https://github.com/kmalakoff","name":"Kevin Malakoff","email":"kmalakoff@gmail.com"},"source":"src/index.ts","engines":{"node":">=0.8"},"exports":{".":{"import":"./dist/esm/index.js","require":"./dist/cjs/index.js"},"./package.json":"./package.json"},"gitHead":"8251b4670da4ea77da832178db5b92f2a99d31b8","license":"MIT","scripts":{"test":"tsds test:node --no-timeouts","build":"tsds build","format":"tsds format","version":"tsds version","test:engines":"nvu engines tsds test:node --no-timeouts","prepublishOnly":"tsds validate"},"version":"0.1.3","_npmUser":{"name":"kmalakoff","email":"kmalakoff@gmail.com"},"homepage":"https://github.com/kmalakoff/module-compat","keywords":["module","esm","cjs","commonjs","import","require","compatibility","loader"],"repository":{"url":"git+ssh://git@github.com/kmalakoff/module-compat.git","type":"git"},"_npmVersion":"12.0.2","description":"Module type detection and loading for CJS and ESM compatibility","directories":{},"maintainers":[{"name":"kmalakoff","email":"kmalakoff@gmail.com"}],"_nodeVersion":"26.7.0","dependencies":{"module-root-sync":"*"},"_hasShrinkwrap":false,"devDependencies":{"@types/node":"*","is-absolute":"^1.0.0","tsds-config":"*","@types/mocha":"*","ts-dev-stack":"*","node-version-use":"*","@types/is-absolute":"^1.0.2"},"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/module-compat_0.1.3_1789248253429_0.08053037102833072"}}},"time":{"created":"2025-12-19T05:35:28.057Z","modified":"2026-09-12T21:24:13.662Z","0.1.0":"2025-12-19T05:35:28.205Z","0.1.1":"2025-12-19T06:27:50.351Z","0.1.2":"2026-08-24T00:15:15.192Z","0.1.3":"2026-09-12T21:24:13.505Z"},"bugs":{"url":"https://github.com/kmalakoff/module-compat/issues"},"author":{"url":"https://github.com/kmalakoff","name":"Kevin Malakoff","email":"kmalakoff@gmail.com"},"license":"MIT","homepage":"https://github.com/kmalakoff/module-compat","keywords":["module","esm","cjs","commonjs","import","require","compatibility","loader"],"repository":{"url":"git+ssh://git@github.com/kmalakoff/module-compat.git","type":"git"},"description":"Module type detection and loading for CJS and ESM compatibility","maintainers":[{"name":"kmalakoff","email":"kmalakoff@gmail.com"}],"readme":"# module-compat\n\nModule type detection and loading for CJS and ESM compatibility.\n\n## Installation\n\n```bash\nnpm install module-compat\n```\n\n## API\n\n### Type Detection\n\n```typescript\nimport { moduleType, extToModuleType } from 'module-compat';\n\n// Detect from file path (checks extension + package.json)\nmoduleType('/path/to/file.js'); // 'module' | 'commonjs'\n\n// Detect from extension only (no filesystem access)\nextToModuleType('.mjs'); // 'module'\nextToModuleType('.cjs'); // 'commonjs'\nextToModuleType('.js');  // undefined (need package.json check)\n```\n\n### Capability Detection\n\n```typescript\nimport { supportsESM, supportsSyncRequireESM } from 'module-compat';\n\nsupportsESM();           // true if Node 12+\nsupportsSyncRequireESM(); // true if Node 23+\n```\n\n### Module Loading\n\n```typescript\nimport { loadModule, loadModuleSync } from 'module-compat';\n\n// Callback-based (CJS on all Node versions; ESM on Node 12+ through the ESM import entry)\nloadModule('/path/to/module.mjs', (err, mod) => {\n  if (err) throw err;\n  console.log(mod);\n});\n\n// With options\nloadModule('/path/to/module.mjs', { interop: 'raw' }, (err, mod) => {\n  // mod is the full namespace: { default, namedExport1, ... }\n});\n\n// Sync (CJS always works, ESM requires Node 23+)\nconst mod = loadModuleSync('/path/to/module.cjs');\n```\n\n### Interop Modes\n\nControl how ESM default exports are handled:\n\n| Mode | Behavior |\n|------|----------|\n| `'default'` | Extract `.default` if present (default) |\n| `'raw'` | Return module namespace as-is |\n| `'typescript'` | Check `__esModule` flag, then extract default |\n\n```typescript\n// ESM module: export default fn; export function helper() {}\n\n// interop: 'default' (default)\nloadModule('module.mjs', (err, mod) => {\n  // mod = fn (the default export)\n});\n\n// interop: 'raw'\nloadModule('module.mjs', { interop: 'raw' }, (err, mod) => {\n  // mod = { default: fn, helper: [Function] }\n});\n```\n\n## Node Version Support\n\n| Node Version | CJS files | ESM async via ESM import | ESM async via CJS require | ESM sync |\n|-------------|-----------|-------------------------|-------------------------|----------|\n| < 12 | Yes | No | No | No |\n| 12-22 | Yes | Yes | No | No |\n| 23+ | Yes | Yes | Yes | Yes |\n\nFor ESM files on Node 12-22, import `module-compat` through its ESM entry. The CommonJS entry cannot load ESM files on those versions because its dynamic import is transpiled to `require()`. CommonJS consumers need Node 23+ for ESM loading. `supportsESM()` reports whether the runtime supports ESM at all.\n","readmeFilename":"README.md"}