{"_id":"is-file-esm","_rev":"2-021e1a38c189023db32e09634d921dea","name":"is-file-esm","dist-tags":{"latest":"1.0.0"},"versions":{"1.0.0":{"name":"is-file-esm","version":"1.0.0","description":"Determines whether a Node file is a Module (`import`) or a Script (`require`)","main":"index.js","scripts":{"test":"tap -R classic --100","ci":"npm test"},"keywords":["esm","cjs","package.json","module","ecmascript modules","native modules","native ecmascript modules"],"author":{"name":"David Mark Clements","url":"@davidmarkclem"},"license":"MIT","engineStrict":true,"engine":{"node":">= 12.4.0"},"devDependencies":{"nonsynchronous":"^1.2.0","standard":"^14.3.4","tap":"^14.10.8"},"dependencies":{"read-pkg-up":"^7.0.1"},"directories":{"test":"test"},"repository":{"type":"git","url":"git+https://github.com/davidmarkclements/is-file-esm.git"},"bugs":{"url":"https://github.com/davidmarkclements/is-file-esm/issues"},"homepage":"https://github.com/davidmarkclements/is-file-esm#readme","gitHead":"83ec13a445422820f4047801764a26f247293411","_id":"is-file-esm@1.0.0","_nodeVersion":"14.8.0","_npmVersion":"6.14.7","dist":{"integrity":"sha512-rZlaNKb4Mr8WlRu2A9XdeoKgnO5aA53XdPHgCKVyCrQ/rWi89RET1+bq37Ru46obaQXeiX4vmFIm1vks41hoSA==","shasum":"987086b0f5a5318179e9d30f4f2f8d37321e1b5f","tarball":"https://registry.npmjs.org/is-file-esm/-/is-file-esm-1.0.0.tgz","fileCount":30,"unpackedSize":33367,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJfd31iCRA9TVsSAnZWagAABagQAKQuu1SWYxVZUJFVBry2\n2K6ntF9Z0FiaufloFcj0SKfG6S2kmk2OjXzlmZv+hFxvottLC/WoUrxZZd7f\nlJNgSqtctMWw2B7cbVR1F9ZRHEgpmsjQeIQdAJYTcpeN8WB9R4JlSrQIKgiP\nXOLvxaX3N/6iHEE5RywISpinfwQXRIPJmtP9LiAFofHnxWacuAv0M0yUit+5\nWsuMe8Jdq13wZLhVYiDUDPD0pZmyX7e1/acaBc/HF8Or6+d9ZZ/o8G65K3PP\nOpH7yKYlyEzEMJuykHkbE5ofsS5dUwJRSek585yxDoQLVLjGtiVtMJqZ4Y2i\n/584UZSBcAEJqH9INs6Nc1G4H1Lv9J4BDjxvZeNw5dvXJw3gMaHzX+L20lCw\nI3CK6tv8aRQjs+aZ+xDR5WK8NXbdBx85219t3zfi7/AJF+jLj+zeBq3cAoCV\n/C+QWqSb1nWxWgOb24sIY4iG9e/YSnh+Y2bO6mDNAPbc7KsETV32AcJ5yDNT\nKNg1toX3rWxVxZ3j19WrHZp/x5xx3kt5wYyc24CyZjUN01u07iYvAU2RZ948\nDEq+HfsbggkxWrTaxSLe5CEa6pw6ouiNkkdVqLzpIMDJ09RCT1QWXOgRhOt3\nQTeSoLaPXIOK6KSRxgR+wyUqXWH7oW4wElH4yTH2kSzourP8400aFw5tIhk1\nEumH\r\n=Bqjj\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIBv9wFUALUybts4VWXYnAu5sHDB2MPNMkN5t2sjLAMwqAiAiTAcMFOeANwHWL52pULtfDkhPUkrmacPrg/rA/CtUtQ=="}]},"maintainers":[{"name":"davidmarkclements","email":"david.mark.clements@gmail.com"}],"_npmUser":{"name":"davidmarkclements","email":"david.mark.clements@gmail.com"},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/is-file-esm_1.0.0_1601666402014_0.4962500696815022"},"_hasShrinkwrap":false}},"time":{"created":"2020-10-02T19:20:02.013Z","1.0.0":"2020-10-02T19:20:02.215Z","modified":"2023-03-07T22:43:34.514Z"},"maintainers":[{"name":"davidmarkclements","email":"david.mark.clements@gmail.com"}],"description":"Determines whether a Node file is a Module (`import`) or a Script (`require`)","homepage":"https://github.com/davidmarkclements/is-file-esm#readme","keywords":["esm","cjs","package.json","module","ecmascript modules","native modules","native ecmascript modules"],"repository":{"type":"git","url":"git+https://github.com/davidmarkclements/is-file-esm.git"},"author":{"name":"David Mark Clements","url":"@davidmarkclem"},"bugs":{"url":"https://github.com/davidmarkclements/is-file-esm/issues"},"license":"MIT","readme":"# is-file-esm\n\n> Determines whether a Node file is a Module (`import`) or a Script (`require`)\n\n## Algorithm\n\nDetermining the module system of a file comes from three inputs, the `type` field \nof the closest `package.json` to that file, the file extension (`.js`, `.mjs` or `.cjs`)\nand the lesser know `--input-type` command-line flag. The latter only applies to \ndyamic input (via STDIN, `--eval` or `--print` flags) so is not considered with this library.\n\nSo to determine whether a file is an esm file (e.g. native EcmaScript modules) or not,\nwe use the following procedure:\n\n```\nread package.json for \"type\" field,\n  if type is \"module\"\n    if answer.mjs -> module \n    if answer.js -> module\n    if answer.cjs -> script\n  if type is \"commonjs\"\n    if answer.mjs -> module   \n    if answer.js -> script\n    if answer.cjs -> script\n  if type is not set\n    if answer.mjs -> module\n    if answer.js -> script\n    if answer.cjs -> script\n```\n\n## API\n\nThe `is-file-esm` module provides synchronous, awaitable (promise-based) and callback based APIs. \n\nIn each case the Result object has the following shape: \n\n```js\n{\n  esm: Boolean, // true if file is a Module, false if it is a Script\n  type: String,  // the determined package.json type, may be undefined, 'module', or 'commonjs'\n  extType: String, // the file extension type, may be 'c', 'm' or 'j'\n  path: String,  // the input path\n  pkgPath: String // the path to the package.json from which the type was determined\n}\n```\n\n### Awaitable (promise-based)\n\n#### `await isFileEsm(path) => Result`\n\n```js\n  import isFileEsm from 'is-file-esm'\n  const { esm, path } = await isFileEsm('/path/to/file.js')\n  if (esm) console.log(`File ${path} is a Module`)\n  else console.log(`File ${path} is a Script`)\n```\n\n### Callback-style\n\n#### `isFileEsm(path, cb(err, Result))`\n\n```js\n  const isFileEsm = require('is-file-esm')\n  isFileEsm('/path/to/file.js', (err,  result) => {\n    if (err) {\n      console.error(err)\n      return\n    }\n    if (result.esm) console.log(`File ${result.path} is a Module`)\n    else console.log(`File ${result.path} is a Script`)\n  })\n```\n\n### Synchronous\n\n#### `isFileEsm.sync(path) => Result`\n\n```js\n  import isFileEsm from 'is-file-esm'\n  const { esm, path } = isFileEsm.sync('/path/to/file.js')\n  if (esm) console.log(`File ${path} is a Module`)\n  else console.log(`File ${path} is a Script`)\n```\n\n### Test\n\n```sh\nnpm test\n```\n\n```\ntest/index.js ..................................... 213/213\ntotal ............................................. 213/213\n\n  213 passing (927.584ms)\n\n  ok\n----------|----------|----------|----------|----------|-------------------|\nFile      |  % Stmts | % Branch |  % Funcs |  % Lines | Uncovered Line #s |\n----------|----------|----------|----------|----------|-------------------|\nAll files |      100 |      100 |      100 |      100 |                   |\n index.js |      100 |      100 |      100 |      100 |                   |\n----------|----------|----------|----------|----------|-------------------|\n```\n\n### License\n\nMIT","readmeFilename":"readme.md","users":{"flumpus-dev":true}}