MCPcopy Create free account
hub / github.com/XmirrorSecurity/OpenSCA-cli / FindMaxVersion

Function FindMaxVersion

opensca/sca/javascript/npm.go:363–385  ·  view source on GitHub ↗

FindMaxVersion 从一组版本中查找符合版本约束的最大版本 version: 范围约束 versions: 待查找的版本列表 return: 符合要求的最大版本

(version string, versions []string)

Source from the content-addressed store, hash-verified

361// versions: 待查找的版本列表
362// return: 符合要求的最大版本
363func FindMaxVersion(version string, versions []string) string {
364 c, err := semver.NewConstraint(version)
365 if err != nil {
366 return version
367 }
368 vers := []*semver.Version{}
369 for _, v := range versions {
370 ver, err := semver.NewVersion(v)
371 if err != nil {
372 continue
373 }
374 if c.Check(ver) {
375 vers = append(vers, ver)
376 }
377 }
378 sort.Slice(vers, func(i, j int) bool {
379 return vers[i].Compare(vers[j]) > 0
380 })
381 if len(vers) > 0 {
382 return vers[0].String()
383 }
384 return version
385}
386
387// findFromNodeModules 从node_modules中查找使用的package.json
388// name: 查找的组件名

Callers 1

ReadNpmJsonFunction · 0.70

Calls 2

CheckMethod · 0.80
StringMethod · 0.45

Tested by

no test coverage detected