-
Notifications
You must be signed in to change notification settings - Fork 55
/
language.ts
38 lines (34 loc) · 1.21 KB
/
language.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import {DependencyLanguage} from './types'
// Attempt to find the language from a SBOM component. For now, we get the source either from
// the bom-ref or the purl property of the SBOM.
export const getLanguageFromComponent = (component: any): DependencyLanguage | undefined => {
const componentName = component['name']
if (component['bom-ref']) {
if (component['bom-ref'].includes('pkg:npm') || component['purl'].includes('pkg:npm')) {
return DependencyLanguage.NPM
}
if (component['purl'].includes('pkg:composer')) {
return DependencyLanguage.PHP
}
if (component['purl'].includes('pkg:cargo')) {
return DependencyLanguage.RUST
}
if (component['purl'].includes('pkg:gem')) {
return DependencyLanguage.RUBY
}
if (component['purl'].includes('pkg:maven')) {
return DependencyLanguage.JVM
}
if (component['purl'].includes('pkg:golang')) {
return DependencyLanguage.GO
}
if (component['purl'].includes('pkg:pypi')) {
return DependencyLanguage.PYTHON
}
if (component['purl'].includes('pkg:nuget')) {
return DependencyLanguage.DOTNET
}
}
console.debug(`language for component ${componentName} not found`)
return undefined
}