Skip to content

Instantly share code, notes, and snippets.

@iainjreid
Last active February 13, 2020 20:28
Show Gist options
  • Star 11 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save iainjreid/5c1cc527fe6b5b7dba41fec7fe54bf6e to your computer and use it in GitHub Desktop.
Save iainjreid/5c1cc527fe6b5b7dba41fec7fe54bf6e to your computer and use it in GitHub Desktop.
A Typescript type definition for NPM package files
export interface IPackageJSON extends Object {
readonly name: string;
readonly version?: string;
readonly description?: string;
readonly keywords?: string[];
readonly homepage?: string;
readonly bugs?: string|IBugs;
readonly license?: string;
readonly author?: string|IAuthor;
readonly contributors?: string[]|IAuthor[];
readonly files?: string[];
readonly main?: string;
readonly bin?: string|IBinMap;
readonly man?: string|string[];
readonly directories?: IDirectories;
readonly repository?: string|IRepository;
readonly scripts?: IScriptsMap;
readonly config?: IConfig;
readonly dependencies?: IDependencyMap;
readonly devDependencies?: IDependencyMap;
readonly peerDependencies?: IDependencyMap;
readonly optionalDependencies?: IDependencyMap;
readonly bundledDependencies?: string[];
readonly engines?: IEngines;
readonly os?: string[];
readonly cpu?: string[];
readonly preferGlobal?: boolean;
readonly private?: boolean;
readonly publishConfig?: IPublishConfig;
}
/**
* An author or contributor
*/
export interface IAuthor {
name: string;
email?: string;
homepage?: string;
}
/**
* A map of exposed bin commands
*/
export interface IBinMap {
[commandName: string]: string;
}
/**
* A bugs link
*/
export interface IBugs {
email: string;
url: string;
}
export interface IConfig {
name?: string;
config?: Object;
}
/**
* A map of dependencies
*/
export interface IDependencyMap {
[dependencyName: string]: string;
}
/**
* CommonJS package structure
*/
export interface IDirectories {
lib?: string;
bin?: string;
man?: string;
doc?: string;
example?: string;
}
export interface IEngines {
node?: string;
npm?: string;
}
export interface IPublishConfig {
registry?: string;
}
/**
* A project repository
*/
export interface IRepository {
type: string;
url: string;
}
export interface IScriptsMap {
[scriptName: string]: string;
}
{
"name": "@types/gist-package-json",
"version": "1.0.0",
"author": "Iain Reid",
"types": "package-json.d.ts"
}
{
"authors": "Iain Reid",
"definitionFilename": "package-json.d.ts",
"sourceRepoURL": "https://gist.github.com/iainreid820/5c1cc527fe6b5b7dba41fec7fe54bf6e",
"declaredModules": [
"IPackageJSON",
"IAuthor",
"IBinMap",
"IBugs",
"IConfig",
"IDependencyMap",
"IDirectories",
"IEngines",
"IPublishConfig",
"IRepository",
"IScriptsMap"
]
}
@fis-cz
Copy link

fis-cz commented Sep 13, 2018

Hello Iain,
As there is no license specified, I would like to ask if I can use code based on this d.ts file in MIT licensed open source code. Thanks.

@iainjreid
Copy link
Author

@fis-cz sorry for the delay in replying, of course you can!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment