Giter Club home page Giter Club logo

date-filtersjs's Introduction

DATE-FILTERSJS - Combination of Filter and Date

Release Release Date Last Commit License

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:

import {Dates, DateFormat, Filter} from 'date-filtersjs';

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 = new Filter(obj);                                            // initialize filter
filter.filterBy("name","userz").result();                                // Filter by an attribute
filter.where("name","==","userz").where("age","==","21").result();       // compound filter (AND), valid operators that can be used (==, !=, <= , >=)

filter.filterByToday("date").result();                                    // filters the date by today
filter.filterByYesterday("date").result();                                // filters the date by yesterday
filter.filterByCurrentWeek("date").result();                              // filters the date by first and last day of the week
filter.filterByCurrentMonth("date").result();                             // filters the date by current month
filter.filterByNextWeek("date").result();                                 // filters the date by next week
filter.filterByNextMonth("date").result();                                // filters the date by next month
filter.filterByLastWeek("date").result();                                 // filters the date by last week

filter.filterByNextThirtyDays("date").result();                           // filters the date by next thirty days
filter.filterByLastSevenDays("date").result();                            // filters the date by last seven days
filter.filterByLastThirtyDays("date").result();                           // filters the date by last thirty days
filter.filterByLastSixtyDays("date").result();                            // filters the date by last sixty days 

filter.filterByLastNinetyDays("date").result();                           // filters the date by last ninety days
filter.filterByMonthToDate("date").result();                              // filters the date by month to date
filter.filterByLastMonth("date").result();                                // 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 = new Dates();                                                  // initialize
date.setFormat("MM/DD/YYYY");                                            // set the format, valid formats ("MM/DD/YYYY", "MM-DD-YYYY", "DD/MM/YYYY")
date.getFormat();                                                        // retrieve format

// both methods below will return an object like this {date: "26/05/2019"}, you can access the date using "date" attribute

date.today();                                                           // retrieve today's date
date.yesterday();                                                       // 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.currentWeek();                                                     // retrieve first and last day of the week
date.currentMonth();                                                    // retrieve first and last day of the month
date.nextWeek();                                                        // retrieve first and last day of next week

date.nextMonth();                                                       // retrieve first and last day of next month
date.lastWeek();                                                        // retrieve first and last day of last week
date.nextThirtyDays();                                                  // retrieve first and last day of the next thirty days

date.lastSevenDays();                                                   // retrieve first and last day of last seven days
date.lastThirtyDays();                                                  // retrieve first and last day of last thirty days
date.lastSixtyDays();                                                   // retrieve first and last day of the last sixty days

date.lastNinetyDays();                                                  // retrieve first and last day of the last ninety days
date.monthToDate();                                                     // retrieve first day of the month and current day
date.lastMonth();                                                       // retrieve first and last day of last month

date.incrementBy("40"));                                                // retrieve current day and last day according to the increment number provided
date.decrementBy("40"));                                                // retrieve current day and last day according to the decrement number provided

Created & Maintained By

Peter (@peterndev)

If you found this extension helpful and want to thank me, consider buying me a cup of โ˜•

Buy Me A Coffee

date-filtersjs's People

Contributors

peterhdd avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

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.