
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
time-range-utils
Advanced tools
A comprehensive TypeScript library for working with time ranges and date intervals.
A comprehensive TypeScript library for working with time ranges and date intervals.
npm install time-range-utils
# or
yarn add time-range-utils
# or
pnpm add time-range-utils
import TimeRangeUtils from "time-range-utils";
const ranges = [
{
start: new Date("2025-01-01T10:00:00Z"),
end: new Date("2025-01-01T12:00:00Z"),
},
{
start: new Date("2025-01-01T11:00:00Z"),
end: new Date("2025-01-01T13:00:00Z"),
},
];
// Merge overlapping ranges
const merged = TimeRangeUtils.mergeOverlap(ranges);
// Result: [{ start: 2025-01-01T10:00:00Z, end: 2025-01-01T13:00:00Z }]
// Split a range into chunks
const range = {
start: new Date("2025-01-01T10:00:00Z"),
end: new Date("2025-01-01T12:00:00Z"),
};
const chunks = TimeRangeUtils.splitRange(range, 4);
// Result: 4 equal 30-minute periods
// Check if date is within range
const isInside = TimeRangeUtils.isInside(
new Date("2025-01-01T11:00:00Z"),
range
);
// Result: true
mergeOverlap(ranges: DateRange[]): DateRange[]Merges overlapping or adjacent time ranges.
subtractRanges(rangeA: DateRange, rangeB: DateRange): DateRange[]Subtracts rangeB from rangeA, returning remaining time periods.
splitRange(range: DateRange, chunks: number): DateRange[]Splits a time range into equal chunks.
isOverlap(rangeA: DateRange, rangeB: DateRange): booleanChecks if two ranges overlap (inclusive boundaries).
isInside(date: Date, range: DateRange): booleanTests if a date falls within a range (inclusive boundaries).
formatRange(range: DateRange): stringConverts a range to a human-readable string.
The library provides detailed error types for better debugging:
import { InvalidDateRangeError, InvalidParameterError } from "time-range-utils";
try {
TimeRangeUtils.splitRange(range, -1);
} catch (error) {
if (error instanceof InvalidParameterError) {
console.log(`Invalid parameter: ${error.parameterName}`);
console.log(`Value: ${error.parameterValue}`);
}
}
Full TypeScript definitions included:
type DateRange = {
start: Date;
end: Date;
};
git checkout -b feature/amazing-featurepnpm testpnpm run lintgit commit -m 'Add amazing feature'git push origin feature/amazing-feature# Install dependencies
pnpm install
# Run tests
pnpm test
# Run tests with coverage
pnpm run test:coverage
# Run linting
pnpm run lint
# Build the package
pnpm run build
# Type checking
pnpm run type-check
This project is licensed under the MIT License - see the LICENSE file for details.
See CHANGELOG.md for a detailed history of changes.
FAQs
A comprehensive TypeScript library for working with time ranges and date intervals.
We found that time-range-utils demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.