Library API Reference
The core package osslibraries exposes the classes below. All ArkTS code examples import from 'osslibraries'.
Libs
The main access point to the scanned data. Holds the list of libraries and the set of unique licenses.
new Libs(libraries?: Library[], licenses?: License[])Fields
libraries: Library[]licenses: License[]
Methods
findLibrary(uniqueId: string): Library | undefined— first library whoseuniqueIdmatches, orundefined.findLicense(hash: string): License | undefined— first license whosehashmatches, orundefined.
Static methods
Libs.fromJson(json: string): Libs— parse a JSON string in OSSLibraries format. Libraries are sorted by name (case-insensitive).Libs.fromMsgpack(bytes: Uint8Array): Libs— parse MessagePack binary data. Libraries are sorted the same way.
const libs = Libs.fromJson(jsonString);
const lib = libs.findLibrary('@ohos/hypium');
const license = libs.findLicense(hash);LibsLoader
Loads and parses the rawfile artifact from a module context.
static async fromRawfile(context: common.Context): Promise<Libs>Loads osslibraries.msgpack first, then falls back to osslibraries.json. Throws the JSON load error when both are missing.
const context: common.Context = this.getUIContext().getHostContext() as common.Context;
const libs: Libs = await LibsLoader.fromRawfile(context);LibsHolder
A static holder for sharing a Libs instance between pages.
static set(libs: Libs | undefined): void
static get(): Libs | undefinedThe built-in page uses it so the detail view does not load the file again.
LibsHolder.set(libs);
const cached = LibsHolder.get();Parser
Parses raw OSSLibraries data into Library and License objects. Libs.fromJson and Libs.fromMsgpack use the parser internally.
static parse(json: string): ParseResult
static parseMsgpack(bytes: Uint8Array): ParseResultParseResult has libraries: Library[] and licenses: License[]. Entries without a uniqueId are skipped and logged.
Library
One dependency. Each field is a public property.
| Field | Type | Notes |
|---|---|---|
uniqueId | string | Package name without version. |
artifactVersion | string | Version of the artifact. |
name | string | Display name. |
description | string | |
website | string | |
developers | Developer[] | |
organization | Organization | undefined | |
scm | Scm | undefined | |
licenses | License[] | Resolved from hash references at parse time. |
funding | Funding[] | |
tag | string[] |
Getters
artifactId: string— returnsuniqueId:artifactVersion.openSource: boolean—truewhenscm.urlis set.
License
One license entry.
| Field | Type | Notes |
|---|---|---|
hash | string | Unique key; references this entry. |
name | string | Human-readable name. |
url | string | Hosted form of the license. |
year | string | Year of the license, when available. |
spdxId | string | SPDX identifier, e.g. MIT. |
licenseContent | string | Full license text. |
In the raw data the text field is named content; the parser maps it to licenseContent.
Developer, Organization, Scm, Funding
Each is a small value class with public fields:
Developer—name,organisationUrlOrganization—name,urlScm—connection,developerConnection,urlFunding—platform,url
See Data Model for the raw JSON shape, and Custom UI for a complete example of reading the data with your own UI.
