{"id":13526874,"url":"https://github.com/npm/read-package-json-fast","last_synced_at":"2025-05-15T17:07:00.860Z","repository":{"id":46901354,"uuid":"223506953","full_name":"npm/read-package-json-fast","owner":"npm","description":"Like read-package-json, but faster","archived":false,"fork":false,"pushed_at":"2025-04-28T18:57:34.000Z","size":243,"stargazers_count":49,"open_issues_count":0,"forks_count":6,"subscribers_count":6,"default_branch":"main","last_synced_at":"2025-05-03T01:53:48.972Z","etag":null,"topics":["npm-cli"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"isc","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/npm.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2019-11-23T00:13:36.000Z","updated_at":"2025-04-28T18:57:36.000Z","dependencies_parsed_at":"2024-04-20T22:57:03.260Z","dependency_job_id":"8207812d-a0f0-480e-a0ea-1e4603608cba","html_url":"https://github.com/npm/read-package-json-fast","commit_stats":{"total_commits":104,"total_committers":8,"mean_commits":13.0,"dds":0.6538461538461539,"last_synced_commit":"6ab7f8d2cf76aad58022bd4d97a67e7abebcf006"},"previous_names":[],"tags_count":18,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/npm%2Fread-package-json-fast","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/npm%2Fread-package-json-fast/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/npm%2Fread-package-json-fast/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/npm%2Fread-package-json-fast/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/npm","download_url":"https://codeload.github.com/npm/read-package-json-fast/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254043219,"owners_count":22004912,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["npm-cli"],"created_at":"2024-08-01T06:01:36.510Z","updated_at":"2025-05-15T17:06:55.845Z","avatar_url":"https://github.com/npm.png","language":"JavaScript","readme":"# read-package-json-fast\n\nLike [`read-package-json`](http://npm.im/read-package-json), but faster and\nmore accepting of \"missing\" data.\n\nThis is only suitable for reading package.json files in a node_modules\ntree, since it doesn't do the various cleanups, normalization, and warnings\nthat are beneficial at the root level in a package being published.\n\n## USAGE\n\n```js\nconst rpj = require('read-package-json-fast')\n\n// typical promisey type API\nrpj('/path/to/package.json')\n  .then(data =\u003e ...)\n  .catch(er =\u003e ...)\n\n// or just normalize a package manifest\nconst normalized = rpj.normalize(packageJsonObject)\n```\n\nErrors raised from parsing will use\n[`json-parse-even-better-errors`](http://npm.im/json-parse-even-better-errors),\nso they'll be of type `JSONParseError` and have a `code: 'EJSONPARSE'`\nproperty.  Errors will also always have a `path` member referring to the\npath originally passed into the function.\n\n## Indentation\n\nTo preserve indentation when the file is saved back to disk, use\n`data[Symbol.for('indent')]` as the third argument to `JSON.stringify`, and\nif you want to preserve windows `\\r\\n` newlines, replace the `\\n` chars in\nthe string with `data[Symbol.for('newline')]`.\n\nFor example:\n\n```js\nconst data = await readPackageJsonFast('./package.json')\nconst indent = Symbol.for('indent')\nconst newline = Symbol.for('newline')\n// .. do some stuff to the data ..\nconst string = JSON.stringify(data, null, data[indent]) + '\\n'\nconst eolFixed = data[newline] === '\\n' ? string\n  : string.replace(/\\n/g, data[newline])\nawait writeFile('./package.json', eolFixed)\n```\n\nIndentation is determined by looking at the whitespace between the initial\n`{` and the first `\"` that follows it.  If you have lots of weird\ninconsistent indentation, then it won't track that or give you any way to\npreserve it.  Whether this is a bug or a feature is debatable ;)\n\n## WHAT THIS MODULE DOES\n\n- Parse JSON\n- Normalize `bundledDependencies`/`bundleDependencies` naming to just\n  `bundleDependencies` (without the extra `d`)\n- Handle `true`, `false`, or object values passed to `bundleDependencies`\n- Normalize `funding: \u003cstring\u003e` to `funding: { url: \u003cstring\u003e }`\n- Remove any `scripts` members that are not a string value.\n- Normalize a string `bin` member to `{ [name]: bin }`.\n- Fold `optionalDependencies` into `dependencies`.\n- Set the `_id` property if name and version are set.  (This is\n  load-bearing in a few places within the npm CLI.)\n\n## WHAT THIS MODULE DOES NOT DO\n\n- Warn about invalid/missing name, version, repository, etc.\n- Extract a description from the `README.md` file, or attach the readme to\n  the parsed data object.\n- Read the `HEAD` value out of the `.git` folder.\n- Warn about potentially typo'ed scripts (eg, `tset` instead of `test`)\n- Check to make sure that all the files in the `files` field exist and are\n  valid files.\n- Fix bundleDependencies that are not listed in `dependencies`.\n- Fix `dependencies` fields that are not strictly objects of string values.\n- Anything involving the `directories` field (ie, bins, mans, and so on).\n","funding_links":[],"categories":["Repository"],"sub_categories":["NPM"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnpm%2Fread-package-json-fast","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnpm%2Fread-package-json-fast","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnpm%2Fread-package-json-fast/lists"}