npm

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Naming     = valid.Validator{valid.Range{'a', 'z'}, valid.Range{'A', 'Z'}, valid.Range{'0', '9'}, valid.Eq('_'), valid.Eq('.'), valid.Eq('-'), valid.Eq('+'), valid.Eq('$'), valid.Eq('!')}
	Versioning = valid.Validator{valid.Range{'a', 'z'}, valid.Range{'A', 'Z'}, valid.Range{'0', '9'}, valid.Eq('_'), valid.Eq('.'), valid.Eq('-'), valid.Eq('+')}
)

Functions

func IsDateVersion

func IsDateVersion(version string) (time.Time, bool, error)

IsDateVersion returns true if the given version is a date in yyyy-mm-dd format.

func IsDistTag

func IsDistTag(s string) bool

IsDistTag returns true if the given version is a distribution tag. https://docs.npmjs.com/cli/v9/commands/npm-dist-tag

func IsExactVersion

func IsExactVersion(version string) bool

IsExactVersion returns true if the given version is an exact version.

func IsStableVersion

func IsStableVersion(version string) bool

IsStableVersion returns true if the version is a stable release (not experimental, beta, alpha, etc.)

func NormalizePackageVersion

func NormalizePackageVersion(version string) string

NormalizePackageVersion normalizes the package version. It removes the leading `=` or `v` and returns "latest" for empty or "*" versions.

func ResolveVersionByTime

func ResolveVersionByTime(metadata *PackageMetadata, targetTime time.Time) (string, error)

ResolveVersionByTime finds the latest stable version published before or at the given time.

func ToTypesPackageName

func ToTypesPackageName(pkgName string) string

ToTypesPackageName converts a package name to a types package name. If the package name is scoped, it returns "@types/[scope_name]__[package_name]".

func ValidatePackageName

func ValidatePackageName(pkgName string) bool

ValidatePackageName validates the package name. based on https://github.com/npm/validate-npm-package-name

Types

type JSONAny

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

func (*JSONAny) MarshalJSON

func (a *JSONAny) MarshalJSON() ([]byte, error)

func (*JSONAny) String

func (a *JSONAny) String() string

func (*JSONAny) UnmarshalJSON

func (a *JSONAny) UnmarshalJSON(b []byte) error

type JSONObject

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

JSONObject represents a readonly JSON object with ordered keys

func NewJSONObject

func NewJSONObject(keys []string, values map[string]any) JSONObject

NewJSONObject creates a new JSONObject with the given keys and values

func (*JSONObject) Get

func (obj *JSONObject) Get(key string) (any, bool)

Get returns the value of the key in the JSON object

func (*JSONObject) Keys

func (obj *JSONObject) Keys() []string

Keys returns the keys of the JSON object

func (*JSONObject) Len

func (obj *JSONObject) Len() int

Len returns the length of the JSON object

func (*JSONObject) UnmarshalJSON

func (obj *JSONObject) UnmarshalJSON(data []byte) error

UnmarshalJSON implements type json.Unmarshaler interface

func (*JSONObject) Values

func (obj *JSONObject) Values() map[string]any

Values returns the values of the JSON object

type NpmPackageDist

type NpmPackageDist struct {
	Tarball string `json:"tarball"`
}

NpmPackageDist defines the dist field of a NPM package

type Package

type Package struct {
	Name     string
	Version  string
	Url      string
	Github   bool
	PkgPrNew bool
}

func ResolveDependencyVersion

func ResolveDependencyVersion(v string) (Package, error)

ResolveDependencyVersion resolves the version of a dependency e.g. "react": "npm:react@19.0.0" e.g. "react": "github:facebook/react#semver:19.0.0" e.g. "flag": "jsr:@luca/flag@0.0.1" e.g. "tinybench": "https://pkg.pr.new/tinybench@a832a55"

func (*Package) String

func (p *Package) String() string

type PackageJSON

type PackageJSON struct {
	Name             string
	PkgName          string
	Version          string
	Type             string
	Main             string
	Module           string
	Types            string
	SideEffectsFalse bool
	SideEffects      set.ReadOnlySet[string]
	Browser          map[string]string
	Dependencies     map[string]string
	PeerDependencies map[string]string
	Imports          map[string]any
	TypesVersions    map[string]any
	Exports          JSONObject
	Esmsh            map[string]any
	Dist             NpmPackageDist
	Deprecated       string
}

PackageJSON defines the package.json of a NPM package

func (*PackageJSON) UnmarshalJSON

func (a *PackageJSON) UnmarshalJSON(b []byte) error

UnmarshalJSON implements the json.Unmarshaler interface

type PackageJSONRaw

type PackageJSONRaw struct {
	Name             string          `json:"name"`
	Version          string          `json:"version"`
	Type             string          `json:"type"`
	Main             JSONAny         `json:"main"`
	Module           JSONAny         `json:"module"`
	ES2015           JSONAny         `json:"es2015"`
	JsNextMain       JSONAny         `json:"jsnext:main"`
	Browser          JSONAny         `json:"browser"`
	Types            JSONAny         `json:"types"`
	Typings          JSONAny         `json:"typings"`
	SideEffects      any             `json:"sideEffects"`
	Dependencies     any             `json:"dependencies"`
	PeerDependencies any             `json:"peerDependencies"`
	Imports          any             `json:"imports"`
	TypesVersions    any             `json:"typesVersions"`
	Exports          json.RawMessage `json:"exports"`
	Esmsh            any             `json:"esm.sh"`
	Dist             json.RawMessage `json:"dist"`
	Deprecated       any             `json:"deprecated"`
}

PackageJSONRaw defines the package.json of a NPM package

func (*PackageJSONRaw) ToNpmPackage

func (a *PackageJSONRaw) ToNpmPackage() *PackageJSON

ToNpmPackage converts PackageJSONRaw to PackageJSON

type PackageMetadata

type PackageMetadata struct {
	DistTags map[string]string         `json:"dist-tags"`
	Versions map[string]PackageJSONRaw `json:"versions"`
	Time     map[string]string         `json:"time"`
}

PackageMetadata defines versions of a NPM package

Jump to

Keyboard shortcuts

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