# Changelog Module The changelog module provides comprehensive parsing, manipulation, and serialization of CHANGELOG.md files. ## Architecture Overview ```mermaid flowchart LR subgraph Input MD[CHANGELOG.md] end subgraph Core PARSE[parse/] MODELS[models/] PARSE --> MODELS end subgraph Transform OPS[operations/] COMPARE[compare/] MODELS --> OPS MODELS --> COMPARE end subgraph Output SERIALIZE[serialize/] OPS --> SERIALIZE SERIALIZE --> MD_OUT[Markdown] SERIALIZE --> JSON_OUT[JSON] end MD --> PARSE ``` ### Module Dependencies ```mermaid graph TD MODELS[models/] --> PARSE[parse/] MODELS --> SERIALIZE[serialize/] MODELS --> COMPARE[compare/] MODELS --> OPS[operations/] PARSE -.->|creates| CHANGELOG[Changelog] SERIALIZE -.->|consumes| CHANGELOG COMPARE -.->|consumes| CHANGELOG OPS -.->|transforms| CHANGELOG ``` ## Data Model ```mermaid classDiagram class Changelog { +source?: string +header: ChangelogHeader +entries: ChangelogEntry[] +metadata: ChangelogMetadata } class ChangelogHeader { +title: string +description: string[] +links: ChangelogLink[] } class ChangelogLink { +label: string +url: string } class ChangelogEntry { +version: string +date: string | null +unreleased: boolean +compareUrl?: string +sections: ChangelogSection[] +rawContent?: string } class ChangelogSection { +type: ChangelogSectionType +heading: string +items: ChangelogItem[] } class ChangelogItem { +description: string +scope?: string +breaking: boolean +commits: CommitRef[] +references: IssueRef[] } class CommitRef { +hash: string +url?: string } class IssueRef { +number: number +type: "issue" | "pull-request" +url?: string } class ChangelogMetadata { +format: ChangelogFormat +isConventional: boolean +repositoryUrl?: string +packageName?: string +warnings: string[] } Changelog --> ChangelogHeader Changelog --> ChangelogEntry Changelog --> ChangelogMetadata ChangelogHeader --> ChangelogLink ChangelogEntry --> ChangelogSection ChangelogSection --> ChangelogItem ChangelogItem --> CommitRef ChangelogItem --> IssueRef ``` ## Parse Pipeline ```mermaid flowchart LR A[Markdown String] --> B["tokenize()"] B --> C[Token Stream] C --> D["parseChangelog()"] D --> E[Changelog Object] subgraph Tokens C --> T1[HEADER] C --> T2[ENTRY_HEADING] C --> T3[SECTION_HEADING] C --> T4[LIST_ITEM] C --> T5[PARAGRAPH] C --> T6[LINK_DEFINITION] end ``` ## Section Types The module recognizes these standard changelog section types: | Type | Common Headings | | --------------------------------------------------------------------------------------------------------------------- | -------------------------- | | [`breaking`](https://www.hyperfrontend.dev/docs/libraries/versioning/changelog/models/#api-ChangelogSectionType) | Breaking Changes, BREAKING | | [`features`](https://www.hyperfrontend.dev/docs/libraries/versioning/changelog/models/#api-ChangelogSectionType) | Features, Added, New | | [`fixes`](https://www.hyperfrontend.dev/docs/libraries/versioning/changelog/models/#api-ChangelogSectionType) | Bug Fixes, Fixed | | `performance` | Performance, Perf | | [`documentation`](https://www.hyperfrontend.dev/docs/libraries/versioning/changelog/models/#api-ChangelogSectionType) | Documentation, Docs | | [`deprecations`](https://www.hyperfrontend.dev/docs/libraries/versioning/changelog/models/#api-ChangelogSectionType) | Deprecated | | [`refactoring`](https://www.hyperfrontend.dev/docs/libraries/versioning/changelog/models/#api-ChangelogSectionType) | Refactored, Refactor | | [`tests`](https://www.hyperfrontend.dev/docs/libraries/versioning/changelog/models/#api-ChangelogSectionType) | Tests, Testing | | [`build`](https://www.hyperfrontend.dev/docs/libraries/versioning/changelog/models/#api-ChangelogSectionType) | Build, Dependencies | | [`ci`](https://www.hyperfrontend.dev/docs/libraries/versioning/changelog/models/#api-ChangelogSectionType) | CI, Continuous Integration | | [`chores`](https://www.hyperfrontend.dev/docs/libraries/versioning/changelog/models/#api-ChangelogSectionType) | Chores, Misc | | [`other`](https://www.hyperfrontend.dev/docs/libraries/versioning/changelog/models/#api-ChangelogSectionType) | Other (fallback) | ## Usage Examples ### Parsing a Changelog ```typescript import { parseChangelog } from '@hyperfrontend/versioning' const markdown = ` # Changelog ## [1.0.0] - 2024-01-15 ### Features - Initial release ` const changelog = parseChangelog(markdown) ``` ### Creating a Changelog Programmatically ```typescript import { createChangelog, createChangelogEntry, createChangelogSection, createChangelogItem } from '@hyperfrontend/versioning' const changelog = createChangelog({ header: { title: '# Changelog', description: [], links: [] }, entries: [ createChangelogEntry('1.0.0', { date: '2024-01-15', sections: [createChangelogSection('features', 'Features', [createChangelogItem('Initial release')])], }), ], metadata: { format: 'keep-a-changelog', isConventional: false, warnings: [] }, }) ``` ### Serializing to Markdown ```typescript import { serializeChangelog } from '@hyperfrontend/versioning' const markdown = serializeChangelog(changelog, { includeScope: true, useAsterisks: false, }) ``` ### Comparing Changelogs ```typescript import { isChangelogEqual, diffChangelogs } from '@hyperfrontend/versioning' const areEqual = isChangelogEqual(changelog1, changelog2) const diff = diffChangelogs(changelog1, changelog2) ``` ### Filtering Entries ```typescript import { filterByVersionRange, filterBreakingChanges } from '@hyperfrontend/versioning' const recent = filterByVersionRange(changelog, '1.0.0', '2.0.0') const breaking = filterBreakingChanges(changelog) ``` ### Merging Changelogs ```typescript import { mergeChangelogs } from '@hyperfrontend/versioning' const result = mergeChangelogs(source, target, { entryStrategy: 'union', sectionStrategy: 'union', itemStrategy: 'union', }) ``` ### Transforming Entries ```typescript import { transformEntries, sortEntries, compact } from '@hyperfrontend/versioning' const updated = transformEntries(changelog, (entry) => ({ ...entry, date: entry.date ?? new Date().toISOString().split('T')[0], })) const sorted = sortEntries(updated) const cleaned = compact(sorted) ``` ## Merge Strategies ```mermaid flowchart TB subgraph Strategies direction TB S[source] --> |"Keep source value"| R1[Result] T[target] --> |"Keep target value"| R2[Result] U[union] --> |"Combine both"| R3[Result] L[latest] --> |"Prefer newer"| R4[Result] end ``` | Strategy | Entry Behavior | Section Behavior | Item Behavior | | ----------------------------------------------------------------------------------------------------------- | --------------------- | ------------------ | ---------------------- | | [`source`](https://www.hyperfrontend.dev/docs/libraries/versioning/changelog/operations/#api-MergeStrategy) | Use source entry | Use source section | Use source item | | [`target`](https://www.hyperfrontend.dev/docs/libraries/versioning/changelog/operations/#api-MergeStrategy) | Use target entry | Use target section | Use target item | | [`union`](https://www.hyperfrontend.dev/docs/libraries/versioning/changelog/#api-MergeStrategy) | Include both (unique) | Combine sections | Combine items | | [`latest`](https://www.hyperfrontend.dev/docs/libraries/versioning/changelog/#api-MergeStrategy) | Use newer entry | Merge by type | Replace by description | ## Design Principles 1. **Immutability**: All operations return new objects; inputs are never mutated 2. **No Regex**: Character-by-character parsing to prevent ReDoS vulnerabilities 3. **Functional**: Pure functions without class-based state 4. **Lossless**: Round-trip parsing preserves original formatting where possible 5. **Type-Safe**: Full TypeScript support with strict typing ## See Also - [semver/](https://www.hyperfrontend.dev/docs/libraries/versioning/semver.md): Version parsing and comparison - [commits/](https://www.hyperfrontend.dev/docs/libraries/versioning/commits.md): Generates changelog entries from commits - [flow/](https://www.hyperfrontend.dev/docs/libraries/versioning/flow.md): Orchestrates changelog generation - [workspace/](https://www.hyperfrontend.dev/docs/libraries/versioning/workspace.md): Discovers changelog files - [Main README](https://www.hyperfrontend.dev/docs/libraries/versioning/../): Package overview and quick start - [ARCHITECTURE.md](https://www.hyperfrontend.dev/docs/libraries/versioning/architecture.md): Design principles and data flow ## API Reference ### Functions #### addEntry ```typescript function addEntry(changelog: Changelog, entry: ChangelogEntry, options?: AddEntryOptions): Changelog ``` Adds a new entry to a changelog. **Parameters** | Name | Type | Description | | --- | --- | --- | | `changelog` | `Changelog` | The changelog to add to | | `entry` | `ChangelogEntry` | The entry to add | | `options?` | `AddEntryOptions` | Optional add options | **Returns** `Changelog`: A new changelog with the entry added **Example: Adding a new entry to a changelog** ```ts const newChangelog = addEntry(changelog, { version: '1.2.0', date: '2024-01-15', unreleased: false, sections: [...] }) ``` #### addItemToEntry ```typescript function addItemToEntry(changelog: Changelog, version: string, sectionType: string, item: ChangelogItem): Changelog ``` Adds an item to a specific section within an entry. **Parameters** | Name | Type | Description | | --- | --- | --- | | `changelog` | `Changelog` | The changelog containing the entry to modify | | `version` | `string` | The version identifier of the entry to update | | `sectionType` | `string` | Category identifier for grouping changes (e.g., 'features', 'fixes') | | `item` | `ChangelogItem` | Description of the change with optional scope and metadata | **Returns** `Changelog`: A new changelog with the item added **Example: Adding a feature item to an entry** ```typescript const item = { description: 'Add dark mode support', scope: 'ui' } const updated = addItemToEntry(changelog, '1.2.0', 'features', item) // Item added to the features section of version 1.2.0 ``` #### addUnreleasedEntry ```typescript function addUnreleasedEntry(changelog: Changelog, sections: unknown): Changelog ``` Adds or updates an unreleased entry. **Parameters** | Name | Type | Description | | --- | --- | --- | | `changelog` | `Changelog` | The changelog to add the unreleased entry to | | `sections` | `unknown` | Sections to include in the unreleased entry | **Returns** `Changelog`: A new changelog with unreleased entry added/updated **Example: Adding an unreleased entry with sections** ```typescript const sections = [createChangelogSection('features', 'Added', [item])] const updated = addUnreleasedEntry(changelog, sections) // => Changelog with unreleased entry at the top ``` #### appendChangelog ```typescript function appendChangelog(source: Changelog, target: Changelog, position: "start" | "end"): Changelog ``` Appends entries from target to source (no conflict resolution). **Parameters** | Name | Type | Description | | --- | --- | --- | | `source` | `Changelog` | The base changelog to append to | | `target` | `Changelog` | The changelog whose entries will be appended | | `position` | `"start" \| "end"` | Where to insert ('start' or 'end') (default: `'end'`) | **Returns** `Changelog`: A new changelog with combined entries **Example: Appending entries to a changelog** ```typescript const combined = appendChangelog(mainChangelog, newChangelog, 'start') // newChangelog entries appear before mainChangelog entries ``` #### checkSchemaCompatibility ```typescript function checkSchemaCompatibility(source: Changelog, target: Changelog): CompatibilityResult ``` Checks if two changelogs have compatible schemas. Used to detect format incompatibilities before merge/compare. **Parameters** | Name | Type | Description | | --- | --- | --- | | `source` | `Changelog` | The source changelog | | `target` | `Changelog` | The target changelog | **Returns** `CompatibilityResult`: Compatibility result with any differences found **Example: Checking schema compatibility before merge** ```ts const result = checkSchemaCompatibility(mainChangelog, branchChangelog) if (!result.compatible) { console.log('Schema differences:', result.differences) } ``` #### cloneChangelog ```typescript function cloneChangelog(changelog: Changelog): Changelog ``` Clones a changelog deeply (for modification without affecting original). **Parameters** | Name | Type | Description | | --- | --- | --- | | `changelog` | `Changelog` | The changelog to clone | **Returns** `Changelog`: A deep copy of the changelog **Example: Cloning a changelog** ```typescript const copy = cloneChangelog(changelog) // Independent deep copy, safe to mutate ``` #### combineChangelogs ```typescript function combineChangelogs(changelogs: unknown, options?: MergeOptions): Changelog ``` Combines multiple changelogs into one. **Parameters** | Name | Type | Description | | --- | --- | --- | | `changelogs` | `unknown` | Array of changelogs to combine | | `options?` | `MergeOptions` | Optional merge options | **Returns** `Changelog`: The combined changelog **Example: Combining multiple changelogs** ```typescript const unified = combineChangelogs([pkg1Changelog, pkg2Changelog], { strategy: 'merge-sections', }) // All entries from both changelogs merged with conflict resolution ``` #### compact ```typescript function compact(changelog: Changelog, keepUnreleased: boolean): Changelog ``` Compacts a changelog by removing empty sections and entries. **Parameters** | Name | Type | Description | | --- | --- | --- | | `changelog` | `Changelog` | The changelog to compact | | `keepUnreleased` | `boolean` | Whether to keep empty unreleased entry (default: true) (default: `true`) | **Returns** `Changelog`: A new compacted changelog **Example: Compacting a changelog** ```typescript const compacted = compact(changelog) // Empty sections and entries removed (unreleased kept) const strict = compact(changelog, false) // Even empty unreleased entry is removed ``` #### createChangelog ```typescript function createChangelog(options?: Partial): Changelog ``` Creates a new changelog with default values. **Parameters** | Name | Type | Description | | --- | --- | --- | | `options?` | `Partial` | Optional configuration to customize the changelog | **Returns** `Changelog`: A new Changelog object with the specified options or defaults **Example: Creating a changelog with custom source** ```typescript const changelog = createChangelog({ source: 'CHANGELOG.md' }) // => { source: 'CHANGELOG.md', header: { title: '# Changelog', ... }, entries: [] } ``` #### createChangelogEntry ```typescript function createChangelogEntry(version: string, options?: Partial>): ChangelogEntry ``` Creates a new changelog entry. **Parameters** | Name | Type | Description | | --- | --- | --- | | `version` | `string` | The version string (e.g., '1.0.0') | | `options?` | `Partial>` | Optional configuration for date, sections, and other properties | **Returns** `ChangelogEntry`: A new ChangelogEntry object **Example: Creating a changelog entry with date and sections** ```typescript const entry = createChangelogEntry('1.0.0', { date: '2024-01-15', sections: [createChangelogSection('features', 'Added', items)], }) ``` #### createChangelogItem ```typescript function createChangelogItem(description: string, options?: Partial>): ChangelogItem ``` Creates a new changelog item. **Parameters** | Name | Type | Description | | --- | --- | --- | | `description` | `string` | The description text of the change | | `options?` | `Partial>` | Optional configuration for scope, commits, references, and breaking flag | **Returns** `ChangelogItem`: A new ChangelogItem object **Example: Creating a changelog item with options** ```typescript const item = createChangelogItem('Add user authentication', { scope: 'auth', breaking: false, references: [{ number: 42, type: 'issue' }], }) ``` #### createChangelogLink ```typescript function createChangelogLink(label: string, url: string): ChangelogLink ``` Creates a changelog link. **Parameters** | Name | Type | Description | | --- | --- | --- | | `label` | `string` | The display text for the link | | `url` | `string` | The URL the link points to | **Returns** `ChangelogLink`: A new ChangelogLink object **Example: Creating a version comparison link** ```typescript const link = createChangelogLink('1.0.0', 'https://github.com/org/repo/compare/v0.9.0...v1.0.0') // => { label: '1.0.0', url: 'https://github.com/...' } ``` #### createChangelogSection ```typescript function createChangelogSection(type: ChangelogSectionType, heading: string, items: unknown): ChangelogSection ``` Creates a new changelog section. **Parameters** | Name | Type | Description | | --- | --- | --- | | `type` | `ChangelogSectionType` | The type of section (features, fixes, breaking, etc.) | | `heading` | `string` | The display heading for the section | | `items` | `unknown` | Optional array of changelog items in this section (default: `[]`) | **Returns** `ChangelogSection`: A new ChangelogSection object **Example: Creating a features section with items** ```typescript const section = createChangelogSection('features', 'Added', [ createChangelogItem('New dashboard widget'), ]) ``` #### createCommitRef ```typescript function createCommitRef(hash: string, url?: string): CommitRef ``` Creates a commit reference from a full hash. **Parameters** | Name | Type | Description | | --- | --- | --- | | `hash` | `string` | The full commit hash | | `url?` | `string` | Optional URL to the commit | **Returns** `CommitRef`: A new CommitRef object with both full and short hash **Example: Creating a commit reference** ```typescript const ref = createCommitRef('abc1234def5678', 'https://github.com/org/repo/commit/abc1234def5678') // => { hash: 'abc1234def5678', shortHash: 'abc1234', url: 'https://...' } ``` #### createEmptyChangelog ```typescript function createEmptyChangelog(): Changelog ``` Creates a new empty changelog with standard header. **Returns** `Changelog`: A new empty Changelog with Keep a Changelog format **Example: Creating an empty changelog with standard header** ```typescript const changelog = createEmptyChangelog() // => Changelog with standard Keep a Changelog header and no entries ``` #### createIssueRef ```typescript function createIssueRef(number: number, type: "issue" | "pull-request", url?: string): IssueRef ``` Creates an issue reference. **Parameters** | Name | Type | Description | | --- | --- | --- | | `number` | `number` | The issue or PR number | | `type` | `"issue" \| "pull-request"` | The type of reference ('issue' or 'pull-request') (default: `'issue'`) | | `url?` | `string` | Optional URL to the issue or PR | **Returns** `IssueRef`: A new IssueRef object **Example: Creating issue and PR references** ```typescript const issueRef = createIssueRef(42, 'issue', 'https://github.com/org/repo/issues/42') // => { number: 42, type: 'issue', url: 'https://...' } const prRef = createIssueRef(123, 'pull-request') // => { number: 123, type: 'pull-request', url: undefined } ``` #### createSpacing ```typescript function createSpacing(count: number, lineEnding: string): string ``` Creates blank lines for spacing. **Parameters** | Name | Type | Description | | --- | --- | --- | | `count` | `number` | Number of blank lines | | `lineEnding` | `string` | Line ending style | **Returns** `string`: String with specified number of blank lines **Example: Creating blank line spacing** ```typescript createSpacing(2, '\n') // => '\n\n' ``` #### createUnreleasedEntry ```typescript function createUnreleasedEntry(sections: unknown): ChangelogEntry ``` Creates an unreleased changelog entry. **Parameters** | Name | Type | Description | | --- | --- | --- | | `sections` | `unknown` | Optional array of changelog sections (default: `[]`) | **Returns** `ChangelogEntry`: A new ChangelogEntry object marked as unreleased **Example: Creating an unreleased entry** ```typescript const unreleased = createUnreleasedEntry([ createChangelogSection('features', 'Added', [item]), ]) // => { version: 'Unreleased', date: null, unreleased: true, sections: [...] } ``` #### deduplicateItems ```typescript function deduplicateItems(changelog: Changelog): Changelog ``` Removes duplicate items across all sections. **Parameters** | Name | Type | Description | | --- | --- | --- | | `changelog` | `Changelog` | The changelog to deduplicate | **Returns** `Changelog`: A new changelog without duplicate items **Example: Deduplicating items across sections** ```typescript const deduped = deduplicateItems(changelog) // Duplicate items (same scope:description) are removed ``` #### diffChangelogs ```typescript function diffChangelogs(source: Changelog, target: Changelog): ChangelogDiff ``` Computes the diff between two changelogs. **Parameters** | Name | Type | Description | | --- | --- | --- | | `source` | `Changelog` | The source/original changelog | | `target` | `Changelog` | The target/modified changelog | **Returns** `ChangelogDiff`: Detailed diff of changes **Example: Comparing two changelogs** ```ts const diff = diffChangelogs(mainChangelog, branchChangelog) console.log(`Added: ${diff.added.length}, Removed: ${diff.removed.length}`) ``` #### diffEntries ```typescript function diffEntries(source: ChangelogEntry, target: ChangelogEntry): EntryDiff ``` Computes the diff between two changelog entries. **Parameters** | Name | Type | Description | | --- | --- | --- | | `source` | `ChangelogEntry` | The source entry | | `target` | `ChangelogEntry` | The target entry | **Returns** `EntryDiff`: Detailed entry diff **Example: Computing diff between two entries** ```typescript const diff = diffEntries(entryV1, entryV2) // => { version: '1.0.0', changes: [{ path: ['date'], type: 'changed', ... }], sectionsChanged: true } ``` #### excludeByScope ```typescript function excludeByScope(changelog: Changelog, scopes: unknown): Changelog ``` Excludes items by scope. **Parameters** | Name | Type | Description | | --- | --- | --- | | `changelog` | `Changelog` | The changelog to filter | | `scopes` | `unknown` | Scopes to exclude | **Returns** `Changelog`: A new changelog without items matching the scopes **Example: Excluding items by scope** ```typescript const publicChanges = excludeByScope(changelog, ['internal', 'test']) // Items scoped to 'internal' or 'test' are removed ``` #### filterBreakingChanges ```typescript function filterBreakingChanges(changelog: Changelog): Changelog ``` Filters entries that have breaking changes. **Parameters** | Name | Type | Description | | --- | --- | --- | | `changelog` | `Changelog` | The changelog to filter | **Returns** `Changelog`: A new changelog with only entries containing breaking changes **Example: Filtering for breaking changes** ```typescript const breaking = filterBreakingChanges(changelog) // Only entries containing breaking changes or items marked as breaking ``` #### filterByDateRange ```typescript function filterByDateRange(changelog: Changelog, startDate?: string, endDate?: string): Changelog ``` Filters entries by release date. **Parameters** | Name | Type | Description | | --- | --- | --- | | `changelog` | `Changelog` | The changelog to filter | | `startDate?` | `string` | Start date (inclusive, ISO format) | | `endDate?` | `string` | End date (inclusive, ISO format) | **Returns** `Changelog`: A new changelog with entries in the date range **Example: Filtering entries by date range** ```typescript const q1 = filterByDateRange(changelog, '2024-01-01', '2024-03-31') // Entries released in Q1 2024 ``` #### filterByScope ```typescript function filterByScope(changelog: Changelog, scopes: unknown): Changelog ``` Filters items by scope. **Parameters** | Name | Type | Description | | --- | --- | --- | | `changelog` | `Changelog` | The changelog to filter | | `scopes` | `unknown` | Scopes to include | **Returns** `Changelog`: A new changelog with only items matching the scopes **Example: Filtering items by scope** ```typescript const apiChanges = filterByScope(changelog, ['api', 'core']) // Only items scoped to 'api' or 'core' ``` #### filterByVersionRange ```typescript function filterByVersionRange(changelog: Changelog, range: string): Changelog ``` Filters entries by version range using semver. **Parameters** | Name | Type | Description | | --- | --- | --- | | `changelog` | `Changelog` | The changelog to filter | | `range` | `string` | Semver range string (e.g., '>=1.0.0 <2.0.0') | **Returns** `Changelog`: A new changelog with entries matching the range **Example: Filtering by semver range** ```ts const majors = filterByVersionRange(changelog, '>=1.0.0 <2.0.0') ``` #### filterEntries ```typescript function filterEntries(changelog: Changelog, predicate: EntryPredicate): Changelog ``` Filters entries using a predicate function. **Parameters** | Name | Type | Description | | --- | --- | --- | | `changelog` | `Changelog` | The changelog to filter | | `predicate` | `EntryPredicate` | Function that returns true for entries to keep | **Returns** `Changelog`: A new changelog with filtered entries **Example: Filtering out unreleased entries** ```ts const filtered = filterEntries(changelog, (entry) => !entry.unreleased) ``` #### filterFromVersion ```typescript function filterFromVersion(changelog: Changelog, startVersion: string): Changelog ``` Filters entries from a start version. **Parameters** | Name | Type | Description | | --- | --- | --- | | `changelog` | `Changelog` | The changelog to filter | | `startVersion` | `string` | The minimum version (inclusive) | **Returns** `Changelog`: A new changelog with entries >= startVersion **Example: Filtering from a start version** ```typescript const recent = filterFromVersion(changelog, '2.0.0') // Only entries for version 2.0.0 and later ``` #### filterItems ```typescript function filterItems(changelog: Changelog, predicate: ItemPredicate): Changelog ``` Filters items within sections. **Parameters** | Name | Type | Description | | --- | --- | --- | | `changelog` | `Changelog` | The changelog to filter | | `predicate` | `ItemPredicate` | Function that returns true for items to keep | **Returns** `Changelog`: A new changelog with filtered items **Example: Filtering items with references** ```typescript const withRefs = filterItems(changelog, (item) => item.references.length > 0) // Only items with issue/PR references ``` #### filterRecentEntries ```typescript function filterRecentEntries(changelog: Changelog, count: number, includeUnreleased: boolean): Changelog ``` Gets the N most recent entries. **Parameters** | Name | Type | Description | | --- | --- | --- | | `changelog` | `Changelog` | The changelog to filter | | `count` | `number` | Number of entries to keep | | `includeUnreleased` | `boolean` | Whether to include unreleased in count (default: false) (default: `false`) | **Returns** `Changelog`: A new changelog with only the most recent entries **Example: Getting the most recent entries** ```typescript const latest = filterRecentEntries(changelog, 5) // Last 5 released versions (plus unreleased if present) ``` #### filterSections ```typescript function filterSections(changelog: Changelog, predicate: SectionPredicate): Changelog ``` Filters sections within each entry. **Parameters** | Name | Type | Description | | --- | --- | --- | | `changelog` | `Changelog` | The changelog to filter | | `predicate` | `SectionPredicate` | Function that returns true for sections to keep | **Returns** `Changelog`: A new changelog with filtered sections **Example: Filtering for user-facing sections** ```typescript const userFacing = filterSections(changelog, (section) => ['features', 'fixes', 'breaking'].includes(section.type) ) ``` #### filterSectionTypes ```typescript function filterSectionTypes(changelog: Changelog, types: unknown): Changelog ``` Keeps only specified section types. **Parameters** | Name | Type | Description | | --- | --- | --- | | `changelog` | `Changelog` | The changelog to filter | | `types` | `unknown` | Section types to keep | **Returns** `Changelog`: A new changelog with only specified section types **Example: Filtering to specific section types** ```typescript const userChanges = filterSectionTypes(changelog, ['features', 'fixes']) // Only features and fixes sections remain ``` #### filterToVersion ```typescript function filterToVersion(changelog: Changelog, endVersion: string): Changelog ``` Filters entries up to an end version. **Parameters** | Name | Type | Description | | --- | --- | --- | | `changelog` | `Changelog` | The changelog to apply the version filter to | | `endVersion` | `string` | The maximum version (inclusive) | **Returns** `Changelog`: A new changelog with entries <= endVersion **Example: Filtering to an end version** ```typescript const legacy = filterToVersion(changelog, '1.9.9') // Only entries for versions up to 1.9.9 ``` #### filterVersionRange ```typescript function filterVersionRange(changelog: Changelog, startVersion: string, endVersion: string): Changelog ``` Gets entries within a version range (inclusive). **Parameters** | Name | Type | Description | | --- | --- | --- | | `changelog` | `Changelog` | The changelog to filter | | `startVersion` | `string` | The minimum version (inclusive) | | `endVersion` | `string` | The maximum version (inclusive) | **Returns** `Changelog`: A new changelog with entries in the range **Example: Filtering entries within a version range** ```typescript const range = filterVersionRange(changelog, '1.5.0', '2.0.0') // Entries from 1.5.0 through 2.0.0 ``` #### formatLink ```typescript function formatLink(text: string, url: string): string ``` Creates a markdown link. **Parameters** | Name | Type | Description | | --- | --- | --- | | `text` | `string` | The display text for the link | | `url` | `string` | The destination URL for the link | **Returns** `string`: Formatted markdown link **Example: Formatting a markdown link** ```typescript formatLink('1.0.0', 'https://github.com/org/repo/releases/tag/v1.0.0') // => '[1.0.0](https://github.com/org/repo/releases/tag/v1.0.0)' ``` #### getEntryByVersion ```typescript function getEntryByVersion(changelog: Changelog, version: string): ChangelogEntry ``` Gets an entry by version from a changelog. **Parameters** | Name | Type | Description | | --- | --- | --- | | `changelog` | `Changelog` | The changelog to search | | `version` | `string` | The version to find | **Returns** `ChangelogEntry`: The entry if found, undefined otherwise **Example: Getting an entry by version** ```typescript const entry = getEntryByVersion(changelog, '1.0.0') // => ChangelogEntry for 1.0.0 or undefined ``` #### getListMarker ```typescript function getListMarker(useAsterisks: boolean): string ``` Creates a list item marker. **Parameters** | Name | Type | Description | | --- | --- | --- | | `useAsterisks` | `boolean` | Whether to use * instead of - | **Returns** `string`: The list item marker ('- ' or '* ') **Example: Getting list markers** ```typescript getListMarker(false) // => '- ' getListMarker(true) // => '* ' ``` #### getSectionHeading ```typescript function getSectionHeading(type: ChangelogSectionType, customHeadings?: Partial>): string ``` Gets the heading for a section type, respecting custom headings. **Parameters** | Name | Type | Description | | --- | --- | --- | | `type` | `ChangelogSectionType` | The changelog section type to get the heading for | | `customHeadings?` | `Partial>` | Optional map of custom section type to heading overrides | **Returns** `string`: The heading string to use **Example: Getting section headings** ```typescript getSectionHeading('features') // => 'Added' getSectionHeading('features', { features: 'New Features' }) // => 'New Features' ``` #### getSectionType ```typescript function getSectionType(heading: string): ChangelogSectionType ``` Determines the section type from a heading string. Returns 'other' if the heading is not recognized. **Parameters** | Name | Type | Description | | --- | --- | --- | | `heading` | `string` | The heading string to parse | **Returns** `ChangelogSectionType`: The corresponding ChangelogSectionType **Example: Mapping heading strings to section types** ```typescript getSectionType('Added') // => 'features' getSectionType('Bug Fixes') // => 'fixes' getSectionType('Custom Section') // => 'other' ``` #### getShortHash ```typescript function getShortHash(hash: string): string ``` Extracts the short hash from a full commit hash. **Parameters** | Name | Type | Description | | --- | --- | --- | | `hash` | `string` | The full commit hash | **Returns** `string`: The first 7 characters of the hash **Example: Extracting short hash from full hash** ```typescript getShortHash('abc1234def5678901234567890') // => 'abc1234' ``` #### hasVersion ```typescript function hasVersion(changelog: Changelog, version: string): boolean ``` Checks if a changelog contains a specific version. **Parameters** | Name | Type | Description | | --- | --- | --- | | `changelog` | `Changelog` | The changelog to search | | `version` | `string` | The version to look for | **Returns** `boolean`: True if the version exists in the changelog **Example: Checking if a changelog contains a version** ```typescript hasVersion(changelog, '2.0.0') // => true if an entry for version 2.0.0 exists ``` #### haveSameVersions ```typescript function haveSameVersions(a: Changelog, b: Changelog): boolean ``` Checks if two changelogs have the same entries (by version). Does not compare entry contents, only versions present. **Parameters** | Name | Type | Description | | --- | --- | --- | | `a` | `Changelog` | First changelog | | `b` | `Changelog` | Second changelog | **Returns** `boolean`: True if both changelogs have the same versions **Example: Checking if changelogs have the same versions** ```typescript haveSameVersions(changelog1, changelog2) // => true if both have entries for the same version strings ``` #### isChangelogEqual ```typescript function isChangelogEqual(a: Changelog, b: Changelog): boolean ``` Checks if two changelogs are structurally identical. **Parameters** | Name | Type | Description | | --- | --- | --- | | `a` | `Changelog` | First changelog | | `b` | `Changelog` | Second changelog | **Returns** `boolean`: True if changelogs are identical **Example: Checking changelog equality** ```ts if (isChangelogEqual(mainChangelog, branchChangelog)) { console.log('Changelogs are identical') } ``` #### isCommitRefEqual ```typescript function isCommitRefEqual(a: CommitRef, b: CommitRef): boolean ``` Checks if two commit references are equal. **Parameters** | Name | Type | Description | | --- | --- | --- | | `a` | `CommitRef` | First commit ref | | `b` | `CommitRef` | Second commit ref | **Returns** `boolean`: True if commit refs are equal **Example: Comparing commit references** ```typescript isCommitRefEqual(commitA, commitB) // => true if hash, shortHash, and url match ``` #### isEntryContentEqual ```typescript function isEntryContentEqual(a: ChangelogEntry, b: ChangelogEntry): boolean ``` Checks if two changelog entries describe the same release. The date and the compare URL are stamped when an entry is generated: the date is the day of generation and the compare URL ends at whatever commit was HEAD. Neither is derived from the commits the entry describes, so an entry regenerated later for the same release differs in both while saying exactly the same thing. This comparison reads the version, the unreleased flag, the raw content, and the sections, which is what a release's changelog entry asserts about the commits behind it. **Parameters** | Name | Type | Description | | --- | --- | --- | | `a` | `ChangelogEntry` | First entry | | `b` | `ChangelogEntry` | Second entry | **Returns** `boolean`: True if both entries carry the same version and sections **Example: Validating a committed entry against one regenerated today** ```typescript isEntryContentEqual(committedEntry, regeneratedEntry) // => true even though the dates and compare URLs differ ``` #### isEntryEqual ```typescript function isEntryEqual(a: ChangelogEntry, b: ChangelogEntry): boolean ``` Checks if two changelog entries are equal. **Parameters** | Name | Type | Description | | --- | --- | --- | | `a` | `ChangelogEntry` | First entry | | `b` | `ChangelogEntry` | Second entry | **Returns** `boolean`: True if entries are equal **Example: Comparing changelog entries** ```typescript isEntryEqual(entryA, entryB) // => true if version, date, sections, and all nested data match ``` #### isHeaderEqual ```typescript function isHeaderEqual(a: ChangelogHeader, b: ChangelogHeader): boolean ``` Checks if two changelog headers are equal. **Parameters** | Name | Type | Description | | --- | --- | --- | | `a` | `ChangelogHeader` | First header | | `b` | `ChangelogHeader` | Second header | **Returns** `boolean`: True if headers are equal **Example: Comparing changelog headers** ```typescript isHeaderEqual(changelog1.header, changelog2.header) // => true if titles, descriptions, and links match ``` #### isIssueRefEqual ```typescript function isIssueRefEqual(a: IssueRef, b: IssueRef): boolean ``` Checks if two issue references are equal. **Parameters** | Name | Type | Description | | --- | --- | --- | | `a` | `IssueRef` | First issue ref | | `b` | `IssueRef` | Second issue ref | **Returns** `boolean`: True if issue refs are equal **Example: Comparing issue references** ```typescript isIssueRefEqual({ number: 42, type: 'issue' }, { number: 42, type: 'issue' }) // => true ``` #### isItemEqual ```typescript function isItemEqual(a: ChangelogItem, b: ChangelogItem): boolean ``` Checks if two changelog items are equal. **Parameters** | Name | Type | Description | | --- | --- | --- | | `a` | `ChangelogItem` | First item | | `b` | `ChangelogItem` | Second item | **Returns** `boolean`: True if items are equal **Example: Comparing changelog items** ```typescript isItemEqual(itemA, itemB) // => true if description, scope, breaking, commits, and references match ``` #### isLinkEqual ```typescript function isLinkEqual(a: ChangelogLink, b: ChangelogLink): boolean ``` Checks if two changelog links are equal. **Parameters** | Name | Type | Description | | --- | --- | --- | | `a` | `ChangelogLink` | First link | | `b` | `ChangelogLink` | Second link | **Returns** `boolean`: True if links are equal **Example: Comparing changelog links** ```typescript isLinkEqual({ label: '1.0.0', url: '...' }, { label: '1.0.0', url: '...' }) // => true ``` #### isMetadataEqual ```typescript function isMetadataEqual(a: ChangelogMetadata, b: ChangelogMetadata): boolean ``` Checks if two changelog metadata objects are equal. **Parameters** | Name | Type | Description | | --- | --- | --- | | `a` | `ChangelogMetadata` | First metadata | | `b` | `ChangelogMetadata` | Second metadata | **Returns** `boolean`: True if metadata are equal **Example: Comparing changelog metadata** ```typescript isMetadataEqual(changelog1.metadata, changelog2.metadata) // => true if format, isConventional, repositoryUrl, and warnings match ``` #### isSectionEqual ```typescript function isSectionEqual(a: ChangelogSection, b: ChangelogSection): boolean ``` Checks if two changelog sections are equal. **Parameters** | Name | Type | Description | | --- | --- | --- | | `a` | `ChangelogSection` | First section | | `b` | `ChangelogSection` | Second section | **Returns** `boolean`: True if sections are equal **Example: Comparing changelog sections** ```typescript isSectionEqual(featuresA, featuresB) // => true if type, heading, and all items match ``` #### mergeChangelogs ```typescript function mergeChangelogs(source: Changelog, target: Changelog, options?: MergeOptions): MergeResult ``` Merges two changelogs together. **Parameters** | Name | Type | Description | | --- | --- | --- | | `source` | `Changelog` | The source changelog | | `target` | `Changelog` | The target changelog | | `options?` | `MergeOptions` | Optional merge options | **Returns** `MergeResult`: The merge result with merged changelog and stats **Example: Merging two changelogs** ```ts const result = mergeChangelogs(mainChangelog, branchChangelog) console.log(`Merged ${result.stats.merged} entries`) ``` #### normalizeSectionHeadings ```typescript function normalizeSectionHeadings(changelog: Changelog): Changelog ``` Normalizes section headings to standard format. **Parameters** | Name | Type | Description | | --- | --- | --- | | `changelog` | `Changelog` | The changelog to normalize | **Returns** `Changelog`: A new changelog with normalized section headings **Example: Normalizing section headings** ```typescript const normalized = normalizeSectionHeadings(changelog) // 'New Features' becomes 'Added', 'Bug Fixes' becomes 'Fixed', etc. ``` #### parseChangelog ```typescript function parseChangelog(content: string, source?: string): Changelog ``` Parses a changelog markdown string into a Changelog object. **Parameters** | Name | Type | Description | | --- | --- | --- | | `content` | `string` | The markdown content to parse | | `source?` | `string` | Optional source file path | **Returns** `Changelog`: Parsed Changelog object **Example: Parsing a changelog markdown string** ```typescript const markdown = `# Changelog ## [1.0.0] - 2024-01-15 ### Added - Initial release` const changelog = parseChangelog(markdown, 'CHANGELOG.md') // => { header: { title: '# Changelog', ... }, entries: [{ version: '1.0.0', ... }] } ``` #### parseCommitRefs ```typescript function parseCommitRefs(text: string, baseUrl?: string): CommitRef[] ``` Parses commit references from a line. Examples: (abc1234), [abc1234], commit abc1234 **Parameters** | Name | Type | Description | | --- | --- | --- | | `text` | `string` | The text to parse for commit references | | `baseUrl?` | `string` | Optional base URL for constructing commit links | **Returns** `CommitRef[]`: An array of parsed CommitRef objects **Example: Parsing commit references from text** ```typescript parseCommitRefs('Fixed bug (abc1234)', 'https://github.com/org/repo') // => [{ hash: 'abc1234', shortHash: 'abc1234', url: 'https://github.com/org/repo/commit/abc1234' }] ``` #### parseIssueRefs ```typescript function parseIssueRefs(text: string, baseUrl?: string): IssueRef[] ``` Parses issue/PR references from a line. Examples: #123, GH-123, closes #123 **Parameters** | Name | Type | Description | | --- | --- | --- | | `text` | `string` | The text to parse for issue references | | `baseUrl?` | `string` | Optional base URL for constructing issue links | **Returns** `IssueRef[]`: An array of parsed IssueRef objects **Example: Parsing issue references from text** ```typescript parseIssueRefs('Closes #42 and PR #123', 'https://github.com/org/repo') // => [{ number: 42, type: 'issue', url: '...' }, { number: 123, type: 'pull-request', url: '...' }] ``` #### parseScopeFromItem ```typescript function parseScopeFromItem(text: string): ScopeFromItem ``` Parses the scope from a changelog item. Example: "**scope:** description" -> { scope: "scope", description: "description" } **Parameters** | Name | Type | Description | | --- | --- | --- | | `text` | `string` | The text to parse for scope | **Returns** `ScopeFromItem`: An object with optional scope and the description **Example: Parsing scope from changelog items** ```typescript parseScopeFromItem('**api:** Add new endpoint') // => { scope: 'api', description: 'Add new endpoint' } parseScopeFromItem('Simple change without scope') // => { scope: undefined, description: 'Simple change without scope' } ``` #### parseVersionFromHeading ```typescript function parseVersionFromHeading(heading: string): ParsedVersionHeading ``` Parses a version string from a heading. Examples: "1.2.3", "v1.2.3", "[1.2.3]", "1.2.3 - 2024-01-01" **Parameters** | Name | Type | Description | | --- | --- | --- | | `heading` | `string` | The heading string to parse | **Returns** `ParsedVersionHeading`: An object containing the parsed version, date, and optional compareUrl **Example: Parsing version headings** ```typescript parseVersionFromHeading('[1.2.3] - 2024-01-15') // => { version: '1.2.3', date: '2024-01-15', compareUrl: undefined } parseVersionFromHeading('v2.0.0') // => { version: '2.0.0', date: null, compareUrl: undefined } ``` #### releaseUnreleased ```typescript function releaseUnreleased(changelog: Changelog, version: string, date?: string, compareUrl?: string): Changelog ``` Creates a new release entry from the current unreleased entry. **Parameters** | Name | Type | Description | | --- | --- | --- | | `changelog` | `Changelog` | The changelog containing the unreleased entry | | `version` | `string` | The version number for the release | | `date?` | `string` | The release date (defaults to today) | | `compareUrl?` | `string` | Optional comparison URL | **Returns** `Changelog`: A new changelog with the unreleased entry converted to a release **Example: Releasing unreleased changes as a new version** ```typescript const released = releaseUnreleased(changelog, '2.0.0', '2024-03-01') // Unreleased entry becomes version 2.0.0 with the specified date ``` #### removeEmptyEntries ```typescript function removeEmptyEntries(changelog: Changelog, keepUnreleased: boolean): Changelog ``` Removes empty entries (entries with no sections or only empty sections). **Parameters** | Name | Type | Description | | --- | --- | --- | | `changelog` | `Changelog` | The changelog to remove empty entries from | | `keepUnreleased` | `boolean` | Whether to keep an empty unreleased entry (default: true) (default: `true`) | **Returns** `Changelog`: A new changelog with empty entries removed **Example: Removing empty entries** ```typescript const cleaned = removeEmptyEntries(changelog) // Entries with no content are removed (unreleased kept by default) const strict = removeEmptyEntries(changelog, false) // Even empty unreleased entry is removed ``` #### removeEmptySections ```typescript function removeEmptySections(changelog: Changelog): Changelog ``` Removes empty sections from all entries. **Parameters** | Name | Type | Description | | --- | --- | --- | | `changelog` | `Changelog` | The changelog to remove empty sections from | **Returns** `Changelog`: A new changelog with empty sections removed **Example: Removing empty sections from all entries** ```typescript const cleaned = removeEmptySections(changelog) // Sections with no items are removed from all entries ``` #### removeEntries ```typescript function removeEntries(changelog: Changelog, versions: unknown, options?: RemoveEntryOptions): Changelog ``` Removes multiple entries from a changelog. **Parameters** | Name | Type | Description | | --- | --- | --- | | `changelog` | `Changelog` | The changelog to remove from | | `versions` | `unknown` | The versions to remove | | `options?` | `RemoveEntryOptions` | Optional removal options | **Returns** `Changelog`: A new changelog without the specified entries **Example: Removing multiple entries** ```typescript const cleaned = removeEntries(changelog, ['0.1.0', '0.2.0']) // Pre-release versions removed from changelog ``` #### removeEntry ```typescript function removeEntry(changelog: Changelog, version: string, options?: RemoveEntryOptions): Changelog ``` Removes an entry from a changelog by version. **Parameters** | Name | Type | Description | | --- | --- | --- | | `changelog` | `Changelog` | The changelog to remove from | | `version` | `string` | The version to remove | | `options?` | `RemoveEntryOptions` | Optional removal options | **Returns** `Changelog`: A new changelog without the specified entry **Example: Removing an entry by version** ```ts const newChangelog = removeEntry(changelog, '1.0.0') ``` #### removeItem ```typescript function removeItem(changelog: Changelog, version: string, sectionType: string, itemDescription: string, options?: RemoveSectionOptions): Changelog ``` Removes an item from an entry by description. **Parameters** | Name | Type | Description | | --- | --- | --- | | `changelog` | `Changelog` | The changelog containing the entry to modify | | `version` | `string` | The version of the entry to modify | | `sectionType` | `string` | The section type containing the item | | `itemDescription` | `string` | The description of the item to remove | | `options?` | `RemoveSectionOptions` | Optional removal options | **Returns** `Changelog`: A new changelog without the specified item **Example: Removing a specific item from a section** ```typescript const updated = removeItem(changelog, '1.0.0', 'features', 'Add dark mode') // The 'Add dark mode' item is removed from features in 1.0.0 ``` #### removeSection ```typescript function removeSection(changelog: Changelog, version: string, sectionType: string, options?: RemoveSectionOptions): Changelog ``` Removes a section from an entry. **Parameters** | Name | Type | Description | | --- | --- | --- | | `changelog` | `Changelog` | The changelog containing the entry to modify | | `version` | `string` | The version of the entry to modify | | `sectionType` | `string` | The section type to remove | | `options?` | `RemoveSectionOptions` | Optional removal options | **Returns** `Changelog`: A new changelog without the specified section **Example: Removing a deprecated section** ```typescript const updated = removeSection(changelog, '1.0.0', 'deprecated') // Version 1.0.0 no longer has a deprecated section ``` #### removeUnreleased ```typescript function removeUnreleased(changelog: Changelog, options?: RemoveEntryOptions): Changelog ``` Removes the unreleased entry if it exists. **Parameters** | Name | Type | Description | | --- | --- | --- | | `changelog` | `Changelog` | The changelog to remove the unreleased entry from | | `options?` | `RemoveEntryOptions` | Optional removal options | **Returns** `Changelog`: A new changelog without the unreleased entry **Example: Removing the unreleased entry** ```typescript const released = removeUnreleased(changelog) // Changelog without the unreleased entry // Silently ignore if not found const safe = removeUnreleased(changelog, { throwIfNotFound: false }) ``` #### resolveOptions ```typescript function resolveOptions(options?: SerializeOptions): Required ``` Merges user options with defaults. **Parameters** | Name | Type | Description | | --- | --- | --- | | `options?` | `SerializeOptions` | User-provided options | **Returns** `Required`: Complete options with defaults applied **Example: Resolving serialize options with defaults** ```typescript const opts = resolveOptions({ includeCommits: true }) // => { includeCommits: true, includeScope: true, lineEnding: '\n', ... } ``` #### reverseEntries ```typescript function reverseEntries(changelog: Changelog): Changelog ``` Reverses the order of entries. **Parameters** | Name | Type | Description | | --- | --- | --- | | `changelog` | `Changelog` | The changelog to reverse | **Returns** `Changelog`: A new changelog with reversed entries **Example: Reversing entry order** ```typescript const reversed = reverseEntries(changelog) // Oldest entries now appear first ``` #### serializeChangelog ```typescript function serializeChangelog(changelog: Changelog, options?: SerializeOptions): string ``` Serializes a Changelog object to markdown string. **Parameters** | Name | Type | Description | | --- | --- | --- | | `changelog` | `Changelog` | The changelog to serialize | | `options?` | `SerializeOptions` | Optional serialization options | **Returns** `string`: The markdown string representation **Example: Basic serialization** ```ts const markdown = serializeChangelog(changelog) ``` **Example: Serializing with custom options** ```ts const markdown = serializeChangelog(changelog, { includeCommits: false, useAsterisks: true, }) ``` #### serializeChangelogToJson ```typescript function serializeChangelogToJson(changelog: Changelog, options?: JsonSerializeOptions): string ``` Serializes a Changelog object to JSON string. **Parameters** | Name | Type | Description | | --- | --- | --- | | `changelog` | `Changelog` | The changelog object to convert to JSON | | `options?` | `JsonSerializeOptions` | Optional JSON serialization options | **Returns** `string`: The JSON string representation **Example: Basic JSON serialization** ```ts const json = serializeChangelogToJson(changelog) ``` **Example: Pretty-printing with custom indentation** ```ts const json = serializeChangelogToJson(changelog, { pretty: true, indent: 4, }) ``` #### sortEntries ```typescript function sortEntries(changelog: Changelog): Changelog ``` Sorts entries by version (descending - newest first). **Parameters** | Name | Type | Description | | --- | --- | --- | | `changelog` | `Changelog` | The changelog to sort | **Returns** `Changelog`: A new changelog with sorted entries **Example: Sorting changelog entries by version** ```typescript const sorted = sortEntries(changelog) // Entries ordered: Unreleased, 2.0.0, 1.1.0, 1.0.0, ... ``` #### sortEntriesByDate ```typescript function sortEntriesByDate(changelog: Changelog): Changelog ``` Sorts entries by date (newest first). **Parameters** | Name | Type | Description | | --- | --- | --- | | `changelog` | `Changelog` | The changelog to sort | **Returns** `Changelog`: A new changelog with sorted entries **Example: Sorting entries by date** ```typescript const sorted = sortEntriesByDate(changelog) // Entries ordered by release date, most recent first ``` #### sortSections ```typescript function sortSections(changelog: Changelog, order?: unknown): Changelog ``` Sorts sections within each entry by a specified order. **Parameters** | Name | Type | Description | | --- | --- | --- | | `changelog` | `Changelog` | The changelog to sort | | `order?` | `unknown` | Optional custom section order (defaults to standard order) | **Returns** `Changelog`: A new changelog with sorted sections **Example: Sorting sections within entries** ```typescript const sorted = sortSections(changelog) // Sections in each entry follow: breaking, features, fixes, ... const custom = sortSections(changelog, ['fixes', 'features', 'breaking']) // Custom ordering: fixes first, then features, then breaking ``` #### stripMetadata ```typescript function stripMetadata(changelog: Changelog): Changelog ``` Strips metadata from a changelog. **Parameters** | Name | Type | Description | | --- | --- | --- | | `changelog` | `Changelog` | The changelog to strip | **Returns** `Changelog`: A new changelog with minimal metadata **Example: Stripping metadata from a changelog** ```typescript const stripped = stripMetadata(changelog) // Source and warnings removed, only format and isConventional retained ``` #### summarizeDiff ```typescript function summarizeDiff(diff: ChangelogDiff): string ``` Creates a human-readable summary of a changelog diff. **Parameters** | Name | Type | Description | | --- | --- | --- | | `diff` | `ChangelogDiff` | The diff to summarize | **Returns** `string`: A string summary of the changes **Example: Creating human-readable diff summary** ```typescript const diff = diffChangelogs(oldChangelog, newChangelog) summarizeDiff(diff) // => 'Added 2 version(s): 1.2.0, 1.1.0; Modified 1 version(s): 1.0.0' ``` #### toJsonObject ```typescript function toJsonObject(changelog: Changelog, options?: JsonSerializeOptions): Record ``` Converts a Changelog to a plain JSON-serializable object. Useful when you need the object itself rather than a string. **Parameters** | Name | Type | Description | | --- | --- | --- | | `changelog` | `Changelog` | The changelog to convert | | `options?` | `JsonSerializeOptions` | Optional JSON serialization options | **Returns** `Record`: A plain object suitable for JSON serialization **Example: Converting changelog to plain object** ```typescript const obj = toJsonObject(changelog, { includeSource: true }) // => { source: 'CHANGELOG.md', header: { title: '...', ... }, entries: [...] } // Send as API response res.json(obj) ``` #### tokenize ```typescript function tokenize(input: string): Token[] ``` Tokenizes a changelog markdown string into tokens. **Parameters** | Name | Type | Description | | --- | --- | --- | | `input` | `string` | The markdown content to tokenize | **Returns** `Token[]`: Array of tokens **Example: Tokenizing changelog markdown** ```typescript const tokens = tokenize('# Changelog\n\n## [1.0.0]\n- Added feature') // => [{ type: 'heading-1', value: 'Changelog', ... }, { type: 'heading-2', ... }, ...] ``` #### transformEntries ```typescript function transformEntries(changelog: Changelog, transformer: EntryTransformer): Changelog ``` Transforms all entries in a changelog. **Parameters** | Name | Type | Description | | --- | --- | --- | | `changelog` | `Changelog` | The changelog to transform | | `transformer` | `EntryTransformer` | Function to transform each entry | **Returns** `Changelog`: A new changelog with transformed entries **Example: Transforming all entries** ```ts const transformed = transformEntries(changelog, (entry) => ({ ...entry, date: entry.date?.toUpperCase() })) ``` #### transformItems ```typescript function transformItems(changelog: Changelog, transformer: ItemTransformer): Changelog ``` Transforms all items in all sections. **Parameters** | Name | Type | Description | | --- | --- | --- | | `changelog` | `Changelog` | The changelog to transform | | `transformer` | `ItemTransformer` | Function to transform each item | **Returns** `Changelog`: A new changelog with transformed items **Example: Prefixing item descriptions with scope** ```typescript const prefixed = transformItems(changelog, (item) => ({ ...item, description: `[${item.scope || 'misc'}] ${item.description}`, })) ``` #### transformSections ```typescript function transformSections(changelog: Changelog, transformer: SectionTransformer): Changelog ``` Transforms all sections in all entries. **Parameters** | Name | Type | Description | | --- | --- | --- | | `changelog` | `Changelog` | The changelog to transform | | `transformer` | `SectionTransformer` | Function to transform each section | **Returns** `Changelog`: A new changelog with transformed sections **Example: Uppercasing section headings** ```typescript const renamed = transformSections(changelog, (section) => ({ ...section, heading: section.heading.toUpperCase(), })) ``` #### updateEntry ```typescript function updateEntry(changelog: Changelog, version: string, updates: Partial | (entry: ChangelogEntry) => ChangelogEntry): Changelog ``` Updates a specific entry by version. **Parameters** | Name | Type | Description | | --- | --- | --- | | `changelog` | `Changelog` | The changelog to update | | `version` | `string` | Version of entry to update | | `updates` | `Partial \| (entry: ChangelogEntry) => ChangelogEntry` | Partial entry updates or transformer function | **Returns** `Changelog`: A new changelog with updated entry **Example: Updating a specific entry** ```typescript const updated = updateEntry(changelog, '1.0.0', { date: '2024-01-15' }) // Or with transformer function const modified = updateEntry(changelog, '1.0.0', (entry) => ({ ...entry, compareUrl: `https://github.com/org/repo/compare/v0.9.0...v${entry.version}`, })) ``` #### updateHeader ```typescript function updateHeader(changelog: Changelog, updates: Partial): Changelog ``` Updates the header of a changelog. **Parameters** | Name | Type | Description | | --- | --- | --- | | `changelog` | `Changelog` | The changelog to update | | `updates` | `Partial` | Partial header updates | **Returns** `Changelog`: A new changelog with updated header **Example: Updating the changelog header** ```typescript const updated = updateHeader(changelog, { title: '# Release Notes' }) ``` #### updateMetadata ```typescript function updateMetadata(changelog: Changelog, updates: Partial): Changelog ``` Updates the metadata of a changelog. **Parameters** | Name | Type | Description | | --- | --- | --- | | `changelog` | `Changelog` | The changelog to update | | `updates` | `Partial` | Partial metadata updates | **Returns** `Changelog`: A new changelog with updated metadata **Example: Updating changelog metadata** ```typescript const updated = updateMetadata(changelog, { repositoryUrl: 'https://github.com/org/repo' }) ``` #### validateChangelog ```typescript function validateChangelog(changelog: unknown): ValidationResult ``` Validates a changelog object against the schema. **Parameters** | Name | Type | Description | | --- | --- | --- | | `changelog` | `unknown` | The changelog object to validate | **Returns** `ValidationResult`: Validation result with any errors **Example: Validating a changelog object** ```ts const result = validateChangelog(myChangelog) if (!result.valid) { console.log('Validation errors:', result.errors) } ``` ### Interfaces #### AddEntryOptions Options for adding an entry. **Properties** | Name | Type | Description | | --- | --- | --- | | `readonly position?` | `number \| "start" \| "end"` | Position to insert (default: 0, at the beginning) | | `readonly replaceExisting?` | `boolean` | Replace existing entry with same version | | `readonly updateMetadata?` | `boolean` | Update metadata after adding | #### Changelog Changelog Complete representation of a CHANGELOG.md file. Designed for lossless round-tripping: parse -> modify -> serialize. **Properties** | Name | Type | Description | | --- | --- | --- | | `readonly source?` | `string` | Original file path (if parsed from file) | | `readonly header` | `ChangelogHeader` | File header/preamble content | | `readonly entries` | `unknown` | Version entries, ordered newest first | | `readonly metadata` | `ChangelogMetadata` | Additional metadata extracted during parsing | #### ChangelogDiff Represents the diff between two changelogs. **Properties** | Name | Type | Description | | --- | --- | --- | | `readonly added` | `unknown` | Entries added in target but not in source | | `readonly removed` | `unknown` | Entries removed from source but not in target | | `readonly modified` | `unknown` | Entries present in both but with differences | | `readonly identical` | `boolean` | Whether changelogs are structurally identical | | `readonly stats` | `DiffStats` | Summary statistics | #### ChangelogEntry Changelog Entry Represents a single version entry in a changelog. **Properties** | Name | Type | Description | | --- | --- | --- | | `readonly version` | `string` | Version string (e.g., "1.2.3") | | `readonly date` | `string` | Release date (ISO format or null for unreleased) | | `readonly unreleased` | `boolean` | Whether this is an unreleased/upcoming section | | `readonly compareUrl?` | `string` | Compare URL (e.g., GitHub compare link) | | `readonly sections` | `unknown` | Grouped changes by category | | `readonly rawContent?` | `string` | Raw text for entries that couldn't be parsed structurally | #### ChangelogHeader Changelog Header The header section of a changelog file. **Properties** | Name | Type | Description | | --- | --- | --- | | `readonly title` | `string` | Title (e.g., "# Changelog") | | `readonly description` | `unknown` | Description paragraphs between title and first entry | | `readonly links` | `unknown` | Any links defined in header | #### ChangelogItem Changelog Item Represents an individual change within a changelog section. **Properties** | Name | Type | Description | | --- | --- | --- | | `readonly scope?` | `string` | Scope (e.g., "api", "cli") | | `readonly description` | `string` | Description of the change | | `readonly commits` | `unknown` | Commit references | | `readonly references` | `unknown` | Issue/PR references | | `readonly breaking` | `boolean` | Whether this is a breaking change | | `readonly source?` | `CommitSource` | Classification source (for auditing/debugging) | | `readonly indirect?` | `boolean` | Whether this is an indirect change (dependency or infrastructure) | #### ChangelogLink Changelog Link Represents a link defined in the changelog header or elsewhere. **Properties** | Name | Type | Description | | --- | --- | --- | | `readonly label` | `string` | Link label | | `readonly url` | `string` | Link URL | #### ChangelogMetadata Changelog Metadata Additional information extracted during parsing. **Properties** | Name | Type | Description | | --- | --- | --- | | `readonly format` | `ChangelogFormat` | Detected changelog format/style | | `readonly isConventional` | `boolean` | Whether the file follows conventional changelog spec | | `readonly repositoryUrl?` | `string` | Repository URL if detected | | `readonly packageName?` | `string` | Package name if detected | | `readonly warnings` | `unknown` | Parser warnings/notes | #### ChangelogSection Changelog Section Represents a category of changes (Features, Bug Fixes, etc.) **Properties** | Name | Type | Description | | --- | --- | --- | | `readonly type` | `ChangelogSectionType` | Section type (features, fixes, etc.) | | `readonly heading` | `string` | Section heading as it appears in file | | `readonly items` | `unknown` | Individual change items | #### CommitRef Commit Reference Represents a reference to a git commit in a changelog item. **Properties** | Name | Type | Description | | --- | --- | --- | | `readonly hash` | `string` | Full commit hash | | `readonly shortHash` | `string` | Short commit hash (typically 7 characters) | | `readonly url?` | `string` | URL to the commit (e.g., GitHub commit link) | #### CompatibilityResult Schema compatibility check result. **Properties** | Name | Type | Description | | --- | --- | --- | | `readonly compatible` | `boolean` | Whether schemas are compatible | | `readonly differences` | `unknown` | List of schema differences found | #### DiffStats Statistics about the diff. **Properties** | Name | Type | Description | | --- | --- | --- | | `readonly addedCount` | `number` | Number of added entries | | `readonly removedCount` | `number` | Number of removed entries | | `readonly modifiedCount` | `number` | Number of modified entries | | `readonly totalChanges` | `number` | Total number of property changes across all modified entries | #### EntryDiff Represents differences in a single entry. **Properties** | Name | Type | Description | | --- | --- | --- | | `readonly version` | `string` | Version of the entry | | `readonly source` | `ChangelogEntry` | Original entry (from source) | | `readonly target` | `ChangelogEntry` | Modified entry (from target) | | `readonly changes` | `unknown` | List of property differences | | `readonly addedSections` | `unknown` | Sections added in target | | `readonly removedSections` | `unknown` | Sections removed from source | | `readonly modifiedSections` | `unknown` | Sections that were modified | #### IssueRef Issue/PR Reference Represents a reference to an issue or pull request. **Properties** | Name | Type | Description | | --- | --- | --- | | `readonly number` | `number` | Issue or PR number | | `readonly url?` | `string` | URL to the issue/PR | | `readonly type` | `"issue" \| "pull-request"` | Type of reference | #### ItemDiff Represents differences in a single item. **Properties** | Name | Type | Description | | --- | --- | --- | | `readonly sourceDescription` | `string` | Description from source | | `readonly source` | `ChangelogItem` | Source item | | `readonly target` | `ChangelogItem` | Target item | | `readonly changes` | `unknown` | List of property changes | #### JsonSerializeOptions JSON serialization options. **Properties** | Name | Type | Description | | --- | --- | --- | | `readonly pretty?` | `boolean` | Pretty print with indentation | | `readonly indent?` | `number` | Indentation size (for pretty printing) | | `readonly includeSource?` | `boolean` | Include source path in output | | `readonly includeMetadata?` | `boolean` | Include metadata in output | | `readonly includeEmptyArrays?` | `boolean` | Include empty arrays | #### MergeOptions Options for merging changelogs. **Properties** | Name | Type | Description | | --- | --- | --- | | `readonly entryStrategy?` | `MergeStrategy` | Strategy for conflicting entries (default: 'union') | | `readonly sectionStrategy?` | `MergeStrategy` | Strategy for conflicting sections (default: 'union') | | `readonly itemStrategy?` | `MergeStrategy` | Strategy for conflicting items (default: 'union') | | `readonly useSourceHeader?` | `boolean` | Use source header (default: true) | | `readonly sortByVersion?` | `boolean` | Sort entries by version after merge | | `readonly removeDuplicates?` | `boolean` | Remove duplicates | #### MergeResult Result of a merge operation. **Properties** | Name | Type | Description | | --- | --- | --- | | `readonly changelog` | `Changelog` | The merged changelog | | `readonly stats` | `MergeStats` | Statistics about the merge | #### MergeStats Statistics about a merge operation. **Properties** | Name | Type | Description | | --- | --- | --- | | `readonly totalEntries` | `number` | Number of entries in result | | `readonly sourceOnly` | `number` | Entries only in source | | `readonly targetOnly` | `number` | Entries only in target | | `readonly merged` | `number` | Entries merged from both | | `readonly conflictsResolved` | `number` | Number of conflicts resolved | #### PropertyDiff Represents a single property difference. **Properties** | Name | Type | Description | | --- | --- | --- | | `readonly path` | `unknown` | Path to the property (e.g., ['date'], ['sections', '0', 'heading']) | | `readonly type` | `"added" \| "changed" \| "removed"` | Type of change | | `readonly oldValue?` | `unknown` | Previous value (for 'removed' and 'changed') | | `readonly newValue?` | `unknown` | New value (for 'added' and 'changed') | #### RemoveEntryOptions Options for removing an entry. **Properties** | Name | Type | Description | | --- | --- | --- | | `readonly throwIfNotFound?` | `boolean` | Throw error if entry not found (default: true) | #### RemoveSectionOptions Options for removing a section or item. **Properties** | Name | Type | Description | | --- | --- | --- | | `readonly throwIfNotFound?` | `boolean` | Throw error if section/item not found (default: true) | #### SchemaDifference A single schema difference. **Properties** | Name | Type | Description | | --- | --- | --- | | `readonly path` | `string` | JSON path where difference was found | | `readonly type` | `"type-mismatch" \| "missing-property" \| "extra-property"` | Type of difference | | `readonly sourceType?` | `string` | Type in source schema | | `readonly targetType?` | `string` | Type in target schema | #### SectionDiff Represents differences in a single section. **Properties** | Name | Type | Description | | --- | --- | --- | | `readonly type` | `string` | Section type | | `readonly source` | `ChangelogSection` | Original section (from source) | | `readonly target` | `ChangelogSection` | Modified section (from target) | | `readonly addedItems` | `unknown` | Items added in target | | `readonly removedItems` | `unknown` | Items removed from source | | `readonly modifiedItems` | `unknown` | Items that were modified | #### SerializeOptions Serialization options for controlling output format. **Properties** | Name | Type | Description | | --- | --- | --- | | `readonly includeDescription?` | `boolean` | Include preamble description in header | | `readonly includeLinks?` | `boolean` | Include links section | | `readonly includeCompareUrls?` | `boolean` | Include compare URLs for entries | | `readonly includeCommits?` | `boolean` | Include commit references | | `readonly includeReferences?` | `boolean` | Include issue/PR references | | `readonly includeScope?` | `boolean` | Include scope in items | | `readonly includeRawContent?` | `boolean` | Include raw content fallback | | `readonly sectionOrder?` | `unknown` | Section ordering (defaults to standard order) | | `readonly sectionHeadings?` | `Partial>` | Custom section headings (overrides defaults) | | `readonly lineEnding?` | `" " \| " "` | Line ending style | | `readonly entrySpacing?` | `number` | Number of blank lines between entries | | `readonly sectionSpacing?` | `number` | Number of blank lines between sections | | `readonly useAsterisks?` | `boolean` | Use asterisks (*) instead of dashes (-) for list items | #### Token Represents a single parsed token from the changelog markdown. **Properties** | Name | Type | Description | | --- | --- | --- | | `readonly type` | `TokenType` | The type classification of the token | | `readonly value` | `string` | The raw text content of the token | | `readonly line` | `number` | Line number where the token appears (1-indexed) | | `readonly column` | `number` | Column position where the token starts (1-indexed) | ### Types #### ChangelogFormat Changelog Format Detected format/style of the changelog file. ```typescript type ChangelogFormat = "keep-a-changelog" | "conventional" | "custom" | "unknown" ``` #### ChangelogSectionType Changelog Section Types Categories for grouping changes in a changelog entry. ```typescript type ChangelogSectionType = "breaking" | "features" | "fixes" | "performance" | "documentation" | "deprecations" | "refactoring" | "tests" | "build" | "ci" | "chores" | "other" ``` #### EntryPredicate Predicate function for filtering entries. ```typescript type EntryPredicate = (entry: ChangelogEntry, index: number) => boolean ``` #### EntryTransformer Transformation function for entries. ```typescript type EntryTransformer = (entry: ChangelogEntry, index: number) => ChangelogEntry ``` #### ItemPredicate Predicate function for filtering items. ```typescript type ItemPredicate = (item: ChangelogItem, section: ChangelogSection, entry: ChangelogEntry) => boolean ``` #### ItemTransformer Transformation function for items. ```typescript type ItemTransformer = (item: ChangelogItem, section: ChangelogSection, entry: ChangelogEntry) => ChangelogItem ``` #### MergeStrategy Strategy for resolving merge conflicts. ```typescript type MergeStrategy = "source" | "target" | "union" | "latest" ``` #### SectionPredicate Predicate function for filtering sections. ```typescript type SectionPredicate = (section: ChangelogSection, entry: ChangelogEntry) => boolean ``` #### SectionTransformer Transformation function for sections. ```typescript type SectionTransformer = (section: ChangelogSection, entry: ChangelogEntry) => ChangelogSection ``` #### TokenType Token Types ```typescript type TokenType = "heading-1" | "heading-2" | "heading-3" | "heading-4" | "list-item" | "link-text" | "link-url" | "text" | "newline" | "blank-line" | "bold" | "code" | "eof" ``` ### Variables #### changelogSchema JSON Schema for a complete Changelog document. Used for validation and format compatibility checking. ```typescript const changelogSchema: Schema ``` **Value** `...` #### DEFAULT_MERGE_OPTIONS Default merge options. ```typescript const DEFAULT_MERGE_OPTIONS: Required ``` **Value** `...` #### DEFAULT_SERIALIZE_OPTIONS Default serialization options. ```typescript const DEFAULT_SERIALIZE_OPTIONS: Required ``` **Value** `...` #### SECTION_HEADINGS Standard section headings for serialization. Maps section types to their preferred heading text. ```typescript const SECTION_HEADINGS: Record ``` **Value** `...` #### SECTION_TYPE_MAP Maps section headings to their canonical types. Used during parsing to normalize different heading styles. ```typescript const SECTION_TYPE_MAP: Record ``` **Value** `...` --- Canonical page: https://www.hyperfrontend.dev/docs/libraries/versioning/changelog/ This file: https://www.hyperfrontend.dev/docs/libraries/versioning/changelog.md Documentation index: https://www.hyperfrontend.dev/llms.txt