Documentation
¶
Index ¶
- Variables
- func IsDateVersion(version string) (time.Time, bool, error)
- func IsDistTag(s string) bool
- func IsExactVersion(version string) bool
- func IsStableVersion(version string) bool
- func NormalizePackageVersion(version string) string
- func ResolveVersionByTime(metadata *PackageMetadata, targetTime time.Time) (string, error)
- func ToTypesPackageName(pkgName string) string
- func ValidatePackageName(pkgName string) bool
- type JSONAny
- type JSONObject
- type NpmPackageDist
- type Package
- type PackageJSON
- type PackageJSONRaw
- type PackageMetadata
Constants ¶
This section is empty.
Variables ¶
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 ¶
IsDateVersion returns true if the given version is a date in yyyy-mm-dd format.
func IsDistTag ¶
IsDistTag returns true if the given version is a distribution tag. https://docs.npmjs.com/cli/v9/commands/npm-dist-tag
func IsExactVersion ¶
IsExactVersion returns true if the given version is an exact version.
func IsStableVersion ¶
IsStableVersion returns true if the version is a stable release (not experimental, beta, alpha, etc.)
func NormalizePackageVersion ¶
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 ¶
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 ¶
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 (*JSONAny) UnmarshalJSON ¶
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) 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 ¶
func ResolveDependencyVersion ¶
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"
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