UNPKG

sync-worktrees

Version:

Automatically synchronize Git worktrees with remote branches - perfect for multi-branch development workflows

47 lines 1.65 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.parseDuration = parseDuration; exports.filterBranchesByAge = filterBranchesByAge; exports.formatDuration = formatDuration; function parseDuration(durationStr) { const match = durationStr.match(/^(\d+)([hdwmy])$/); if (!match) { return null; } const value = parseInt(match[1], 10); const unit = match[2]; const multipliers = { h: 60 * 60 * 1000, // hours d: 24 * 60 * 60 * 1000, // days w: 7 * 24 * 60 * 60 * 1000, // weeks m: 30 * 24 * 60 * 60 * 1000, // months (approximate) y: 365 * 24 * 60 * 60 * 1000, // years (approximate) }; return value * multipliers[unit]; } function filterBranchesByAge(branches, maxAge) { const maxAgeMs = parseDuration(maxAge); if (maxAgeMs === null) { console.warn(`Invalid duration format: ${maxAge}. Using all branches.`); return branches; } const cutoffDate = new Date(Date.now() - maxAgeMs); return branches.filter(({ lastActivity }) => lastActivity >= cutoffDate); } function formatDuration(durationStr) { const match = durationStr.match(/^(\d+)([hdwmy])$/); if (!match) { return durationStr; } const value = parseInt(match[1], 10); const unit = match[2]; const unitNames = { h: value === 1 ? "hour" : "hours", d: value === 1 ? "day" : "days", w: value === 1 ? "week" : "weeks", m: value === 1 ? "month" : "months", y: value === 1 ? "year" : "years", }; return `${value} ${unitNames[unit]}`; } //# sourceMappingURL=date-filter.js.map