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 🙏

© 2024 – Pkg Stats / Ryan Hefner

date-clashes

v0.5.1

Published

A simple API for detecting overlapping dates

Downloads

2

Readme

date-clashes

A simple API for detecting overlapping dates

Installation

npm install date-clashes --save

Usage

var myDates = [
   { s: /* Date */, e: /* Date */ , id: 1 },
   { s: /* Date */, e: /* Date */ , id: 2 },
   ...
];

var DateClash = require("date-clashes");

// Supply the constructor with instructions on how to parse your date objects
// The function must return an object that matches the 'Range' interface below
var clash = new DateClash.Clash(date => { return { start: date.s, end: date.e, id: date.id } });

// Detect the clashes
var clashes = clash.flatten(myDates);

// Make the clash 'window'/'extremities' fall on particular days of the week
// 0 = Sunday, 6 = Saturday
var clashes = clash.flatten(myDates, { startDay: 1 /* Monday */, endDay: 0 /* Sunday */ });

// Returns an object of type Clashes that looks like:
{
    start: Tue Sep 15 2015 00:00:00 GMT+0800 (W. Australia Standard Time),
    end: Thu Sep 24 2015 00:00:00 GMT+0800 (W. Australia Standard Time),
    
    '1': { date: Tue Sep 15 2015 00:00:00 GMT+0800 (W. Australia Standard Time),
     clashes: [ ... ] },
     ...
    '10': { date: Tue Sep 24 2015 00:00:00 GMT+0800 (W. Australia Standard Time),
     clashes: [ ... ] },
}


interface Clashes {
    start: Date; // The floored version of the earliest date in your array
    end: Date; // The ceiling version of the latest date in your array
    [dayNumber: number]: { date: Date, clashes: Range[] }
}

interface Range {
    start: Date;
    end: Date;
    [key: string]: any;
}

API

Constructor
constructor(rangeGetter?: RangeGetter);
RangeGetter

A function that takes an object and returns an object that date-clashes can understand (Range)
The object must contain a start and end property which must be Date objects.

Example:

function rangeGetter(myObject) {
    return {
        start: new Date(myObject.startDate),
        end: new Date(myObject.endDate),
        id: myObject.id,
        firstName: myObject.firstName,
        lastName: myObject.lastName
    };
}

var clash = new DateClash.Clash(rangeGetter);
Flatten

The function that does all of the work.
Takes an array of objects that your rangeGetter function can parse.

function flatten(dates: Array<any>, options?: Options) => Clashes;
Options

An optional object that has two optional properties:
startDay and endDay
These options will determine the day number of outer-extremities of the returned Clashes object.

{
    startDay: number,
    endDay: number
}

License

MIT