DATE-FILTERSJS - Combination of Filter and Date
Introduction
This is a javascript library, the main purpose of this library is to easily apply filter on specific date range and apply filter on any attribute.
Installation
To build your project using Webpack or similar builders, install packages from NPM:
npm i date-filtersjs
import as follows:
;;
Usage
Example User object
let obj = "name" : "userx" "age" : "20" "date" : "05/25/2019" "name" : "usery" "age" : "21" "date" : "05/24/2019" "name" : "userg" "age" : "21" "date" : "05/31/2019" "name" : "userz" "age" : "21" "date" : "06/03/2019" "name" : "userw" "age" : "21" "date" : "26/05/2019" ;
Filter
let filter = obj; // initialize filterfilter; // Filter by an attributefilter; // compound filter (AND), valid operators that can be used (==, !=, <= , >=) filter; // filters the date by todayfilter; // filters the date by yesterdayfilter; // filters the date by first and last day of the weekfilter; // filters the date by current monthfilter; // filters the date by next weekfilter; // filters the date by next monthfilter; // filters the date by last week filter; // filters the date by next thirty daysfilter; // filters the date by last seven daysfilter; // filters the date by last thirty daysfilter; // filters the date by last sixty days filter; // filters the date by last ninety daysfilter; // filters the date by month to datefilter; // filters the date by last month
Note: All of the above will return the filtered array
Date
You can also retrieve the date ranges, the following are the different methods available:
let date = ; // initializedate; // set the format, valid formats ("MM/DD/YYYY", "MM-DD-YYYY", "DD/MM/YYYY")date; // retrieve format // both methods below will return an object like this {date: "26/05/2019"}, you can access the date using "date" attribute date; // retrieve today's datedate; // retrieve yesterday's date // all methods below will return an object like this {first: "26/05/2019", last: "01/06/2019"}, you can access the first and last date by using "first" and "last attribute date; // retrieve first and last day of the weekdate; // retrieve first and last day of the monthdate; // retrieve first and last day of next week date; // retrieve first and last day of next monthdate; // retrieve first and last day of last weekdate; // retrieve first and last day of the next thirty days date; // retrieve first and last day of last seven daysdate; // retrieve first and last day of last thirty daysdate; // retrieve first and last day of the last sixty days date; // retrieve first and last day of the last ninety daysdate; // retrieve first day of the month and current daydate; // retrieve first and last day of last month date); // retrieve current day and last day according to the increment number provideddate); // retrieve current day and last day according to the decrement number provided