Skip to content

Commit 5e4dba8

Browse files
committed
chore: add documentation
1 parent f36f161 commit 5e4dba8

File tree

5 files changed

+135
-1
lines changed

5 files changed

+135
-1
lines changed

CONTRIBUTING

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
## Development
2+
3+
### Building
4+
5+
```bash
6+
npm run build
7+
```
8+
9+
### Testing
10+
11+
```bash
12+
npm test
13+
```
14+
15+
### Linting
16+
17+
```bash
18+
npm run lint
19+
npm run lint:fix
20+
```
21+
22+
### Formatting
23+
24+
```bash
25+
npm run format:check
26+
npm run format:write
27+
```

README.md

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
# @herodevs/eol-shared
2+
3+
A TypeScript utility library for End-of-Life (EOL) scanning and analysis.
4+
5+
## Installation
6+
7+
```bash
8+
npm install @herodevs/eol-shared
9+
```
10+
11+
## Requirements
12+
13+
- Node.js 22 or higher
14+
15+
## API
16+
17+
### [`spdxToCdxBom(spdxBom: SPDX23): CdxBom`](./src/spdx-to-cdx.mts#L61)
18+
19+
Converts an SPDX BOM to CycloneDX format. This conversion takes the most important package and relationship data from SPDX and translates them into CycloneDX components and dependencies as closely as possible.
20+
21+
```typescript
22+
import { spdxToCdxBom } from '@herodevs/eol-shared';
23+
import type { CdxBom } from '@herodevs/eol-shared';
24+
25+
const spdxBom = {
26+
/* your SPDX BOM data */
27+
};
28+
const cdxBom: CdxBom = spdxToCdxBom(spdxBom);
29+
```
30+
31+
**Parameters**: `spdxBom` - The SPDX BOM object to convert
32+
**Returns**: A CycloneDX BOM object
33+
34+
### [`xmlStringToJSON(xmlString: string): CdxBom`](./src/cdx-xml-to-json.mts#L161)
35+
36+
Converts a CycloneDX XML string to a JSON object. The CycloneDX spec does not change between formats, so conversion from XML to JSON is lossless.
37+
38+
```typescript
39+
import { xmlStringToJSON } from '@herodevs/eol-shared';
40+
import type { CdxBom } from '@herodevs/eol-shared';
41+
42+
const xmlString = `<?xml version="1.0"?>...`;
43+
const jsonBom: CdxBom = xmlStringToJSON(xmlString);
44+
```
45+
46+
**Parameters**: `xmlString` - The XML string to parse
47+
**Returns**: The parsed CycloneDX BOM object
48+
49+
### [`trimCdxBom(cdxBom: CdxBom): CdxBom`](./src/trim-cdx-bom.mts#L3)
50+
51+
Creates a trimmed copy of a CycloneDX BOM by removing SBOM data not necessary for EOL scanning:
52+
53+
- `externalReferences` from components
54+
- `evidence` from components
55+
- `hashes` from components
56+
- `properties` from components
57+
58+
```typescript
59+
import { trimCdxBom } from '@herodevs/eol-shared';
60+
import type { CdxBom } from '@herodevs/eol-shared';
61+
62+
const originalBom: CdxBom = {
63+
/* your CycloneDX BOM */
64+
};
65+
const trimmedBom: CdxBom = trimCdxBom(originalBom);
66+
```
67+
68+
**Parameters**: `cdxBom` - The CycloneDX BOM to trim
69+
**Returns**: A new trimmed CycloneDX BOM object
70+
71+
### Types
72+
73+
The package exports the following TypeScript types:
74+
75+
- `CdxBom` - CycloneDX BOM structure as exported from [`@cyclonedx/cyclonedx-library`](https://github.com/CycloneDX/cyclonedx-javascript-library/blob/447db28f47ffd03b6f9c2f4a450bef0f0392c6bb/src/serialize/json/types.ts#L76)
76+
- `Component` - Component definition
77+
- `Dependency` - Dependency relationship
78+
- `Hash` - Hash/checksum information
79+
- `License` - License information
80+
- `ExternalReference` - External reference data
81+
- `ComponentScope` - Component scope enumeration
82+
83+
## Resources
84+
85+
This package is designed to work with:
86+
87+
- [CycloneDX](https://cyclonedx.org/) - Industry standard for Software Bill of Materials
88+
- [SPDX](https://spdx.dev/) - Software Package Data Exchange standard

src/cdx-xml-to-json.mts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { XMLParser } from 'fast-xml-parser';
2+
import type { CdxBom } from './index.mts';
23

34
const COLLECTION_KEYS = [
45
'tools',
@@ -157,7 +158,13 @@ function transform(obj: any): any {
157158
return result;
158159
}
159160

160-
export async function xmlStringToJSON(xml: string) {
161+
/**
162+
* Converts a CycloneDX XML string to a JSON object.
163+
* The CycloneDX spec does not change between formats, so conversion from XML to JSON is lossless.
164+
* @param xml - The XML string to parse
165+
* @returns The parsed CycloneDX BOM object
166+
*/
167+
export function xmlStringToJSON(xml: string): CdxBom {
161168
const parsed = parser.parse(xml);
162169
return transform(parsed);
163170
}

src/spdx-to-cdx.mts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,12 @@ function mapScope(rel: string): Scope {
5959
}
6060
}
6161

62+
/**
63+
* Converts an SPDX BOM to CycloneDX format.
64+
* Takes the most important package and relationship data from SPDX and translates them into CycloneDX components and dependencies as closely as possible.
65+
* @param spdx - The SPDX BOM object to convert
66+
* @returns A CycloneDX BOM object
67+
*/
6268
export function spdxToCdxBom(spdx: SPDX23): CdxBom {
6369
const bom: CdxBom = {
6470
$schema: 'http://cyclonedx.org/schema/bom-1.5.schema.json',

src/trim-cdx-bom.mts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
import type { CdxBom } from './types/index.mts';
22

3+
/**
4+
* Creates a trimmed copy of a CycloneDX BOM by removing SBOM data not necessary for EOL scanning.
5+
* Removes externalReferences, evidence, hashes, and properties from components.
6+
* @param cdxBom - The CycloneDX BOM to trim
7+
* @returns A new trimmed CycloneDX BOM object
8+
*/
39
export function trimCdxBom(cdxBom: CdxBom): CdxBom {
410
const newBom = structuredClone(cdxBom);
511

0 commit comments

Comments
 (0)