{"name":"esm-utils","version":"1.0.0","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.4","@fisker/eslint-config":"6.0.1","@fisker/eslint-config-ava":"2.0.2","@fisker/husky-config":"4.0.4","@fisker/lint-staged-config":"3.0.4","@fisker/prettier-config":"4.0.4","ava":"3.15.0","cz-conventional-changelog":"3.3.0","del-cli":"3.0.1","eslint":"7.26.0","husky":"6.0.0","lint-staged":"11.0.0","markdownlint-cli":"0.27.1","npm-run-all":"4.1.5","nyc":"15.1.0","prettier":"2.3.0","sort-package-json":"1.50.0"},"publishConfig":{"access":"public","registry":"https://registry.npmjs.org/"},"gitHead":"449df17e03856bc0cd780816872e0dc2c251d278","_id":"esm-utils@1.0.0","_nodeVersion":"14.16.1","_npmVersion":"7.9.0","dist":{"integrity":"sha512-TTfXrUJyKVl82vNGpJq/qOtnt1HXE0mZwAd36TjZhnPkaH1g5se7B5t43NgWrz8LUTjrDeCOhM7oXKz45ZnOfg==","shasum":"77c952afde15db6e2028b492b5eb76bd8b30ff5f","tarball":"http://registry-npm.ywwl.com/esm-utils/download/esm-utils-1.0.0.tgz","fileCount":6,"unpackedSize":5689,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJgnIv8CRA9TVsSAnZWagAAtckP/2ljxl2i3eDpS+SaS0Za\nj2Hw8/NuKeXHpduz1zLJDi4j2HwPRvDDYni+L0zyHgeE/FHr2zKd+RTJzILo\n91GaWS+HQaQIoMcD1UlnaVhN9/DNzEjzPDkGEhXowsfZ70SOtcbqOPC47SOx\nDtI3iDsrTjsuTMvyUiWYwngjfFOdAJpEXw/EcTCCf0b4vAQNlTQC0aCdIeot\nPtMEbkyQo1rJ5NO69W1Wst/hckMuVyh4+ou6QUORHZ80FnqRXG5MjCwjuTS1\ngdBIDg0bCfculiGDeSXiEJd7ujSOQ6zYnACY5eh+6A0GDseCWHs9pGnekTO/\nKGBc3BQizgMlqg3h1H8ImdPWqv3xHcN1+21VViw1BZCeFkBpHGiT6hXzkh4Z\nMLh02oDLED0qMKXFyOzuWhAMw+8KElTYPGJmZ8itaiA5sF12/3UsXsm5QMkk\nAd3UVKVjL6oDbHimm5FG7spU9qtZD9uCSVtrA9eMaIAc+xsuRmtpOnmkbbG9\niGpHceHJNRTz0eC0g+XGla4CqqZqn/Zp6d35kLQLJfZrQYEyKLkToTlpOiQy\nBvxFdlKNXTaOT2poXYEIJPzKPKm+e5sifdZMdR6QgUWCjK8raxuNgTXmJOnT\npdtJTBO4FWqBb2cVMPzs3YJ6AN1u+GDqKhEzT/ODsg5Cl7SNRDTzxpXGd/YS\n/05u\r\n=Wh9T\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDl2jKcylhO0hVFOhWE5IVZYpfzy09LGVyn5Uc2/JSglQIgUpnWLtyHXoiAB3SvE/WCvwXBf/u4xOXoh6LoZN95FRI="}],"size":2494,"noattachment":false,"key":"/esm-utils/-/esm-utils-1.0.0.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_1.0.0_1620872187608_0.9060056148559885"},"_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":1620872187745,"_cnpm_publish_time":1620872187745,"dist-tags":{"latest":"4.4.2"}}