Comparing version 1.2.1 to 1.3.0
{ | ||
"name": "expired", | ||
"version": "1.2.1", | ||
"version": "1.3.0", | ||
"description": "Calculate when HTTP responses expire from the cache headers", | ||
@@ -5,0 +5,0 @@ "main": "src/index.js", |
@@ -14,5 +14,15 @@ const isBefore = require('date-fns/is_before'); | ||
expired.on = headers => { | ||
// Check we have headers | ||
if (!headers) { | ||
throw new Error('Headers argument is missing'); | ||
} | ||
// Parse headers if we got a raw string | ||
headers = (typeof headers === 'string') ? parse(headers) : headers; | ||
// Check we have date header | ||
if (!headers.date) { | ||
throw new Error('Date header is missing'); | ||
} | ||
// Default to Date header | ||
@@ -19,0 +29,0 @@ let expiredOn = new Date(headers.date); |
@@ -6,2 +6,14 @@ import test from 'ava'; | ||
test('throw error if header argument is missing', t => { | ||
const err = t.throws(() => expired()); | ||
t.is(err.message, 'Headers argument is missing'); | ||
}); | ||
test('throw error if Date header is missing', t => { | ||
const headers = {}; | ||
const err = t.throws(() => expired(headers)); | ||
t.is(err.message, 'Date header is missing'); | ||
}); | ||
test('headers can be passed in as an object', t => { | ||
@@ -8,0 +20,0 @@ const date = new Date().toUTCString(); |
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
12957
236