Skip to content

Commit

Permalink
Document index.js
Browse files Browse the repository at this point in the history
  • Loading branch information
bredele committed Apr 6, 2018
1 parent 8c9ab68 commit 0b85117
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
19 changes: 19 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@


/**
* Given an expiration date, filter dates that are
* valid, expired or expire soon.
*
* @param {Array} arr
* @param {Number|Date|String} limit
* @param {Number} soon
* @return {Object}
* @api public
*/

module.exports = (arr, limit, soon = 0) => {
const obj = { valid: [], expired: [], soon: []}
limit = parse(limit)
Expand All @@ -17,6 +28,14 @@ module.exports = (arr, limit, soon = 0) => {
}


/**
* Parse given time into a date in ms.
*
* @param {Date|Number|String} time
* @return {Number}
* @api private
*/

function parse (time) {
return typeof time === 'number' ? time : Date.parse(time)
}
4 changes: 2 additions & 2 deletions test/runout.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const test = require('tape')
const runout = require('..')


test('should extract valid and expired dates from a given expiration limit', assert => {
test('should filter valid and expired dates from a given expiration limit', assert => {
assert.plan(1)
const obj = runout([
new Date('01-01-2000').getTime(),
Expand Down Expand Up @@ -51,7 +51,7 @@ test('should convert date strings into ms and sort them', assert => {
})


test('should extract dates that expire soon', assert => {
test('should filter dates that expire soon', assert => {
assert.plan(1)
const obj = runout([
new Date('01-01-2000'),
Expand Down

0 comments on commit 0b85117

Please sign in to comment.