Documentation
¶
Overview ¶
Package npm is the library behind the npmcli command line: the HTTP client, request shaping, and the typed data models for the npm package registry.
Two public APIs: the registry at registry.npmjs.org for package metadata and the downloads API at api.npmjs.org for download statistics. Both are open and require no key.
Index ¶
- Constants
- Variables
- type Client
- func (c *Client) Deps(ctx context.Context, name string) ([]Dependency, error)
- func (c *Client) Downloads(ctx context.Context, name, period string) (*Downloads, error)
- func (c *Client) Info(ctx context.Context, name string) (*Package, error)
- func (c *Client) Search(ctx context.Context, query string, limit int) ([]SearchResult, error)
- func (c *Client) Version(ctx context.Context, name, version string) (*PackageVersion, error)
- type Config
- type Dependency
- type Domain
- type Downloads
- type Package
- type PackageVersion
- type SearchResult
Constants ¶
const DefaultUserAgent = "npmcli/0.1.0 (github.com/tamnd/npm-cli)"
DefaultUserAgent identifies the client to npm APIs.
const Host = "registry.npmjs.org"
Host is the primary registry hostname.
Variables ¶
var ErrNotFound = errors.New("not found")
ErrNotFound is returned when the registry returns a 404 for a package.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client talks to the npm registry and downloads APIs.
func (*Client) Downloads ¶
Downloads fetches download counts for a package over a period. period can be "last-week", "last-month", "last-year", or a date range "YYYY-MM-DD:YYYY-MM-DD".
type Config ¶
type Config struct {
RegistryURL string
DownloadsURL string
UserAgent string
Rate time.Duration
Timeout time.Duration
Retries int
}
Config holds constructor parameters for both endpoints.
type Dependency ¶
type Dependency struct {
Name string `json:"name"`
Constraint string `json:"constraint"`
Kind string `json:"kind"` // "dep" or "devDep"
}
Dependency is a flat record for one dependency entry.
type Domain ¶
type Domain struct{}
Domain is the npm registry driver.
func (Domain) Classify ¶
Classify turns any accepted input into the canonical (type, id), so `ant resolve` and `ant url` touch no network.
func (Domain) Info ¶
func (Domain) Info() kit.DomainInfo
Info describes the scheme, the hostnames a pasted link is matched against, and the identity reused for help and version output.
type Downloads ¶
type Downloads struct {
Package string `json:"package"`
Downloads int `json:"downloads"`
Start string `json:"start"`
End string `json:"end"`
}
Downloads is the record returned by the downloads command.
type Package ¶
type Package struct {
Name string `json:"name" kit:"id"`
Description string `json:"description"`
Version string `json:"version"`
Keywords []string `json:"keywords"`
Homepage string `json:"homepage"`
License string `json:"license"`
Author string `json:"author"`
Repository string `json:"repository"`
Created string `json:"created"`
Modified string `json:"modified"`
Readme string `json:"readme,omitempty"`
URL string `json:"url"`
}
Package is the record returned by the info command.
type PackageVersion ¶
type PackageVersion struct {
Name string `json:"name"`
Version string `json:"version"`
Description string `json:"description"`
Keywords []string `json:"keywords"`
Homepage string `json:"homepage"`
License string `json:"license"`
Author string `json:"author"`
Dependencies map[string]string `json:"dependencies"`
DevDependencies map[string]string `json:"dev_dependencies"`
URL string `json:"url"`
}
PackageVersion is the record returned by the version command.
type SearchResult ¶
type SearchResult struct {
Rank int `json:"rank"`
Name string `json:"name"`
Version string `json:"version"`
Description string `json:"description"`
Keywords []string `json:"keywords"`
ScoreFinal float64 `json:"score_final"`
URL string `json:"url"`
}
SearchResult is one hit from the npm search API.