https://github.com/radarsu/types-package-json
A handful set of package.json types and interfaces to improve working with dynamically imported package.json files.
https://github.com/radarsu/types-package-json
dynamic import interface json package-json types
Last synced: about 2 months ago
JSON representation
A handful set of package.json types and interfaces to improve working with dynamically imported package.json files.
- Host: GitHub
- URL: https://github.com/radarsu/types-package-json
- Owner: radarsu
- Created: 2020-07-06T13:48:48.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2022-05-28T13:21:32.000Z (over 3 years ago)
- Last Synced: 2024-09-20T01:48:17.609Z (about 1 year ago)
- Topics: dynamic, import, interface, json, package-json, types
- Language: TypeScript
- Homepage:
- Size: 1.95 KB
- Stars: 7
- Watchers: 3
- Forks: 1
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# types-package-json
A handful set of **package.json** types and interfaces to improve working with dynamically imported **package.json** files. **@types/package-json** became deprecated as **package.json** files imported by typescript come with it's own type definitions. Sometimes though, when you import files dynamically type becomes **any** and that's when this package becomes useful.
> Based on npm package.json documentation: https://docs.npmjs.com/files/package.json
# Usage
`npm i -D types-package-json`
```ts
import { IPackageJson } from 'types-package-json';const packageJsonPath = path.resolve(process.cwd(), `package.json`);
const packageJson: Partial = await import(packageJsonPath);
```# Features
- **Zero overhead** - contains only types and interfaces, no actual objects.
- **I prefixed** - all interfaces are prefiexed with I to avoid misunderstanding interface with a class and decrease naming overlaps.
- **IPackageJson** - full package.json interface, name and version is required
- **IPackageJsonAddress** - optional email and url
- **IPackageJsonPerson** - required name, optional email and url
- **IPackageJsonDependencyTypes** - 'dependencies' | 'devDependencies' | 'peerDependencies' | 'optionalDependencies' (bundledDependencies are not included in this type as they serve different purpose).