Giter Club home page Giter Club logo

sortof's Introduction

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.

sortof's People

Watchers

 avatar  avatar

Forkers

ccasilimas

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.