Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ All notable changes to this project will be documented in this file.

<!-- add unreleased items here -->

* List of well-known SPDX IDs is bundle-able and tree-shakable ([#1371] via [#1372])
The list itself is still not public, you may use the existing functionality to work with it:
`SPDX.isSupportedSpdxId()` and `SPDX.fixupSpdxId()`

[#1371]: https://github.com/CycloneDX/cyclonedx-javascript-library/issues/1371
[#1372]: https://github.com/CycloneDX/cyclonedx-javascript-library/pull/1372

## 9.4.1 -- 2025-12-04

* Fixed
Expand Down
1 change: 1 addition & 0 deletions src/.gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
spdx_specenum.ts linguist-generated
13 changes: 5 additions & 8 deletions src/spdx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,27 +19,24 @@ Copyright (c) OWASP Foundation. All Rights Reserved.

import spdxExpressionParse from 'spdx-expression-parse'

/* @ts-expect-error: TS6059 -- this works as long as the file/path is available in dist-package. */
import { enum as _spdxSpecEnum } from '../res/schema/spdx.SNAPSHOT.schema.json' with { type: 'json' }
import { LIST as spdxSpecEnum } from './spdx_specenum'

/**
* One of the known SPDX licence identifiers.
* One of the known SPDX license identifiers.
*
* @see {@link http://cyclonedx.org/schema/spdx | SPDX schema}
* @see {@link isSupportedSpdxId}
* @see {@link fixupSpdxId}
*/
export type SpdxId = string

const spdxIds: ReadonlySet<SpdxId> = new Set(_spdxSpecEnum)

const spdxLowerToActual: Readonly<Record<string, SpdxId>> = Object.freeze(Object.fromEntries(
_spdxSpecEnum.map(spdxId => [spdxId.toLowerCase(), spdxId])
spdxSpecEnum.map(spdxId => [spdxId.toLowerCase(), spdxId])
))

export function isSupportedSpdxId (value: SpdxId | any): value is SpdxId {
/* eslint-disable-next-line @typescript-eslint/no-unsafe-argument -- fix */
return spdxIds.has(value)
/* eslint-disable-next-line @typescript-eslint/no-unsafe-argument -- ack */
return spdxSpecEnum.includes(value)
}

/** Try to convert a `string`-like to a valid/known {@link SpdxId}. */
Expand Down
Loading