@hyperfrontend/versioning/changelog/operations

operations

Immutable transformations over Changelog objects: every operation returns a new value, leaving the input untouched.

Add operations (addEntry, addUnreleasedEntry, releaseUnreleased, addItemToEntry) build new entries and items into a changelog. Remove operations strip entries or sections by predicate. filterEntries, filterSections, and filterItems produce focused projections. transformEntries, transformSections and transformItems apply arbitrary transformer functions per entry, section and item. The merge family (mergeChangelogs, configured via MergeStrategy and MergeOptions) combines two changelogs and reports MergeResult / MergeStats describing what was added, conflicted, or skipped. Useful for cross-branch and monorepo changelog reconciliation.

API Reference§

ƒ Functions

§function

addEntry(changelog: Changelog, entry: ChangelogEntry, options?: AddEntryOptions): Changelog

Adds a new entry to a changelog.
Parameters
NameTypeDescription
§changelog
ChangelogThe changelog to add to
§entry
ChangelogEntryThe entry to add
§options?
AddEntryOptionsOptional add options
Returns
Changelog
A new changelog with the entry added
Example

Adding a new entry to a changelog

const newChangelog = addEntry(changelog, {
  version: '1.2.0',
  date: '2024-01-15',
  unreleased: false,
  sections: [...]
})
§function

addItemToEntry(changelog: Changelog, version: string, sectionType: string, item: ChangelogItem): Changelog

Adds an item to a specific section within an entry.
Parameters
NameTypeDescription
§changelog
ChangelogThe changelog containing the entry to modify
§version
stringThe version identifier of the entry to update
§sectionType
stringCategory identifier for grouping changes (e.g., 'features', 'fixes')
§item
ChangelogItemDescription 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

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
§function

addUnreleasedEntry(changelog: Changelog, sections: unknown): Changelog

Adds or updates an unreleased entry.
Parameters
NameTypeDescription
§changelog
ChangelogThe changelog to add the unreleased entry to
§sections
unknownSections to include in the unreleased entry
Returns
Changelog
A new changelog with unreleased entry added/updated
Example

Adding an unreleased entry with sections

const sections = [createChangelogSection('features', 'Added', [item])]
const updated = addUnreleasedEntry(changelog, sections)
// => Changelog with unreleased entry at the top
§function

appendChangelog(source: Changelog, target: Changelog, position: "start" | "end"): Changelog

Appends entries from target to source (no conflict resolution).
Parameters
NameTypeDescription
§source
ChangelogThe base changelog to append to
§target
ChangelogThe 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

const combined = appendChangelog(mainChangelog, newChangelog, 'start')
// newChangelog entries appear before mainChangelog entries
§function

cloneChangelog(changelog: Changelog): Changelog

Clones a changelog deeply (for modification without affecting original).
Parameters
NameTypeDescription
§changelog
ChangelogThe changelog to clone
Returns
Changelog
A deep copy of the changelog
Example

Cloning a changelog

const copy = cloneChangelog(changelog)
// Independent deep copy, safe to mutate
§function

combineChangelogs(changelogs: unknown, options?: MergeOptions): Changelog

Combines multiple changelogs into one.
Parameters
NameTypeDescription
§changelogs
unknownArray of changelogs to combine
§options?
MergeOptionsOptional merge options
Returns
Changelog
The combined changelog
Example

Combining multiple changelogs

const unified = combineChangelogs([pkg1Changelog, pkg2Changelog], {
  strategy: 'merge-sections',
})
// All entries from both changelogs merged with conflict resolution
§function

compact(changelog: Changelog, keepUnreleased: boolean): Changelog

Compacts a changelog by removing empty sections and entries.
Parameters
NameTypeDescription
§changelog
ChangelogThe changelog to compact
§keepUnreleased
booleanWhether to keep empty unreleased entry (default: true)(default: true)
Returns
Changelog
A new compacted changelog
Example

Compacting a changelog

const compacted = compact(changelog)
// Empty sections and entries removed (unreleased kept)

const strict = compact(changelog, false)
// Even empty unreleased entry is removed
§function

deduplicateItems(changelog: Changelog): Changelog

Removes duplicate items across all sections.
Parameters
NameTypeDescription
§changelog
ChangelogThe changelog to deduplicate
Returns
Changelog
A new changelog without duplicate items
Example

Deduplicating items across sections

const deduped = deduplicateItems(changelog)
// Duplicate items (same scope:description) are removed
§function

excludeByScope(changelog: Changelog, scopes: unknown): Changelog

Excludes items by scope.
Parameters
NameTypeDescription
§changelog
ChangelogThe changelog to filter
§scopes
unknownScopes to exclude
Returns
Changelog
A new changelog without items matching the scopes
Example

Excluding items by scope

const publicChanges = excludeByScope(changelog, ['internal', 'test'])
// Items scoped to 'internal' or 'test' are removed
§function

filterBreakingChanges(changelog: Changelog): Changelog

Filters entries that have breaking changes.
Parameters
NameTypeDescription
§changelog
ChangelogThe changelog to filter
Returns
Changelog
A new changelog with only entries containing breaking changes
Example

Filtering for breaking changes

const breaking = filterBreakingChanges(changelog)
// Only entries containing breaking changes or items marked as breaking
§function

filterByDateRange(changelog: Changelog, startDate?: string, endDate?: string): Changelog

Filters entries by release date.
Parameters
NameTypeDescription
§changelog
ChangelogThe changelog to filter
§startDate?
stringStart date (inclusive, ISO format)
§endDate?
stringEnd date (inclusive, ISO format)
Returns
Changelog
A new changelog with entries in the date range
Example

Filtering entries by date range

const q1 = filterByDateRange(changelog, '2024-01-01', '2024-03-31')
// Entries released in Q1 2024
§function

filterByScope(changelog: Changelog, scopes: unknown): Changelog

Filters items by scope.
Parameters
NameTypeDescription
§changelog
ChangelogThe changelog to filter
§scopes
unknownScopes to include
Returns
Changelog
A new changelog with only items matching the scopes
Example

Filtering items by scope

const apiChanges = filterByScope(changelog, ['api', 'core'])
// Only items scoped to 'api' or 'core'
§function

filterByVersionRange(changelog: Changelog, range: string): Changelog

Filters entries by version range using semver.
Parameters
NameTypeDescription
§changelog
ChangelogThe changelog to filter
§range
stringSemver 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

const majors = filterByVersionRange(changelog, '>=1.0.0 <2.0.0')
§function

filterEntries(changelog: Changelog, predicate: EntryPredicate): Changelog

Filters entries using a predicate function.
Parameters
NameTypeDescription
§changelog
ChangelogThe changelog to filter
§predicate
EntryPredicateFunction that returns true for entries to keep
Returns
Changelog
A new changelog with filtered entries
Example

Filtering out unreleased entries

const filtered = filterEntries(changelog, (entry) => !entry.unreleased)
§function

filterFromVersion(changelog: Changelog, startVersion: string): Changelog

Filters entries from a start version.
Parameters
NameTypeDescription
§changelog
ChangelogThe changelog to filter
§startVersion
stringThe minimum version (inclusive)
Returns
Changelog
A new changelog with entries >= startVersion
Example

Filtering from a start version

const recent = filterFromVersion(changelog, '2.0.0')
// Only entries for version 2.0.0 and later
§function

filterItems(changelog: Changelog, predicate: ItemPredicate): Changelog

Filters items within sections.
Parameters
NameTypeDescription
§changelog
ChangelogThe changelog to filter
§predicate
ItemPredicateFunction that returns true for items to keep
Returns
Changelog
A new changelog with filtered items
Example

Filtering items with references

const withRefs = filterItems(changelog, (item) => item.references.length > 0)
// Only items with issue/PR references
§function

filterRecentEntries(changelog: Changelog, count: number, includeUnreleased: boolean): Changelog

Gets the N most recent entries.
Parameters
NameTypeDescription
§changelog
ChangelogThe changelog to filter
§count
numberNumber of entries to keep
§includeUnreleased
booleanWhether 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

const latest = filterRecentEntries(changelog, 5)
// Last 5 released versions (plus unreleased if present)
§function

filterSections(changelog: Changelog, predicate: SectionPredicate): Changelog

Filters sections within each entry.
Parameters
NameTypeDescription
§changelog
ChangelogThe changelog to filter
§predicate
SectionPredicateFunction that returns true for sections to keep
Returns
Changelog
A new changelog with filtered sections
Example

Filtering for user-facing sections

const userFacing = filterSections(changelog, (section) =>
  ['features', 'fixes', 'breaking'].includes(section.type)
)
§function

filterSectionTypes(changelog: Changelog, types: unknown): Changelog

Keeps only specified section types.
Parameters
NameTypeDescription
§changelog
ChangelogThe changelog to filter
§types
unknownSection types to keep
Returns
Changelog
A new changelog with only specified section types
Example

Filtering to specific section types

const userChanges = filterSectionTypes(changelog, ['features', 'fixes'])
// Only features and fixes sections remain
§function

filterToVersion(changelog: Changelog, endVersion: string): Changelog

Filters entries up to an end version.
Parameters
NameTypeDescription
§changelog
ChangelogThe changelog to apply the version filter to
§endVersion
stringThe maximum version (inclusive)
Returns
Changelog
A new changelog with entries <= endVersion
Example

Filtering to an end version

const legacy = filterToVersion(changelog, '1.9.9')
// Only entries for versions up to 1.9.9
§function

filterVersionRange(changelog: Changelog, startVersion: string, endVersion: string): Changelog

Gets entries within a version range (inclusive).
Parameters
NameTypeDescription
§changelog
ChangelogThe changelog to filter
§startVersion
stringThe minimum version (inclusive)
§endVersion
stringThe maximum version (inclusive)
Returns
Changelog
A new changelog with entries in the range
Example

Filtering entries within a version range

const range = filterVersionRange(changelog, '1.5.0', '2.0.0')
// Entries from 1.5.0 through 2.0.0
§function

mergeChangelogs(source: Changelog, target: Changelog, options?: MergeOptions): MergeResult

Merges two changelogs together.
Parameters
NameTypeDescription
§source
ChangelogThe source changelog
§target
ChangelogThe target changelog
§options?
MergeOptionsOptional merge options
Returns
MergeResult
The merge result with merged changelog and stats
Example

Merging two changelogs

const result = mergeChangelogs(mainChangelog, branchChangelog)
console.log(`Merged ${result.stats.merged} entries`)
§function

normalizeSectionHeadings(changelog: Changelog): Changelog

Normalizes section headings to standard format.
Parameters
NameTypeDescription
§changelog
ChangelogThe changelog to normalize
Returns
Changelog
A new changelog with normalized section headings
Example

Normalizing section headings

const normalized = normalizeSectionHeadings(changelog)
// 'New Features' becomes 'Added', 'Bug Fixes' becomes 'Fixed', etc.
§function

releaseUnreleased(changelog: Changelog, version: string, date?: string, compareUrl?: string): Changelog

Creates a new release entry from the current unreleased entry.
Parameters
NameTypeDescription
§changelog
ChangelogThe changelog containing the unreleased entry
§version
stringThe version number for the release
§date?
stringThe release date (defaults to today)
§compareUrl?
stringOptional comparison URL
Returns
Changelog
A new changelog with the unreleased entry converted to a release
Example

Releasing unreleased changes as a new version

const released = releaseUnreleased(changelog, '2.0.0', '2024-03-01')
// Unreleased entry becomes version 2.0.0 with the specified date
§function

removeEmptyEntries(changelog: Changelog, keepUnreleased: boolean): Changelog

Removes empty entries (entries with no sections or only empty sections).
Parameters
NameTypeDescription
§changelog
ChangelogThe changelog to remove empty entries from
§keepUnreleased
booleanWhether to keep an empty unreleased entry (default: true)(default: true)
Returns
Changelog
A new changelog with empty entries removed
Example

Removing empty entries

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
§function

removeEmptySections(changelog: Changelog): Changelog

Removes empty sections from all entries.
Parameters
NameTypeDescription
§changelog
ChangelogThe changelog to remove empty sections from
Returns
Changelog
A new changelog with empty sections removed
Example

Removing empty sections from all entries

const cleaned = removeEmptySections(changelog)
// Sections with no items are removed from all entries
§function

removeEntries(changelog: Changelog, versions: unknown, options?: RemoveEntryOptions): Changelog

Removes multiple entries from a changelog.
Parameters
NameTypeDescription
§changelog
ChangelogThe changelog to remove from
§versions
unknownThe versions to remove
§options?
RemoveEntryOptionsOptional removal options
Returns
Changelog
A new changelog without the specified entries
Example

Removing multiple entries

const cleaned = removeEntries(changelog, ['0.1.0', '0.2.0'])
// Pre-release versions removed from changelog
§function

removeEntry(changelog: Changelog, version: string, options?: RemoveEntryOptions): Changelog

Removes an entry from a changelog by version.
Parameters
NameTypeDescription
§changelog
ChangelogThe changelog to remove from
§version
stringThe version to remove
§options?
RemoveEntryOptionsOptional removal options
Returns
Changelog
A new changelog without the specified entry
Example

Removing an entry by version

const newChangelog = removeEntry(changelog, '1.0.0')
§function

removeItem(changelog: Changelog, version: string, sectionType: string, itemDescription: string, options?: RemoveSectionOptions): Changelog

Removes an item from an entry by description.
Parameters
NameTypeDescription
§changelog
ChangelogThe changelog containing the entry to modify
§version
stringThe version of the entry to modify
§sectionType
stringThe section type containing the item
§itemDescription
stringThe description of the item to remove
§options?
RemoveSectionOptionsOptional removal options
Returns
Changelog
A new changelog without the specified item
Example

Removing a specific item from a section

const updated = removeItem(changelog, '1.0.0', 'features', 'Add dark mode')
// The 'Add dark mode' item is removed from features in 1.0.0
§function

removeSection(changelog: Changelog, version: string, sectionType: string, options?: RemoveSectionOptions): Changelog

Removes a section from an entry.
Parameters
NameTypeDescription
§changelog
ChangelogThe changelog containing the entry to modify
§version
stringThe version of the entry to modify
§sectionType
stringThe section type to remove
§options?
RemoveSectionOptionsOptional removal options
Returns
Changelog
A new changelog without the specified section
Example

Removing a deprecated section

const updated = removeSection(changelog, '1.0.0', 'deprecated')
// Version 1.0.0 no longer has a deprecated section
§function

removeUnreleased(changelog: Changelog, options?: RemoveEntryOptions): Changelog

Removes the unreleased entry if it exists.
Parameters
NameTypeDescription
§changelog
ChangelogThe changelog to remove the unreleased entry from
§options?
RemoveEntryOptionsOptional removal options
Returns
Changelog
A new changelog without the unreleased entry
Example

Removing the unreleased entry

const released = removeUnreleased(changelog)
// Changelog without the unreleased entry

// Silently ignore if not found
const safe = removeUnreleased(changelog, { throwIfNotFound: false })
§function

reverseEntries(changelog: Changelog): Changelog

Reverses the order of entries.
Parameters
NameTypeDescription
§changelog
ChangelogThe changelog to reverse
Returns
Changelog
A new changelog with reversed entries
Example

Reversing entry order

const reversed = reverseEntries(changelog)
// Oldest entries now appear first
§function

sortEntries(changelog: Changelog): Changelog

Sorts entries by version (descending - newest first).
Parameters
NameTypeDescription
§changelog
ChangelogThe changelog to sort
Returns
Changelog
A new changelog with sorted entries
Example

Sorting changelog entries by version

const sorted = sortEntries(changelog)
// Entries ordered: Unreleased, 2.0.0, 1.1.0, 1.0.0, ...
§function

sortEntriesByDate(changelog: Changelog): Changelog

Sorts entries by date (newest first).
Parameters
NameTypeDescription
§changelog
ChangelogThe changelog to sort
Returns
Changelog
A new changelog with sorted entries
Example

Sorting entries by date

const sorted = sortEntriesByDate(changelog)
// Entries ordered by release date, most recent first
§function

sortSections(changelog: Changelog, order?: unknown): Changelog

Sorts sections within each entry by a specified order.
Parameters
NameTypeDescription
§changelog
ChangelogThe changelog to sort
§order?
unknownOptional custom section order (defaults to standard order)
Returns
Changelog
A new changelog with sorted sections
Example

Sorting sections within entries

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
§function

stripMetadata(changelog: Changelog): Changelog

Strips metadata from a changelog.
Parameters
NameTypeDescription
§changelog
ChangelogThe changelog to strip
Returns
Changelog
A new changelog with minimal metadata
Example

Stripping metadata from a changelog

const stripped = stripMetadata(changelog)
// Source and warnings removed, only format and isConventional retained
§function

transformEntries(changelog: Changelog, transformer: EntryTransformer): Changelog

Transforms all entries in a changelog.
Parameters
NameTypeDescription
§changelog
ChangelogThe changelog to transform
§transformer
EntryTransformerFunction to transform each entry
Returns
Changelog
A new changelog with transformed entries
Example

Transforming all entries

const transformed = transformEntries(changelog, (entry) => ({
  ...entry,
  date: entry.date?.toUpperCase()
}))
§function

transformItems(changelog: Changelog, transformer: ItemTransformer): Changelog

Transforms all items in all sections.
Parameters
NameTypeDescription
§changelog
ChangelogThe changelog to transform
§transformer
ItemTransformerFunction to transform each item
Returns
Changelog
A new changelog with transformed items
Example

Prefixing item descriptions with scope

const prefixed = transformItems(changelog, (item) => ({
  ...item,
  description: `[${item.scope || 'misc'}] ${item.description}`,
}))
§function

transformSections(changelog: Changelog, transformer: SectionTransformer): Changelog

Transforms all sections in all entries.
Parameters
NameTypeDescription
§changelog
ChangelogThe changelog to transform
§transformer
SectionTransformerFunction to transform each section
Returns
Changelog
A new changelog with transformed sections
Example

Uppercasing section headings

const renamed = transformSections(changelog, (section) => ({
  ...section,
  heading: section.heading.toUpperCase(),
}))
§function

updateEntry(changelog: Changelog, version: string, updates: Partial<ChangelogEntry> | (entry: ChangelogEntry) => ChangelogEntry): Changelog

Updates a specific entry by version.
Parameters
NameTypeDescription
§changelog
ChangelogThe changelog to update
§version
stringVersion of entry to update
§updates
Partial<ChangelogEntry> | (entry: ChangelogEntry) => ChangelogEntryPartial entry updates or transformer function
Returns
Changelog
A new changelog with updated entry
Example

Updating a specific entry

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}`,
}))
§function

updateHeader(changelog: Changelog, updates: Partial<ChangelogHeader>): Changelog

Updates the header of a changelog.
Parameters
NameTypeDescription
§changelog
ChangelogThe changelog to update
§updates
Partial<ChangelogHeader>Partial header updates
Returns
Changelog
A new changelog with updated header
Example

Updating the changelog header

const updated = updateHeader(changelog, { title: '# Release Notes' })
§function

updateMetadata(changelog: Changelog, updates: Partial<ChangelogMetadata>): Changelog

Updates the metadata of a changelog.
Parameters
NameTypeDescription
§changelog
ChangelogThe changelog to update
§updates
Partial<ChangelogMetadata>Partial metadata updates
Returns
Changelog
A new changelog with updated metadata
Example

Updating changelog metadata

const updated = updateMetadata(changelog, { repositoryUrl: 'https://github.com/org/repo' })

◈ Interfaces

§interface

AddEntryOptions

Options for adding an entry.
Properties
§readonly position?:number | "start" | "end"Position to insert (default: 0, at the beginning)
§readonly replaceExisting?:booleanReplace existing entry with same version
§readonly updateMetadata?:booleanUpdate metadata after adding
§interface

MergeOptions

Options for merging changelogs.
Properties
§readonly entryStrategy?:MergeStrategyStrategy for conflicting entries (default: 'union')
§readonly sectionStrategy?:MergeStrategyStrategy for conflicting sections (default: 'union')
§readonly itemStrategy?:MergeStrategyStrategy for conflicting items (default: 'union')
§readonly useSourceHeader?:booleanUse source header (default: true)
§readonly sortByVersion?:booleanSort entries by version after merge
§readonly removeDuplicates?:booleanRemove duplicates
§interface

MergeResult

Result of a merge operation.
Properties
§readonly changelog:ChangelogThe merged changelog
§readonly stats:MergeStatsStatistics about the merge
§interface

MergeStats

Statistics about a merge operation.
Properties
§readonly totalEntries:numberNumber of entries in result
§readonly sourceOnly:numberEntries only in source
§readonly targetOnly:numberEntries only in target
§readonly merged:numberEntries merged from both
§readonly conflictsResolved:numberNumber of conflicts resolved
§interface

RemoveEntryOptions

Options for removing an entry.
Properties
§readonly throwIfNotFound?:booleanThrow error if entry not found (default: true)
§interface

RemoveSectionOptions

Options for removing a section or item.
Properties
§readonly throwIfNotFound?:booleanThrow error if section/item not found (default: true)

◆ Types

§type

EntryPredicate

Predicate function for filtering entries.
type EntryPredicate = (entry: ChangelogEntry, index: number) => boolean
§type

EntryTransformer

Transformation function for entries.
type EntryTransformer = (entry: ChangelogEntry, index: number) => ChangelogEntry
§type

ItemPredicate

Predicate function for filtering items.
type ItemPredicate = (item: ChangelogItem, section: ChangelogSection, entry: ChangelogEntry) => boolean
§type

ItemTransformer

Transformation function for items.
type ItemTransformer = (item: ChangelogItem, section: ChangelogSection, entry: ChangelogEntry) => ChangelogItem
§type

MergeStrategy

Strategy for resolving merge conflicts.
type MergeStrategy = "source" | "target" | "union" | "latest"
§type

SectionPredicate

Predicate function for filtering sections.
type SectionPredicate = (section: ChangelogSection, entry: ChangelogEntry) => boolean
§type

SectionTransformer

Transformation function for sections.
type SectionTransformer = (section: ChangelogSection, entry: ChangelogEntry) => ChangelogSection

● Variables

§type

DEFAULT_MERGE_OPTIONS

Default merge options.