npm

package
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 15, 2026 License: Apache-2.0 Imports: 12 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package npm is the Source for the npm registry. It lists the versions of a package from its packument, GET {base}/{name}.

Abbreviated or full metadata

The registry serves two shapes of the packument. The abbreviated one (Accept: application/vnd.npm.install-v1+json) is small but has no "time" map. The full one has it. A Version needs PublishedAt, and an unpublished version is only visible as a key of "time" with no entry in "versions", so the default is the full document. WithAbbreviated opts in to the smaller shape for callers that can live without both: it leaves PublishedAt zero and cannot report unpublished versions. Full packuments of busy packages are large. Decompressed sizes measured in November 2026:

package      full     abbreviated
react        7.1 MB   3.0 MB
@types/node  11.2 MB
aws-sdk      10.6 MB  3.8 MB
typescript   15.9 MB  8.8 MB
next         31.5 MB  25.7 MB

netguard's default body cap is 10 MiB, so several popular packages exceed it. netguard has a built-in 64 MiB cap for registry.npmjs.org (overridable with netguard.HostLimit.MaxBodyBytes), so a netguard client needs no configuration. A mirror on another host keeps the global cap unless the client is built with a HostLimits entry for it. A response over the cap makes List fail with an error wrapping netguard.ErrBodyTooLarge.

Errors and ordering

A 404 (a package that never existed, or whose registry document is gone) is returned as an error wrapping *netguard.StatusError, never as an empty result. Versions are sorted newest first by PublishedAt, ties by Raw. In abbreviated mode there is no PublishedAt, so the order is only by Raw (string order, not semantic); the core must not rely on it.

What a Version carries

Raw is the version key. PublishedAt comes from "time". A version that is in "time" but not in "versions" was unpublished and is Yanked. A deprecated version is not Yanked; its message is Metadata["deprecated"]. Metadata also has "dist-tags" (the tags pointing at the version, sorted), "tarball", "integrity" and "shasum" when the registry gives them, and "unpublished": true for unpublished versions. Prerelease is left nil: npm has no such flag and the core derives it from the version.

Index

Constants

View Source
const (
	// Kind is the registry key of this source.
	Kind = "npm"
	// DefaultBaseURL is the public npm registry.
	DefaultBaseURL = "https://registry.npmjs.org"
	// DefaultPackageURL is the prefix of package pages on the public registry.
	DefaultPackageURL = "https://www.npmjs.com/package"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Option

type Option func(*Source)

Option configures a Source.

func WithAbbreviated

func WithAbbreviated() Option

WithAbbreviated requests the abbreviated packument. See the package documentation for what is lost.

func WithPackageURL

func WithPackageURL(prefix string) Option

WithPackageURL sets the prefix of the release page URL, to which "/{name}/v/{version}" is appended. Without it, URL is set only for the public registry.

type Source

type Source struct {
	// contains filtered or unexported fields
}

Source implements source.Source for npm.

func New

func New(baseURL string, hc *http.Client, opts ...Option) *Source

New returns an npm Source reading from baseURL (DefaultBaseURL if empty) with hc, normally the HTTPClient of a netguard client.

func (*Source) Kind

func (*Source) Kind() string

Kind implements source.Source.

func (*Source) List

List implements source.Source.

func (*Source) Validate

func (*Source) Validate(t source.Target) error

Validate implements source.Source. The only coordinate is "name", the package name, scoped as "@scope/name". It does no I/O.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL