@cyclonedx/cyclonedx-library

中文文档
10.5.0发布于 2026/11/09Apache-2.0TypeScriptCommonJS零依赖构建来源已验证近 30 天下载 311.3万

Core functionality of CycloneDX for JavaScript (Node.js or WebBrowser).

原始使用文档
文档目录10 节
  1. Responsibilities
  2. Capabilities
  3. Installation
  4. Optional Peer Dependencies
  5. Usage
  6. As Node.js package
  7. In WebBrowsers
  8. API documentation
  9. Development & Contributing
  10. License

CycloneDX JavaScript Library

shield_npm-version shield_rtfd shield_gh-workflow-test shield_coverage shield_ossf-best-practices shield_license
shield_website shield_slack shield_groups shield_twitter-follow


OWASP CycloneDX is a full‑stack Bill of Materials (BOM) and system‑transparency standard that provides deep visibility into software, services, hardware, and AI components, enabling advanced supply‑chain security and cyber‑risk reduction.

This package provides functionality of CycloneDX for JavaScript (Node.js or WebBrowsers), written in TypeScript and compiled for the target.

[!NOTE]
This package is a software library not intended for standalone use.
For a list of tools and plugins for generating Software Bill of Materials (SBOM), check out the meta-package.

Responsibilities

  • Provide a general purpose JavaScript-implementation of CycloneDX for Node.js and WebBrowsers.
  • Provide typing for said implementation, so developers and dev-tools can rely on it.
  • Provide data models to work with CycloneDX.
  • Provide JSON- and XML-normalizers, that...
    • supports all shipped data models.
    • respects any injected CycloneDX Specification and generates valid output according to it.
    • can be configured to generate reproducible/deterministic output.
    • can prepare data structures for JSON- and XML-serialization.
  • Serialization:
    • Provide a universal JSON-serializer for all target environments.
    • Provide an XML-serializer for all target environments.
    • Support the downstream implementation of custom XML-serializers tailored to specific environments
      by providing an abstract base class that takes care of normalization and BomRef-discrimination.
      This is done, because there is no universal XML support in JavaScript.
  • Provide formal JSON- and XML-validators according to CycloneDX Specification. (currently for Node.js only)

Capabilities

  • Enums for the following use cases:
    • AttachmentEncoding
    • ComponentScope
    • ComponentType
    • ExternalReferenceType
    • HashAlgorithm
    • Vulnerability related:
      • AffectStatus
      • AnalysisJustification
      • AnalysisResponse
      • AnalysisState
      • RatingMethod
      • Severity
  • Data models for the following use cases:
    • Attachment
    • Bom
    • BomLink, BomLinkDocument, BomLinkElement
    • BomRef, BomRefRepository
    • Component, ComponentRepository, ComponentEvidence
    • ExternalReference, ExternalReferenceRepository
    • Hash, HashContent, HashDictionary
    • LicenseExpression, NamedLicense, SpdxLicense, LicenseRepository
    • Metadata
    • OrganizationalContact, OrganizationalContactRepository
    • OrganizationalEntity, OrganizationalEntityRepository
    • Property, PropertyRepository
    • SWID
    • Tool, ToolRepository, Tools
    • Vulnerability related:
      • Advisory, AdvisoryRepository
      • Affect, AffectRepository, AffectedSingleVersion, AffectedVersionRange, AffectedVersionRepository
      • Analysis
      • Credits
      • Rating, RatingRepository
      • Reference, ReferenceRepository
      • Source
      • Vulnerability, VulnerabilityRepository
  • Utilities for the following use cases:
    • Generate valid random SerialNumbers for Bom.serialNumber
    • Gather license evidences from files (for Node.js only)
  • Factories for the following use cases:
    • Create data models from any license descriptor string
    • Specific to Node.js: create data models from PackageJson-like data structures and derived data
  • Builders for the following use cases:
    • Specific to Node.js: create deep data models Tool or Component from PackageJson-like data structures
  • Implementation of the CycloneDX Specification for the following versions:
    • 1.7
    • 1.6
    • 1.5
    • 1.4
    • 1.3
    • 1.2
  • Normalizers that convert data models to JSON structures
  • Normalizers that convert data models to XML structures
  • Universal serializer that converts Bom data models to JSON string
  • Specific Serializer that converts Bom data models to XML string:
    • Specific to WebBrowsers: implementation utilizes browser-specific document generators and printers.
    • Specific to Node.js: implementation utilizes optional dependencies as described below
  • Formal validators for JSON string and XML string (currently for Node.js only)
    Requires optional dependencies as described below

Installation

This package and the build results are available for npm, pnpm and yarn:

npm i -S @cyclonedx/cyclonedx-library
pnpm add @cyclonedx/cyclonedx-library
yarn add @cyclonedx/cyclonedx-library

You can install the package from source, which will build automatically on installation:

npm i -S github:CycloneDX/cyclonedx-javascript-library
pnpm add github:CycloneDX/cyclonedx-javascript-library
yarn add @cyclonedx/cyclonedx-library@github:CycloneDX/cyclonedx-javascript-library # only with yarn-2

Optional Peer Dependencies

Some features require optional peer dependencies — see package.json for version details.

In addition, we have some suggestions for related 3rd-party standards:

Usage

See extended examples.

As Node.js package

const CDX = require('@cyclonedx/cyclonedx-library')

const bom = new CDX.Models.Bom()
bom.metadata.component = new CDX.Models.Component(
  CDX.Enums.ComponentType.Application,
  'MyProject'
)
const componentA = new CDX.Models.Component(
  CDX.Enums.ComponentType.Library,
  'myComponentA',
)
bom.components.add(componentA)
bom.metadata.component.dependencies.add(componentA.bomRef)

To ensure optimal tree‑shaking when bundling, import only the symbols you actually need from the library’s published entry points. You can find all available entry points in the exports field of the package’s package.json.

const { Bom, Component } = require('@cyclonedx/cyclonedx-library/Models')
const { ComponentType } = require('@cyclonedx/cyclonedx-library/Enums')

const bom = new Bom()
bom.metadata.component = new Component(
  ComponentType.Application,
  'MyProject'
)
const componentA = new Component(
  ComponentType.Library,
  'myComponentA',
)
bom.components.add(componentA)
bom.metadata.component.dependencies.add(componentA.bomRef)

In WebBrowsers

<script src="path-to-this-package/dist.web/lib.js"></script>
<script type="application/javascript">
    const CDX = CycloneDX_library

    let bom = new CDX.Models.Bom()
    bom.metadata.component = new CDX.Models.Component(
        CDX.Enums.ComponentType.Application,
        'MyProject'
    )
    const componentA = new CDX.Models.Component(
        CDX.Enums.ComponentType.Library,
        'myComponentA',
    )
    bom.components.add(componentA)
    bom.metadata.component.dependencies.add(componentA.bomRef)
</script>

API documentation

We ship annotated type definitions, so that your IDE and tools may pick up the documentation when you use this library downstream.

There are also pre-rendered documentations hosted on readthedocs.

Development & Contributing

Feel free to open issues, bug reports or pull requests.
See the CONTRIBUTING file for details.

License

Permission to modify and redistribute is granted under the terms of the Apache 2.0 license.
See the LICENSE file for the full license.

版本与发布记录

@cyclonedx/cyclonedx-library 共发布 123 个版本,首次发布于 2022/06/09;过去 12 个月发布了 18 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
10.5.0latest2026/11/091 天前
10.4.02026/11/037 天前
10.4.0-rc.0unstable-prerelease2026/11/037 天前
10.3.02026/09/181 个月前
10.2.02026/08/172 个月前
10.1.12026/08/103 个月前

其他发布通道:backport → 6.13.1,testing → 10.1.1-rc.1,unstable-prerelease → 10.4.0-rc.0。

关于 @cyclonedx/cyclonedx-library 的常见问题

@cyclonedx/cyclonedx-library 是什么?

Core functionality of CycloneDX for JavaScript (Node.js or WebBrowser).

如何安装 @cyclonedx/cyclonedx-library?

在项目目录运行 npm install @cyclonedx/cyclonedx-library,或使用 pnpm add / yarn add / bun add。

@cyclonedx/cyclonedx-library 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@cyclonedx/cyclonedx-library 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@cyclonedx/cyclonedx-library 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=20.18.0。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@cyclonedx/cyclonedx-library 可以商用吗?

@cyclonedx/cyclonedx-library 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@cyclonedx/cyclonedx-library 的下载量有多少?

根据 npm 官方下载统计,@cyclonedx/cyclonedx-library 在 2026/10/11 – 2026/11/09 这 30 天内被下载 3,112,600 次,日均约 103,753 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@cyclonedx/cyclonedx-library 还在维护吗?

最新版本 10.5.0 发布于 2026/11/09(1 天前);至今共发布 123 个版本,其中过去 12 个月发布了 18 个;首次发布于 2022/06/09。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。