Up to date typescript definitions for npm registry content
- Node.js v24 or higher
This package is available in the Node Package Repository and can be easily installed with npm or yarn.
$ npm i @nodesecure/npm-types -D
# or
$ yarn add @nodesecure/npm-types -Dimport type { PackageJSON } from "@nodesecure/npm-types";Represents a standard package.json file with all npm-supported fields.
import type { PackageJSON } from "@nodesecure/npm-types";
const pkg: PackageJSON = {
name: "my-package",
version: "1.0.0",
dependencies: { ... }
};Extends PackageJSON for monorepo workspace configurations. Name and version are optional.
import type { WorkspacesPackageJSON } from "@nodesecure/npm-types";
const workspace: WorkspacesPackageJSON = {
workspaces: ["packages/*"]
};Complete package metadata as returned by the npm registry. Contains all versions, maintainers, and distribution information.
import type { Packument } from "@nodesecure/npm-types";
const packument: Packument = {
_id: "my-package",
name: "my-package",
"dist-tags": { latest: "1.0.0" },
versions: { ... },
time: { ... }
};Metadata for a specific package version within a packument. Includes distribution details, maintainers, and npm-specific fields.
import type { PackumentVersion } from "@nodesecure/npm-types";
const version: PackumentVersion = {
name: "my-package",
version: "1.0.0",
dist: {
tarball: "https://...",
shasum: "...",
integrity: "sha512-..."
},
_npmUser: { name: "username" }
};Abbreviated package metadata format (corgi format). Lighter alternative to Packument for install operations.
import type { Manifest } from "@nodesecure/npm-types";Minimal manifest shape compatible with abbreviated registry manifests (e.g. pacote.manifest()).
- No
[field: string]: unknownindex signature (unlikeBasePackageJSON). - Avoids the need for explicit casts when assigning
Pick-based types likepacote.AbbreviatedManifest & pacote.ManifestResult.
import type { AbbreviatedManifestDocument } from "@nodesecure/npm-types";
const doc: AbbreviatedManifestDocument = {
name: "my-package",
version: "1.0.0",
dependencies: { lodash: "^4.17.21" }
};Represents a person (author, contributor, maintainer).
import type { Contact } from "@nodesecure/npm-types";
const author: Contact = {
name: "John Doe",
email: "john@example.com",
url: "https://johndoe.com"
};Git repository information.
import type { Repository } from "@nodesecure/npm-types";
const repo: Repository = {
type: "git",
url: "https://github.com/user/repo.git",
directory: "packages/core"
};Distribution information for a package version (tarball location, integrity hashes, signatures).
import type { Dist } from "@nodesecure/npm-types";Version tags (latest, next, beta, etc.) pointing to specific versions.
import type { DistTags } from "@nodesecure/npm-types";
const tags: DistTags = {
latest: "1.0.0",
next: "2.0.0-beta.1"
};Package specification string in the format name@version.
import type { Spec } from "@nodesecure/npm-types";
const spec: Spec = "lodash@4.17.21";Types for Node.js conditional exports (ESM/CJS).
import type { NodeExport } from "@nodesecure/npm-types";
const exports: NodeExport = {
import: "./dist/index.mjs",
require: "./dist/index.cjs",
default: "./dist/index.js"
};Types for Node.js subpath imports (# imports).
import type { NodeImport } from "@nodesecure/npm-types";Metadata returned by npm pack command.
import type { PackTarball } from "@nodesecure/npm-types";PGP signature information for signed packages.
import type { Signature } from "@nodesecure/npm-types";import type { PackageJSON } from "@nodesecure/npm-types";
import { readFileSync } from "node:fs";
const pkg: PackageJSON = JSON.parse(
readFileSync("./package.json", "utf-8")
);import type { Packument } from "@nodesecure/npm-types";
const response = await fetch("https://registry.npmjs.org/lodash");
const packument: Packument = await response.json();
console.log(packument["dist-tags"].latest);