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

sortof

v0.7.0

Published

sort lists of objects by date strings

Downloads

10

Readme

sortof

This module returns several functions that sort/filter a list of objects by date string. This module uses moment, so your date values can also be moment objects.

Given a list of objects that have a date value, you can filter by dates occuring:

  • today
  • tomorrow
  • this week
  • next week
  • within a week (today + 1 week)
  • this month
  • next month
  • within a month (today + 1 month)
  • any range, given a start and end date

This module works in Node.js and the browser, with Browserify.

browser support

npm install sorta

usage

All functions take the same first 3 params:

  • [Array] an array of objects
  • [String] key in each object that points to the date string (ie. 'date', 'start_time')
  • [String] format of date strings according to moment#format

Others take an additional param.

functions

The module returns an object with the following member functions. They each filter and return a list.

sort(array, key, format)

returns an array of objects sorted linearly from today to the future

range(array, key, format, begin, end)

returns an array of objects fliltered by the range (within the range). The begin and end params should be date strings in the same format as the rest, or a moment.js object. The other functions use this function.

today(array, key, format)

return an array of objects which have date-times that are Today

tomorrow([ibid.])

returns same for dates occuring tomorrow

thisWeek([ibid.])

returns same for dates occuring within the current calendar week (beginning Sunday)

nextWeek([ibid.])

returns same for dates occuring next calendar week

withinWeek([ibid.])

returns same for dates occuring within a week, starting today

thisMonth(array, key, fmt [, month])

returns same for dates occruing within the given calendar month. Defaults to this month. The month param can be a number (0,11), or a string, the name of the month.

nextMonth(array, key, fmt)

return same for dates occuring next calenday month

withinMonth(array, key, format)

returns same for dates within the next month, starting today

moment

for convenience, this module returns the actual moment module.