Comparing version 0.0.1 to 0.1.0
{ | ||
"name": "expired", | ||
"version": "0.0.1", | ||
"version": "0.1.0", | ||
"description": "Calculate when HTTP cache headers expire", | ||
@@ -8,3 +8,3 @@ "main": "src/index.js", | ||
"test": "nyc ava", | ||
"lint": "snazzy", | ||
"lint": "xo", | ||
"coverage": "nyc report --reporter=text-lcov | coveralls" | ||
@@ -37,4 +37,4 @@ }, | ||
"nyc": "^10.0.0", | ||
"snazzy": "^5.0.0" | ||
"xo": "^0.17.1" | ||
} | ||
} |
@@ -1,19 +0,22 @@ | ||
const addSeconds = require('date-fns/add_seconds') | ||
const isPast = require('date-fns/is_past'); | ||
const addSeconds = require('date-fns/add_seconds'); | ||
function expired (headers) { | ||
const originDate = new Date(headers.date) | ||
const expired = headers => isPast(expired.on(headers)); | ||
expired.on = headers => { | ||
const originDate = new Date(headers.date); | ||
// Get max age ms | ||
let maxAge = headers['cache-control'] && headers['cache-control'].match(/max-age=(\d+)/) | ||
maxAge = parseInt(maxAge ? maxAge[1] : 0) | ||
let maxAge = headers['cache-control'] && headers['cache-control'].match(/max-age=(\d+)/); | ||
maxAge = parseInt(maxAge ? maxAge[1] : 0, 10); | ||
// Take current age into account | ||
if (headers.age) { | ||
maxAge -= headers.age | ||
} | ||
if (headers.age) { | ||
maxAge -= headers.age; | ||
} | ||
// Calculate expirey date | ||
return addSeconds(new Date(originDate), maxAge) | ||
} | ||
return addSeconds(new Date(originDate), maxAge); | ||
}; | ||
module.exports = expired | ||
module.exports = expired; |
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
3816
21