count-per-day

1.1.0 • Public • Published

count-per-daybuild status

Get counts per day from a list of dates

NPM

NPM

Installation

npm install count-per-day

Example

Input

var countPerDay = require('./count-per-day')
  , days = [
        new Date('2014-01-01T12:00:00')
      , new Date('2014-01-04T11:00:00')
      , new Date('2014-01-01T14:00:00')
      , new Date('2014-01-02T16:55:00')
    ]
  , daysWithWeight = [
        { date: new Date('2014-01-01T12:00:00'), weight: -1 }
      , { date: new Date('2014-01-04T11:00:00'), weight: 13.37 }
      , { date: new Date('2014-01-01T14:00:00'), weight: 2 }
      , { date: new Date('2014-01-02T16:55:00'), weight: -1000 }        
  ]
 
console.log('You can get the counts by day as an object')
console.log(countPerDay(days))
console.log('But you can also get it as an array from first date to last date')
console.log(countPerDay.array(days))
console.log('You can also get counts per day with where every day has a weight')
console.log(countPerDay.withWeight(daysWithWeight))
console.log('and that can you also get as an array from first date to last')
console.log(countPerDay.withWeight.array(daysWithWeight))

Output

You can get the counts by day as an object
{ '2014-01-01': 2, '2014-01-04': 1, '2014-01-02': 1 }
But you can also get it as an array from first date to last date
[ { day: '2014-01-01', count: 2 },
  { day: '2014-01-02', count: 1 },
  { day: '2014-01-03', count: 0 },
  { day: '2014-01-04', count: 1 } ]
You can also get counts per day with where every day has a weight
{ '2014-01-01': 1, '2014-01-04': 13.37, '2014-01-02': -1000 }
and that can you also get as an array from first date to last
[ { day: '2014-01-01', weight: 1 },
  { day: '2014-01-02', weight: -1000 },
  { day: '2014-01-03', weight: 0 },
  { day: '2014-01-04', weight: 13.37 } ]

Licence

Copyright (c) 2014 David Björklund

This software is released under the MIT license:

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Readme

Keywords

none

Package Sidebar

Install

npm i count-per-day

Weekly Downloads

4

Version

1.1.0

License

MIT

Last publish

Collaborators

  • kesla