Skip to content

Commit

Permalink
v0.7.2
Browse files Browse the repository at this point in the history
- Added a test for PackageFromCommunity
- Implemented `v1.Package.IsModpack` method.
  • Loading branch information
Owen3H committed Aug 29, 2024
1 parent 3d279d5 commit 11d8abf
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
9 changes: 9 additions & 0 deletions tests/package_v1_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,3 +120,12 @@ func TestDownloadVersion(t *testing.T) {
data, _ := pkg.LatestVersion().Download()
println(data)
}

func TestPackageFromCommunity(t *testing.T) {
pkg := TSGOV1.PackageFromCommunity("lethal-company", "Megalophobia", "MEGALOPHOBIA")
if pkg == nil {
t.Fatal("package not found in community")
}

util.PrettyPrint(pkg)
}
17 changes: 17 additions & 0 deletions v1/package.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,27 @@ type Package struct {
Versions []PackageVersion `json:"versions"`
}

// Alias for [v1.Package.Versions][0]
func (pkg Package) LatestVersion() PackageVersion {
return pkg.Versions[0]
}

// Determines if the package is a modpack by checking the latest version has either a "modpack" or "modpacks" category.
// In addition, the description can also be checked in-case the package's categories are tagged incorrectly.
// When passing `true` the description must begin with "modpack " (including the whitespace). Simply pass `false` to disable this behaviour.
func (pkg Package) IsModpack(checkDescription bool) bool {
for _, category := range pkg.Categories {
category = strings.ToLower(category)
return category == "modpack" || category == "modpacks"
}

if !checkDescription {
return false
}

return strings.HasPrefix(strings.ToLower(pkg.LatestVersion().Description), "modpack ")
}

// Gets a specific [PackageVersion] from this package's list of versions.
//
// verNumber should be specified in the format: major.minor.patch
Expand Down

0 comments on commit 11d8abf

Please sign in to comment.