{"name":"esm-utils","version":"0.0.2","description":"Utilities you need when migrating to ESModule.","homepage":"https://github.com/fisker/esm-utils#readme","bugs":{"url":"https://github.com/fisker/esm-utils/issues"},"repository":{"type":"git","url":"git+https://github.com/fisker/esm-utils.git"},"funding":"https://github.com/fisker/esm-utils?sponsor=1","license":"MIT","author":{"name":"fisker Cheung","email":"lionkay@gmail.com","url":"https://www.fiskercheung.com/"},"sideEffects":false,"type":"module","exports":"./index.js","scripts":{"build":"run-p build:*","build:js":"echo no need","clean":"run-p clean:*","clean:dist":"del-cli dist","dist":"run-p dist:*","dist:npm":"np --yolo --no-yarn","format":"run-p format:*","format:eslint":"yarn lint:eslint --fix","format:markdown":"yarn lint:markdown --fix","format:package-json":"sort-package-json \"package.json\" \"packages/*/package.json\"","format:prettier":"yarn lint:prettier --write","lint":"run-p lint:*","lint:eslint":"eslint \"**/*.{js,mjs,cjs,vue}\"","lint:markdown":"markdownlint \"**/*.md\" --ignore \"**/node_modules/**\"","lint:package-json":"yarn run format:package-json --check","lint:prettier":"prettier \"**/*.{css,html,js,cjs,mjs,json,less,md,scss,ts,vue,yaml,yml}\" --check","release":"run-s lint build format test dist","test":"ava","test-coverage":"nyc yarn test"},"config":{"commitizen":{"path":"./node_modules/cz-conventional-changelog"}},"ava":{"verbose":true},"nyc":{"reporter":["lcov","text"]},"devDependencies":{"@commitlint/cli":"12.1.1","@fisker/commitlint-config":"1.3.3","@fisker/eslint-config":"5.0.2","@fisker/eslint-config-ava":"2.0.2","@fisker/husky-config":"4.0.3","@fisker/lint-staged-config":"3.0.3","@fisker/prettier-config":"4.0.2","ava":"3.15.0","cz-conventional-changelog":"3.3.0","del-cli":"3.0.1","eslint":"7.24.0","husky":"6.0.0","lint-staged":"10.5.4","markdownlint-cli":"0.27.1","npm-run-all":"4.1.5","nyc":"15.1.0","prettier":"2.2.1","sort-package-json":"1.49.0"},"publishConfig":{"access":"public","registry":"https://registry.npmjs.org/"},"gitHead":"9d3650aa71e42ff7dfd4dc70b2cf73c6536f1c32","_id":"esm-utils@0.0.2","_nodeVersion":"12.22.1","_npmVersion":"7.9.0","dist":{"integrity":"sha512-YwCn3l2TiaL1gArSDortscYkMBuz3UQuJCYsA2ZW6FAvVtHLaqzHjEt3aDPJynRS2wkgnoXErWbzQv0HnNKcuA==","shasum":"9fe2aa26723751c835829b5fc716e1bbec77e439","tarball":"http://registry-npm.ywwl.com/esm-utils/download/esm-utils-0.0.2.tgz","fileCount":6,"unpackedSize":5015,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJgfT07CRA9TVsSAnZWagAAA1QP/A6QrenS7najEKSI66bP\nLdUHT+rHQqfB/u99VgmaFN/U7zAMmcjTqsLelP+sxTDeOTUsAc9LM0WLF3nd\n06jGIOxQrgKqvsivfNqG0tkp8nNUPhiFTsV71qR9TAkkXLHHjTLrCh3wI+vY\nuSsCvvhDYWxeYJr592eJaffbQrcLBrlgm7boR8YaieifrvzQUlKT8XHKHMOi\ndVjr+NqsRcPCPHBSjOXxlMaS2c0zJjbyeQrd6hIvyhT5D57m1UW0u5VPvPhp\nfn/XyF+KwYqToDGnfrwLjAUIC+/3/i9yiVf/qix9iLVhXogrTcgz9ltuM2aG\n1JzEEfKYpy36OVnpx2a/R5Dij8c4DbQaXFFDAyKckRGiH0dsEMYRHt6/pVF/\nxeJPIZzUCLfvyZS1nFOzvC3BCUzDedPM8tyyQ3Q4CRRyT3BWV0iCoCr4nrCT\nVPN512Q4tAoD73C9Qs2w6Z3evl1UragrNiPXCpf4gi8f/rQGOK0fYNvZaDqK\ngdbEw7FvIiDLQy2+yBrJyH4KgmO4VENL2kWG6KCvITou6HbIORl0wbtsGwBD\nyeaF8u2xB7tKHPEpnIiLK6u9OmXQZ5DmcxSZRzYF4zLqJ2D5+egjEd+KNMCr\nleGTWAIzOsDwXXm1dmqJWOCWK3DPr6rfcPyjgWbKka45xwPT/UOBYbDSr5Bx\n7SA6\r\n=SZLy\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDjOy8sPlmQBERIXnU/q5Oozk4VHpiPz7i0WA6+OAl+DQIgY/uvnEtLLe4sFYctgPXY0cg9+1OuOWRkoJ5ioIXI6Lc="}],"size":2321,"noattachment":false,"key":"/esm-utils/-/esm-utils-0.0.2.tgz"},"_npmUser":{"name":"fisker","email":"lionkay@gmail.com"},"directories":{},"maintainers":[{"name":"fisker","email":"lionkay@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/esm-utils_0.0.2_1618820411004_0.27694378768430483"},"_hasShrinkwrap":false,"readme":"# esm-utils\n\n[![Build Status][github_actions_badge]][github_actions_link]\n[![Coverage][coveralls_badge]][coveralls_link]\n[![Npm Version][package_version_badge]][package_link]\n[![MIT License][license_badge]][license_link]\n\n[github_actions_badge]: https://img.shields.io/github/actions/workflow/status/fisker/esm-utils/continuous-integration.yml?branch=main&style=flat-square\n[github_actions_link]: https://github.com/fisker/esm-utils/actions?query=branch%3Amain\n[coveralls_badge]: https://img.shields.io/coveralls/github/fisker/esm-utils/main?style=flat-square\n[coveralls_link]: https://coveralls.io/github/fisker/esm-utils?branch=main\n[license_badge]: https://img.shields.io/npm/l/esm-utils.svg?style=flat-square\n[license_link]: https://github.com/fisker/esm-utils/blob/main/license\n[package_version_badge]: https://img.shields.io/npm/v/esm-utils.svg?style=flat-square\n[package_link]: https://www.npmjs.com/package/esm-utils\n\n> Utilities you'll need when migrating to ESModule.\n\n## Install\n\n```bash\nyarn add esm-utils\n```\n\n## Usage\n\n<!-- prettier-ignore -->\n```js\nimport createEsmUtils from 'esm-utils'\n\nconst {\n  dirname,\n  filename,\n  require,\n  importModule,\n  resolve,\n  readJson,\n  readJsonSync,\n} = createEsmUtils(import.meta)\n```\n\n```js\n/* Those named exports only accept absolute path or URL */\nimport {\n  importModule,\n  readJson,\n  loadJson,\n  readJsonSync,\n  loadJsonSync,\n} from 'esm-utils'\n```\n\n## API\n\n### `createEsmUtils(import.meta | URL | 'string')`\n\nReturns an `object` with the following properties:\n\n- `dirname` (alias `__dirname`)\n- `filename` (alias `__filename`)\n- `require`\n- `importModule` (alias `import`)\n- `resolve`\n- `readJson` (alias `loadJson`)\n- `readJsonSync` (alias `loadJsonSync`)\n\n**Please read [this note](#you-dont-need-dirname-and-filename) before you use `dirname` and `filename`**\n\nSync version of `readJson`.\n\n### `utils.importModule(string | URL, options?)`\n\nSame as `import()`, but accepts absolute path (on Windows, `import('C:\\\\foo.js')` error throws when pass a absolute path starts with a drive letter).\n\n#### `options.traceSyntaxError`\n\ntype: `boolean`\\\ndefault: `false`\n\nDue to [this Node.js issue](https://github.com/nodejs/modules/issues/471), Node.js does not emit the location of the syntax error in the error thrown in dynamic `import()`.\n\nWhen set `traceSyntaxError: true`, we'll try to get a better error message by running `node <file>` in a child process.\n\n### `utils.readJson(string | URL)`\n\nReturns `Promise<jsonObject>`.\n\n### `utils.readJsonSync(string | URL)`\n\nSync version of `utils.readJson`\n\n### `utils.resolve(string | URL)`\n\nPonyfill for [`import.meta.resolve`](https://nodejs.org/api/esm.html#esm_import_meta_resolve_specifier_parent).\n\nIf `import.meta.resolve` exits, use it directly, otherwise returns a simple wrapper of [import-meta-resolve](https://github.com/wooorm/import-meta-resolve).\n\n## Import json file\n\nWith [`Import Assertions`](https://github.com/tc39/proposal-import-assertions)\n\n```js\nimport foo from './foo.json' assert {type: 'json'}\n```\n\n```json\nawait import('./foo.json', {assert: {type: 'json'}})\n```\n\nWith `require`, like CommonJS\n\n```js\nimport createEsmUtils from 'esm-utils'\n\nconst {require} = createEsmUtils(import.meta)\nconst foo = require('./foo.json')\n```\n\nWith `readJson` or `readJsonSync`\n\n```js\nimport createEsmUtils from 'esm-utils'\n\nconst {readJson} = createEsmUtils(import.meta)\nconst foo = await readJson('./foo.json')\n```\n\n```js\nimport createEsmUtils from 'esm-utils'\n\nconst {readJsonSync} = createEsmUtils(import.meta)\nconst foo = readJsonSync('./foo.json')\n```\n\n## `importModule()`\n\nSame as `utils.importModule()`, but only accept absolute path or URL.\n\n## `readJson()` (alias `loadJson`)\n\nSame as `utils.readJson()`, but only accept absolute path or URL.\n\n## `readJsonSync()` (alias `loadJsonSync`)\n\nSame as `utils.readJsonSync()`, but only accept absolute path or URL.\n\n## You don't need `dirname` and `filename`\n\nThe `dirname` and `filename` supposed to be a quick solution when migrating to ES Modules. In most cases, you don't need them, because many APIs accept `URL` directly.\n\n<!-- prettier-ignore -->\n```js\n/* BAD */\nimport fs from 'node:fs/promises'\nimport path from 'node:path'\nimport createEsmUtils from 'esm-utils'\n\nconst {dirname} = createEsmUtils(import.meta)\nconst buffer = await fs.readFile(\n  path.join(dirname, './path/to/file')\n)\n```\n\n<!-- prettier-ignore -->\n```js\n/* GOOD */\nimport fs from 'node:fs/promises'\n\nconst buffer = await fs.readFile(\n  new URL('./path/to/file', import.meta.url)\n)\n```\n","publish_time":1618820411209,"_cnpm_publish_time":1618820411209,"dist-tags":{"latest":"4.4.2"}}