@@ -74,6 +74,13 @@ export interface LicenseVisitor {
7474
7575/**
7676 * Collect licenses that are incompatible (copyleft).
77+ *
78+ * @example
79+ * ```typescript
80+ * const nodes = [{ license: 'MIT' }, { license: 'GPL-3.0' }]
81+ * const incompatible = collectIncompatibleLicenses(nodes)
82+ * // incompatible contains only the GPL-3.0 node
83+ * ```
7784 */
7885/*@__NO_SIDE_EFFECTS__ */
7986export function collectIncompatibleLicenses (
@@ -91,6 +98,12 @@ export function collectIncompatibleLicenses(
9198
9299/**
93100 * Collect warnings from license nodes.
101+ *
102+ * @example
103+ * ```typescript
104+ * const nodes = [{ license: 'UNLICENSED' }]
105+ * collectLicenseWarnings(nodes) // ['Package is unlicensed']
106+ * ```
94107 */
95108/*@__NO_SIDE_EFFECTS__ */
96109export function collectLicenseWarnings ( licenseNodes : LicenseNode [ ] ) : string [ ] {
@@ -112,6 +125,13 @@ export function collectLicenseWarnings(licenseNodes: LicenseNode[]): string[] {
112125
113126/**
114127 * Create an AST node from a raw node.
128+ *
129+ * @example
130+ * ```typescript
131+ * const raw = { license: 'MIT' }
132+ * const node = createAstNode(raw)
133+ * // node.type === 'License'
134+ * ```
115135 */
116136/*@__NO_SIDE_EFFECTS__ */
117137export function createAstNode ( rawNode : SpdxAstNode ) : InternalAstNode {
@@ -122,6 +142,17 @@ export function createAstNode(rawNode: SpdxAstNode): InternalAstNode {
122142
123143/**
124144 * Create a binary operation AST node.
145+ *
146+ * @example
147+ * ```typescript
148+ * const raw = {
149+ * left: { license: 'MIT' },
150+ * conjunction: 'OR' as const,
151+ * right: { license: 'Apache-2.0' }
152+ * }
153+ * const node = createBinaryOperationNode(raw)
154+ * // node.type === 'BinaryOperation'
155+ * ```
125156 */
126157/*@__NO_SIDE_EFFECTS__ */
127158export function createBinaryOperationNode (
@@ -156,6 +187,12 @@ export function createBinaryOperationNode(
156187
157188/**
158189 * Create a license AST node.
190+ *
191+ * @example
192+ * ```typescript
193+ * const node = createLicenseNode({ license: 'MIT' })
194+ * // node.type === 'License' && node.license === 'MIT'
195+ * ```
159196 */
160197/*@__NO_SIDE_EFFECTS__ */
161198export function createLicenseNode (
@@ -170,6 +207,12 @@ export function createLicenseNode(
170207
171208/**
172209 * Parse an SPDX license expression into an AST.
210+ *
211+ * @example
212+ * ```typescript
213+ * const ast = parseSpdxExp('MIT OR Apache-2.0')
214+ * // ast is a BinaryOperation node with MIT and Apache-2.0 leaves
215+ * ```
173216 */
174217/*@__NO_SIDE_EFFECTS__ */
175218export function parseSpdxExp ( spdxExp : string ) : SpdxAstNode | undefined {
@@ -184,6 +227,12 @@ export function parseSpdxExp(spdxExp: string): SpdxAstNode | undefined {
184227
185228/**
186229 * Parse package license field into structured license nodes.
230+ *
231+ * @example
232+ * ```typescript
233+ * const nodes = resolvePackageLicenses('MIT', '/tmp/my-project')
234+ * // [{ license: 'MIT' }]
235+ * ```
187236 */
188237/*@__NO_SIDE_EFFECTS__ */
189238export function resolvePackageLicenses (
@@ -238,6 +287,16 @@ export function resolvePackageLicenses(
238287
239288/**
240289 * Traverse SPDX license AST and invoke visitor callbacks for each node.
290+ *
291+ * @example
292+ * ```typescript
293+ * const ast = parseSpdxExp('MIT OR Apache-2.0')
294+ * const licenses: string[] = []
295+ * if (ast) {
296+ * visitLicenses(ast, { License(node) { licenses.push(node.license) } })
297+ * }
298+ * // licenses === ['MIT', 'Apache-2.0']
299+ * ```
241300 */
242301/*@__NO_SIDE_EFFECTS__ */
243302export function visitLicenses ( ast : SpdxAstNode , visitor : LicenseVisitor ) : void {
0 commit comments