npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

time-range-utils

v1.0.0

Published

A comprehensive TypeScript library for working with time ranges and date intervals.

Readme

Time Range Utils

A comprehensive TypeScript library for working with time ranges and date intervals.

Features

  • Merge overlapping ranges - Combine overlapping time periods
  • Subtract ranges - Remove time periods from ranges
  • Split ranges - Divide ranges into equal chunks
  • Check overlaps - Detect if ranges overlap
  • Point-in-range testing - Check if dates fall within ranges
  • Format ranges - Human-readable string representations
  • TypeScript support - Full type safety and IntelliSense
  • Comprehensive validation - Detailed error messages for invalid inputs
  • Zero dependencies - Lightweight and fast

Installation

npm install time-range-utils
# or
yarn add time-range-utils
# or
pnpm add time-range-utils

Quick Start

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

API Reference

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): boolean

Checks if two ranges overlap (inclusive boundaries).

isInside(date: Date, range: DateRange): boolean

Tests if a date falls within a range (inclusive boundaries).

formatRange(range: DateRange): string

Converts a range to a human-readable string.

Error Handling

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}`);
  }
}

TypeScript Support

Full TypeScript definitions included:

type DateRange = {
  start: Date;
  end: Date;
};

Contributing

  1. Fork the repository
  2. Create a feature branch: git checkout -b feature/amazing-feature
  3. Make your changes and add tests
  4. Run tests: pnpm test
  5. Run linting: pnpm run lint
  6. Commit your changes: git commit -m 'Add amazing feature'
  7. Push to the branch: git push origin feature/amazing-feature
  8. Open a Pull Request

Development

# 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

License

This project is licensed under the MIT License - see the LICENSE file for details.

Changelog

See CHANGELOG.md for a detailed history of changes.

Support