{"id":15118173,"url":"https://github.com/unjs/pkg-types","last_synced_at":"2025-06-10T22:41:35.401Z","repository":{"id":36951259,"uuid":"416860231","full_name":"unjs/pkg-types","owner":"unjs","description":"Node.js utilities and TypeScript definitions for package.json and tsconfig.json","archived":false,"fork":false,"pushed_at":"2025-01-09T12:45:23.000Z","size":775,"stargazers_count":253,"open_issues_count":5,"forks_count":17,"subscribers_count":7,"default_branch":"main","last_synced_at":"2025-01-10T14:12:08.227Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/unjs.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-10-13T18:44:40.000Z","updated_at":"2024-12-28T09:40:56.000Z","dependencies_parsed_at":"2024-01-22T14:11:27.968Z","dependency_job_id":"138f2e2e-8e28-49d0-8cda-e98f4cbe4b41","html_url":"https://github.com/unjs/pkg-types","commit_stats":{"total_commits":230,"total_committers":16,"mean_commits":14.375,"dds":0.4347826086956522,"last_synced_commit":"395df23d091edef8f38e7db92fa3e44445a29433"},"previous_names":[],"tags_count":27,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/unjs%2Fpkg-types","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/unjs%2Fpkg-types/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/unjs%2Fpkg-types/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/unjs%2Fpkg-types/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/unjs","download_url":"https://codeload.github.com/unjs/pkg-types/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":234358787,"owners_count":18819774,"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":[],"created_at":"2024-09-26T01:46:09.626Z","updated_at":"2025-06-10T22:41:35.389Z","avatar_url":"https://github.com/unjs.png","language":"TypeScript","readme":"# pkg-types\n\n\u003c!-- automd:badges color=yellow codecov --\u003e\n\n[![npm version](https://img.shields.io/npm/v/pkg-types?color=yellow)](https://npmjs.com/package/pkg-types)\n[![npm downloads](https://img.shields.io/npm/dm/pkg-types?color=yellow)](https://npm.chart.dev/pkg-types)\n[![codecov](https://img.shields.io/codecov/c/gh/unjs/pkg-types?color=yellow)](https://codecov.io/gh/unjs/pkg-types)\n\n\u003c!-- /automd --\u003e\n\nNode.js utilities and TypeScript definitions for `package.json` and `tsconfig.json`.\n\n## Install\n\n\u003c!-- automd:pm-i --\u003e\n\n```sh\n# ✨ Auto-detect\nnpx nypm install pkg-types\n\n# npm\nnpm install pkg-types\n\n# yarn\nyarn add pkg-types\n\n# pnpm\npnpm install pkg-types\n\n# bun\nbun install pkg-types\n\n# deno\ndeno install pkg-types\n```\n\n\u003c!-- /automd --\u003e\n\n## Usage\n\n### `readPackageJSON`\n\n```js\nimport { readPackageJSON } from \"pkg-types\";\nconst localPackageJson = await readPackageJSON();\n// or\nconst packageJson = await readPackageJSON(\"/fully/resolved/path/to/folder\");\n```\n\n### `writePackageJSON`\n\n```js\nimport { writePackageJSON } from \"pkg-types\";\n\nawait writePackageJSON(\"path/to/package.json\", pkg);\n```\n\n### `resolvePackageJSON`\n\n```js\nimport { resolvePackageJSON } from \"pkg-types\";\nconst filename = await resolvePackageJSON();\n// or\nconst packageJson = await resolvePackageJSON(\"/fully/resolved/path/to/folder\");\n```\n\n### `readTSConfig`\n\n```js\nimport { readTSConfig } from \"pkg-types\";\nconst tsconfig = await readTSConfig();\n// or\nconst tsconfig2 = await readTSConfig(\"/fully/resolved/path/to/folder\");\n```\n\n### `writeTSConfig`\n\n```js\nimport { writeTSConfig } from \"pkg-types\";\n\nawait writeTSConfig(\"path/to/tsconfig.json\", tsconfig);\n```\n\n### `resolveTSConfig`\n\n```js\nimport { resolveTSConfig } from \"pkg-types\";\nconst filename = await resolveTSConfig();\n// or\nconst tsconfig = await resolveTSConfig(\"/fully/resolved/path/to/folder\");\n```\n\n### `resolveFile`\n\n```js\nimport { resolveFile } from \"pkg-types\";\nconst filename = await resolveFile(\"README.md\", {\n  startingFrom: id,\n  rootPattern: /^node_modules$/,\n  matcher: (filename) =\u003e filename.endsWith(\".md\"),\n});\n```\n\n### `resolveLockFile`\n\nFind path to the lock file (`yarn.lock`, `package-lock.json`, `pnpm-lock.yaml`, `npm-shrinkwrap.json`, `bun.lockb`, `bun.lock`) or throws an error.\n\n```js\nimport { resolveLockFile } from \"pkg-types\";\nconst lockfile = await resolveLockFile(\".\");\n```\n\n### `findWorkspaceDir`\n\nTry to detect workspace dir by in order:\n\n1. Farthest workspace file (`pnpm-workspace.yaml`, `lerna.json`, `turbo.json`, `rush.json`)\n2. Closest `.git/config` file\n3. Farthest lockfile\n4. Farthest `package.json` file\n\nIf fails, throws an error.\n\n```js\nimport { findWorkspaceDir } from \"pkg-types\";\nconst workspaceDir = await findWorkspaceDir(\".\");\n```\n\n### `resolveGitConfig`\n\nFinds closest `.git/config` file.\n\n```js\nimport { resolveGitConfig } from \"pkg-types\";\n\nconst gitConfig = await resolveGitConfig(\".\")\n```\n\n### `readGitConfig`\n\nFinds and reads closest `.git/config` file into a JS object.\n\n```js\nimport { readGitConfig } from \"pkg-types\";\n\nconst gitConfigObj = await readGitConfig(\".\")\n```\n\n### `writeGitConfig`\n\nStringifies git config object into INI text format and writes it to a file.\n\n```js\nimport { writeGitConfig } from \"pkg-types\";\n\nawait writeGitConfig(\".git/config\", gitConfigObj)\n```\n\n### `parseGitConfig`\n\nParses a git config file in INI text format into a JavaScript object.\n\n```js\nimport { parseGitConfig } from \"pkg-types\";\n\nconst gitConfigObj = parseGitConfig(gitConfigINI)\n```\n\n### `stringifyGitConfig`\n\nStringifies a git config object into a git config file INI text format.\n\n```js\nimport { stringifyGitConfig } from \"pkg-types\";\n\nconst gitConfigINI = stringifyGitConfig(gitConfigObj)\n```\n\n## Types\n\n**Note:** In order to make types working, you need to install `typescript` as a devDependency.\n\nYou can directly use typed interfaces:\n\n```ts\nimport type { TSConfig, PackageJSON, GitConfig } from \"pkg-types\";\n```\n\nYou can also use define utils for type support for using in plain `.js` files and auto-complete in IDE.\n\n```js\nimport type { definePackageJSON } from 'pkg-types'\n\nconst pkg = definePackageJSON({})\n```\n\n```js\nimport type { defineTSConfig } from 'pkg-types'\n\nconst pkg = defineTSConfig({})\n```\n\n```js\nimport type { defineGitConfig } from 'pkg-types'\n\nconst gitConfig = defineGitConfig({})\n```\n\n## Alternatives\n\n- [dominikg/tsconfck](https://github.com/dominikg/tsconfck)\n\n## License\n\n\u003c!-- automd:contributors license=MIT author=\"pi0,danielroe\" --\u003e\n\nPublished under the [MIT](https://github.com/unjs/pkg-types/blob/main/LICENSE) license.\nMade by [@pi0](https://github.com/pi0), [@danielroe](https://github.com/danielroe) and [community](https://github.com/unjs/pkg-types/graphs/contributors) 💛\n\u003cbr\u003e\u003cbr\u003e\n\u003ca href=\"https://github.com/unjs/pkg-types/graphs/contributors\"\u003e\n\u003cimg src=\"https://contrib.rocks/image?repo=unjs/pkg-types\" /\u003e\n\u003c/a\u003e\n\n\u003c!-- /automd --\u003e\n","funding_links":[],"categories":["TypeScript","Utilities"],"sub_categories":["Data Structures"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Funjs%2Fpkg-types","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Funjs%2Fpkg-types","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Funjs%2Fpkg-types/lists"}