{"name":"esm-utils","version":"2.2.0","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":"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":"c8 yarn test"},"config":{"commitizen":{"path":"./node_modules/cz-conventional-changelog"}},"ava":{"files":["!test/fixture.js"],"verbose":true},"c8":{"reporter":["lcov","text"]},"devDependencies":{"@commitlint/cli":"16.1.0","@fisker/commitlint-config":"2.0.2","@fisker/eslint-config":"10.0.12","@fisker/eslint-config-ava":"2.0.5","@fisker/husky-config":"4.1.2","@fisker/lint-staged-config":"3.1.4","@fisker/prettier-config":"5.0.5","ava":"4.0.1","c8":"7.11.0","cz-conventional-changelog":"3.3.0","del-cli":"4.0.1","eslint":"8.8.0","husky":"7.0.4","lint-staged":"12.3.3","markdownlint-cli":"0.31.1","npm-run-all":"4.1.5","prettier":"2.5.1","sort-package-json":"1.54.0"},"publishConfig":{"access":"public","registry":"https://registry.npmjs.org/"},"gitHead":"8eb33cfb0ff70293057b89f461ffb351bbf303c7","_id":"esm-utils@2.2.0","_nodeVersion":"14.18.3","_npmVersion":"7.9.0","dist":{"integrity":"sha512-kYj4yNRo4W3by0f1mj4AfRh1nsRTTpQG921Ik3AfyUq6upGlkI1fnMLypHn6XtFzZPdCYH1k9mtQA5MyZF9m+w==","shasum":"c950c0f3ea191f3830f0187f246b0cf2620c1e66","tarball":"http://registry-npm.ywwl.com/esm-utils/download/esm-utils-2.2.0.tgz","fileCount":8,"unpackedSize":11023,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJiBQumCRA9TVsSAnZWagAAawsP/1kBwE63zMJH/d6BKCYx\n/fsAEVTEh9jF5afzW3SWT9NksK3YuMdZmyxYtL0bMVkmXTYeY7ZX8dmA66z+\nSwSbNMrQctGdxK/hn8A1qwxuRokpti51VEGVq9hcnHrPzEmequEGIko0HIGe\nYhvURkpYyaqUIl7eVme6PX0CTBsP+1Q/n51ITG44VHaf+qEUW+ZSI9nVIxBG\nDKD2ja1bwJOIqmRyM8ehxAhfNeYcy5PRpcKEwDxdUes40hwBm2e+rJQiJLGS\nf5LVCrN5kIgS2CXTzRIKkZ7iW130wbVFOUdcQkztf39xAQi4Ew9cQH1Po9W6\n4SG7ug56zN4rfSCxQ2U8l6WufZEyaDg4KCCGkT9t0eNdPxWW+Yb/VE9xL2we\n9gyUCTNaBrFMzT8qqc0Y789Ueg595YYRSrmaTS1II4Yxo2KFrwlYL4ULN4RJ\ntF0bm45k4wTjQleyW6xv+oPOOZ6QYUQN2dQ90jA8lRiYUbMa+N6OMaKoHpSz\nJx5lk6McovfJ4LzSplShdtIueKZfVVJkSvF/6XPFhgmI01Ovl+pnGQU5XKuv\njFPxKRw77ZEdy3GIFX3J4JVaLdAitSTfjeeoDSkDeCy2gZBsMvG112pXCgCE\nzxenSrPUZTO/sbBaOxEgj4BlVbbg+6nsXjq1cgVEj87w8gHEx/zO54tZaTi2\nMsva\r\n=p0pL\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIC9YftbtYIW5bDEho0dULu7mryKDeP8GlHvAZ/Is4OguAiABZt6mCUJsWXeHUzs61UOKAdkzte3hyNM0SFpNjvYUQg=="}],"size":3985,"noattachment":false,"key":"/esm-utils/-/esm-utils-2.2.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_2.2.0_1644497830396_0.0077282052852210015"},"_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":1644497830525,"_cnpm_publish_time":1644497830525,"dist-tags":{"latest":"4.4.2"}}