Browse Source

Drop standard for xo

pull/5/head
Luke Childs 8 years ago
parent
commit
9f551432d8
  1. 4
      package.json
  2. 20
      src/index.js
  3. 8
      test/unit.js

4
package.json

@ -5,7 +5,7 @@
"main": "src/index.js", "main": "src/index.js",
"scripts": { "scripts": {
"test": "nyc ava", "test": "nyc ava",
"lint": "snazzy", "lint": "xo",
"coverage": "nyc report --reporter=text-lcov | coveralls" "coverage": "nyc report --reporter=text-lcov | coveralls"
}, },
"repository": { "repository": {
@ -33,6 +33,6 @@
"ava": "^0.17.0", "ava": "^0.17.0",
"coveralls": "^2.11.15", "coveralls": "^2.11.15",
"nyc": "^10.0.0", "nyc": "^10.0.0",
"snazzy": "^5.0.0" "xo": "^0.17.1"
} }
} }

20
src/index.js

@ -1,19 +1,19 @@
const addSeconds = require('date-fns/add_seconds') const addSeconds = require('date-fns/add_seconds');
function expired (headers) { function expired(headers) {
const originDate = new Date(headers.date) const originDate = new Date(headers.date);
// Get max age ms // Get max age ms
let maxAge = headers['cache-control'] && headers['cache-control'].match(/max-age=(\d+)/) let maxAge = headers['cache-control'] && headers['cache-control'].match(/max-age=(\d+)/);
maxAge = parseInt(maxAge ? maxAge[1] : 0) maxAge = parseInt(maxAge ? maxAge[1] : 0, 10);
// Take current age into account // Take current age into account
if (headers.age) { if (headers.age) {
maxAge -= headers.age maxAge -= headers.age;
} }
// Calculate expirey date // Calculate expirey date
return addSeconds(new Date(originDate), maxAge) return addSeconds(new Date(originDate), maxAge);
} }
module.exports = expired module.exports = expired;

8
test/unit.js

@ -1,6 +1,6 @@
import test from 'ava' import test from 'ava';
import expired from '../' import expired from '../';
test('expired is a function', t => { test('expired is a function', t => {
t.is(typeof expired, 'function') t.is(typeof expired, 'function');
}) });

Loading…
Cancel
Save