Skip to content
← Public packages

@kody/lineage

Interactive commit-level lines of kody, minus generated noise, as an offline-ready chart.

FollowForkOpen app

Files

labels-toggle.ts

18 lines · 757 B · TypeScript
/**
 * Chart label visibility, linkable with `?labels=off`. Labels show unless the
 * URL explicitly turns them off, so links without the param are unchanged.
 */
export function labelsVisibleFromSearch(search: string): boolean {
	const value = new URLSearchParams(search).get('labels')
	if (value === null) return true
	return !['off', 'false', '0', 'hide', 'hidden', 'no'].includes(value.trim().toLowerCase())
}

/** Search string for the given label state: drops the param when labels are on. */
export function searchWithLabels(search: string, visible: boolean): string {
	const params = new URLSearchParams(search)
	if (visible) params.delete('labels')
	else params.set('labels', 'off')
	const next = params.toString()
	return next ? `?${next}` : ''
}