{"name":"esm-utils","version":"3.1.1","description":"Utilities you'll 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","typings":"./index.d.ts","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":"markdownlint-cli2-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,jsx,mjs,cjs,vue}\"","lint:markdown":"markdownlint-cli2","lint:package-json":"yarn run format:package-json --check","lint:prettier":"prettier . --check","prepare":"husky install","release":"run-s lint build format test dist","test":"ava","test-coverage":"c8 yarn test"},"ava":{"files":["!test/fixture.js"],"verbose":true},"c8":{"reporter":["lcov","text"]},"dependencies":{"url-or-path":"2.1.0"},"devDependencies":{"@fisker/eslint-config":"10.1.4","@fisker/eslint-config-ava":"2.0.5","@fisker/husky-config":"4.1.2","@fisker/lint-staged-config":"3.1.5","@fisker/markdownlint-cli2-config":"0.0.3","@fisker/prettier-config":"5.0.6","ava":"4.2.0","c8":"7.11.2","cz-conventional-changelog":"3.3.0","del-cli":"4.0.1","eslint":"8.14.0","husky":"7.0.4","lint-staged":"12.4.1","markdownlint-cli2":"0.4.0","npm-run-all":"4.1.5","prettier":"2.6.2","sort-package-json":"1.55.0"},"packageManager":"yarn@3.2.0","publishConfig":{"access":"public","registry":"https://registry.npmjs.org/"},"gitHead":"03766bd03a9802a5429b86265c5ec5d81790655f","_id":"esm-utils@3.1.1","_nodeVersion":"12.22.12","_npmVersion":"7.9.0","dist":{"integrity":"sha512-NytBLB+N+Y9JNzGilK2WANaEUo3iqxAfhgC5A63m1L7HOzXJ+hr2OePb/Fw2RR/ywunbs7Ewbi+W0d94R+8Uhw==","shasum":"5c9a17bb4239fb1a29cd578c56db37c12170ecd7","tarball":"http://registry-npm.ywwl.com/esm-utils/download/esm-utils-3.1.1.tgz","fileCount":8,"unpackedSize":13067,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIEBL06935rEWnhvvch6dtrkBN4nlns4p+YHo0GgRgmp8AiAPxPtJzjNymYfK45siFIc301K/fJDYx/n1dT2LMg+kCA=="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJia8nMACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmrlDQ//TUjQxC04EeywjAtXqijJbCfibEE0Sw4YHjOxYBWTeAqew0fH\r\nfG1VR64V7qaJuIPqA3k0ERc48swoD46oiuJl7VyuERWGrr+1TsxOg4l2GrpN\r\n9Qvyh5mlfSyy07G9EAY50vZ5k9z4V/b+C34nBm1icMnH2f+PUS5pXp0iSE1F\r\nkbw5hqHpniWySxFLUJftB0zYRFKCLxTRNDRelBByz/mZhWOg1Xvbcnyo/SHg\r\n0BPJ4Fhccb6Hkubrw7uUBagzFoGEbcWODtA53ib8zpuGp/QPry4EwjRuHfgR\r\nlqTwGoqXwTbenjmDFit5GVRqundMz1GLJRnLmbFR0mo/E9JVBDlcGcfxz+uc\r\nTeCBXJdY04R9VwIGFx/u+u4dEHPb47gOMEmB2k6Eqs4bs6pmzKrpX9DfZ/ko\r\n7msOj4Ejm/uRrj3JYwkdWBNGhBtjxDbBy+KSYLZT+dBJh1V62BzE+3x3LdMt\r\ny1I5ztg+WN+NWt+25ehE5gfIq6ypbEngG0qQFEDsExoM+6vJ75Rc7wvUFzem\r\nCID5jzN0Pm8mBX2jOM+f35STghoRmFw8VFu+KVxMWLVO69Ml0lnSxM2ZucPe\r\nQEzyYBqDj7litNmFF/H7A7rkPHBGbN/nF4h0HPpBFa43Fo5omAxwoiLKnBm2\r\nfJI6BXCVXvrVSMX4t94bJOxC9YEYs3eV7pM=\r\n=Hu8u\r\n-----END PGP SIGNATURE-----\r\n","size":4783,"noattachment":false,"key":"/esm-utils/-/esm-utils-3.1.1.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_3.1.1_1651231180140_0.9264437108772889"},"_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":1651231180280,"_cnpm_publish_time":1651231180280,"dist-tags":{"latest":"4.4.2"}}