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

@gi/raider

v0.0.3

Published

High performance time and date query functions for JavaScript

Downloads

10

Readme

Raider

Sometimes a new recipe just isn't better

Build Status Coverage Status

Why

  • Minimal and super fast

Such speed, much wow

  • nuff said

Install

$ npm install --save @gi/raider

Usage

const raider = require('raider');

console.log(raider.getMinutes(new Date(), new Date(2016, 11, 24));

API

tl;dr

  • raider.isSameDay(dateA, dateB)
  • raider.getMinutes(dateA, dateB)
  • raider.getWeekday(date)
  • new raider.Span(dateA, dateB)
  • span.contains(date)
  • span.inside(date)
  • span.overlaps(span)
  • span.intersection(span)
  • span.xor(span)
  • span.getMinutes()
  • span.length()

raider.isSameDay(dateA, dateB)

Are two dates on the same day?

const today = new Date();
const xmas = new Date(2016, 11, 24);

console.log(raider.isSameDay(today, xmas));
//=> true (yaaay)

raider.getMinutes(dateA, dateB)

Get the minutes between two dates.

const oneDate = new Date(2016, 3, 21, 8, 53);
const otherDate = new Date(2016, 3, 22, 7, 10);

console.log(raider.getMinutes(oneDate, otherDate));
//=> 1337

raider.getWeekday(date)

Get the weekday of a date. Sunday = 0

const date = new Date(2016, 3, 21);
console.log(raider.getWeekday(date));
//=> 4 (thursday)

// Better yet, use the native function for this
console.log(date.getDay());
//=> 4

Spans

const date1 = new Date(2016, 0, 4, 9, 0);
const date2 = new Date(2016, 0, 4, 17, 0);

const span = new raider.Span(date1, date2);

.contains(date)

Does the span contain the date?

const date = new Date(2016, 0, 4, 11, 30);
const borderDate = new Date(2016, 0, 4, 9, 0);

console.log(span.contains(date));
//=> true

console.log(span.contains(borderDate));
//=> true

.inside(date)

Is the date inside the span?

const date = new Date(2016, 0, 4, 11, 30);
const borderDate = new Date(2016, 0, 4, 9, 0);

console.log(span.contains(date));
//=> true

console.log(span.contains(borderDate));
//=> false

.overlaps(span)

Does the span overlap the other?

const span1 = new raider.Span(
	new Date(2016, 0, 4, 9, 0),
	new Date(2016, 0, 4, 17, 0)
);

const span2 = new raider.Span(
	new Date(2016, 0, 4, 8, 0),
	new Date(2016, 0, 4, 9, 15)
);

console.log(span1.overlaps(span2));
//=> true

.intersection(span)

Returns a new Span where both spans intersect

const intersection = span1.intersection(span2);
/* = new Span(
		new Date(2016, 0, 4, 9, 0),
		new Date(2016, 0, 4, 9, 15)
	)
*/

.xor(span)

Returns an array of spans where the intersections have been cut out

const xorred = span1.xor(span2);
/* = [
		new Span(
			new Date(2016, 0, 4, 8, 0),
			new Date(2016, 0, 4, 9, 0)
		),
		new Span(
			new Date(2016, 0, 4, 9, 15),
			new Date(2016, 0, 4, 17, 0)
		)
	]

.getMinutes()

Returns the minutes between the dates in the span

console.log(span2.getMinutes());
//=> 75

.length()

Returns the milliseconds between the dates in the span

console.log(span2.length());
//=> 4500000