api

package
v0.0.0-...-3be1b17 Latest Latest
Warning

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

Go to latest
Published: Mar 22, 2025 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DistInfo

type DistInfo struct {
	Tarball      string `json:"tarball"`
	Shasum       string `json:"shasum"`
	Integrity    string `json:"integrity"`
	UnpackedSize int    `json:"unpackedSize"` // The registry gives a numeric "unpackedSize"
}

DistInfo holds distribution-related fields for a specific version.

type DownloadsResponse

type DownloadsResponse struct {
	Downloads int    `json:"downloads"`
	Start     string `json:"start"`
	End       string `json:"end"`
	Package   string `json:"package"`
}

DownloadsResponse is the response from the downloads API at https://api.npmjs.org/downloads/point/last-week/<packageName>.

type NpmPackageInfo

type NpmPackageInfo struct {
	Name            string
	Version         string
	License         string
	UnpackedSizeKB  string // We’ll convert from int bytes to a human-readable "KB"
	WeeklyDownloads string
	Created         string
	Modified        string
	LastPublished   string
}

NpmPackageInfo is what we'll return with all fields we care about.

func FetchNpmPackageInfo

func FetchNpmPackageInfo(packageName string) (*NpmPackageInfo, error)

FetchNpmPackageInfo fetches metadata from the registry and weekly downloads from the npmjs.org API

type NpmTime

type NpmTime struct {
	Created  string `json:"created"`
	Modified string `json:"modified"`
}

NpmTime holds creation and modification times for the entire package. We'll also parse the "last published" date from a specific version.

type RegistryResponse

type RegistryResponse struct {
	Name     string                 `json:"name"`
	Time     map[string]string      `json:"time"`     // Each version has a date, plus "created", "modified"
	Versions map[string]VersionInfo `json:"versions"` // Keyed by version string
	DistTags map[string]string      `json:"dist-tags"`
}

RegistryResponse is the overall response from https://registry.npmjs.org/<packageName>.

type VersionInfo

type VersionInfo struct {
	Name    string   `json:"name"`
	Version string   `json:"version"`
	License any      `json:"license"` // License can be a string or object, so use `any`
	Dist    DistInfo `json:"dist"`
}

VersionInfo holds metadata for a specific version (license, dist info, etc.).

Jump to

Keyboard shortcuts

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