date-streaks
Advanced tools
Comparing version 1.2.0 to 1.2.1
@@ -29,6 +29,8 @@ 'use strict'; | ||
_ref$length = _ref.length, | ||
length = _ref$length === undefined ? 7 : _ref$length; | ||
length = _ref$length === undefined ? 7 : _ref$length, | ||
_ref$endDate = _ref.endDate, | ||
endDate = _ref$endDate === undefined ? new Date() : _ref$endDate; | ||
var pastDates = [].concat(_toConsumableArray(Array(length))).map(function (_, i) { | ||
return (0, _start_of_day2.default)((0, _sub_days2.default)(new Date(), i)); | ||
return (0, _start_of_day2.default)((0, _sub_days2.default)(endDate, i)); | ||
}); | ||
@@ -35,0 +37,0 @@ var sortedDates = (0, _helpers.sortDates)(dates).map(function (date) { |
{ | ||
"name": "date-streaks", | ||
"version": "1.2.0", | ||
"version": "1.2.1", | ||
"description": "Find a variety of streak metrics from a list of dates.", | ||
@@ -5,0 +5,0 @@ "main": "./dist/index.js", |
@@ -118,7 +118,7 @@ # 🗓⚡️ Date Streaks | ||
Track record returns a list of dates from today into the past with the provided dates marked as `true`. This is especially helpful for features where you want to show users a calendar of dates where they completed some task. | ||
Track record returns a list of dates from a specified date into the past with the provided dates marked as `true`. This is especially helpful for features where you want to show users a calendar of dates where they completed some task. | ||
#### Example | ||
Let's assume today is 1/10/2018. | ||
Let's get a track record for the days preceeding 1/13/2018. | ||
@@ -129,6 +129,6 @@ ```js | ||
const dates = [ | ||
new Date('01/01/2018'), | ||
new Date('01/02/2018'), | ||
new Date('01/08/2018'), | ||
new Date('01/09/2018') | ||
new Date('01/04/2018'), | ||
new Date('01/05/2018'), | ||
new Date('01/11/2018'), | ||
new Date('01/12/2018') | ||
]; | ||
@@ -139,3 +139,7 @@ | ||
trackRecord({ dates, length }); // object filled w/ {dates:Array, length:Number} | ||
// defaults to today's date | ||
const endDate = new Date('01/13/2018'); | ||
trackRecord({ dates, length, endDate }); | ||
``` | ||
@@ -147,12 +151,12 @@ | ||
{ | ||
'Wed Jan 10 2018 00:00:00 GMT-0400': false, | ||
'Tue Jan 09 2018 00:00:00 GMT-0400': true, | ||
'Mon Jan 08 2018 00:00:00 GMT-0400': true, | ||
'Sun Jan 07 2018 00:00:00 GMT-0400': false, | ||
'Sat Jan 06 2018 00:00:00 GMT-0400': false, | ||
'Fri Jan 05 2018 00:00:00 GMT-0400': false, | ||
'Thu Jan 04 2018 00:00:00 GMT-0400': false, | ||
'Wed Jan 03 2018 00:00:00 GMT-0400': false, | ||
'Tue Jan 02 2018 00:00:00 GMT-0400': true, | ||
'Mon Jan 01 2018 00:00:00 GMT-0400': true | ||
'Wed Jan 13 2018 00:00:00 GMT-0400': false, | ||
'Tue Jan 12 2018 00:00:00 GMT-0400': true, | ||
'Mon Jan 11 2018 00:00:00 GMT-0400': true, | ||
'Sun Jan 10 2018 00:00:00 GMT-0400': false, | ||
'Sat Jan 09 2018 00:00:00 GMT-0400': false, | ||
'Fri Jan 08 2018 00:00:00 GMT-0400': false, | ||
'Thu Jan 07 2018 00:00:00 GMT-0400': false, | ||
'Wed Jan 06 2018 00:00:00 GMT-0400': false, | ||
'Tue Jan 05 2018 00:00:00 GMT-0400': true, | ||
'Mon Jan 04 2018 00:00:00 GMT-0400': true | ||
} | ||
@@ -159,0 +163,0 @@ ``` |
const { expect } = require('chai'); | ||
const { getDatesParameter } = require('../dist/helpers') | ||
const { getDatesParameter, sortDates } = require('../dist/helpers'); | ||
@@ -19,2 +19,20 @@ describe('Helpers', () => { | ||
}); | ||
describe('sortDates', () => { | ||
it('should accept an empty array as input', () => { | ||
let result = sortDates([]); | ||
let isSorted = result.every((date, index) => !index || result[index-1] <= date); | ||
expect(isSorted).to.equal(true); | ||
}); | ||
it('should return a sorted array', () => { | ||
let result = sortDates([ | ||
new Date('01/04/2018'), | ||
new Date('01/01/2018'), | ||
new Date('01/03/2018'), | ||
]); | ||
let isSorted = result.every((date, index) => !index || result[index-1] <= date); | ||
expect(isSorted).to.equal(true); | ||
}); | ||
}); | ||
}); |
@@ -1,2 +0,2 @@ | ||
var { startOfDay, subDays, addDays } = require('date-fns'); | ||
var { startOfDay, endOfWeek, subDays, addDays } = require('date-fns'); | ||
var expect = require('chai').expect; | ||
@@ -172,2 +172,21 @@ var summary = require('../dist/summary').default; | ||
}); | ||
it('should take a custom end date', () => { | ||
var today = startOfDay(new Date()); | ||
var result = trackRecord({dates: [today], startDate: endOfWeek(new Date())}); | ||
expect(result[today]).to.equal(true); | ||
}); | ||
it('should take a custom length of days and a custom end date', () => { | ||
var today = startOfDay(new Date()); | ||
var result = trackRecord({dates: [today], length: 10, endDate: endOfWeek(new Date())}); | ||
expect(result[today]).to.equal(true); | ||
}); | ||
it('should accept an empty array as input', () => { | ||
var result = trackRecord({ dates: [] }); | ||
debugger; | ||
expect(Object.keys(result).length).to.equal(7); | ||
}); | ||
}); | ||
@@ -174,0 +193,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
23939
438
176