Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

cache-headers

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cache-headers - npm Package Compare versions

Comparing version 0.0.4 to 0.0.5

6

dist/additionalHeaders.js

@@ -17,3 +17,3 @@ /**

* @param {number} [options.maxAge] Additional time to add
* @param {object} [options.testDate] A test date object
* @param {object} [options.date] A test date object
* @param {string} [options.formatType] {@link module:utils#formatDate}

@@ -25,6 +25,6 @@ * @return {{ name: string, value: string }}

var maxAge = options.maxAge;
var testDate = options.testDate;
var date = options.date;
var formatType = options.formatType;
var newTime = utils.addTime({ date: testDate, timeToAdd: maxAge });
var newTime = utils.addTime({ date: date, timeToAdd: maxAge });
var value = utils.formatDate(newTime.toISOString(), formatType);

@@ -31,0 +31,0 @@

@@ -98,5 +98,4 @@ /**

/**
*
* @param {object} options
* @param {object} [options.time=new Date()] Date object
* @param {object} [options.date=new Date()] Date object
* @param {number} [options.timeToAdd=timeValues.TEN_MINUTES] A number of time to add, defaults in seconds

@@ -108,4 +107,4 @@ * @param {string} [options.timeFormat='s'] The time format based on momentjs {{@link http://momentjs.com/docs/#/manipulating/add/}}

var options = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0];
var _options$time = options.time;
var time = _options$time === undefined ? new Date() : _options$time;
var _options$date = options.date;
var date = _options$date === undefined ? new Date() : _options$date;
var _options$timeToAdd = options.timeToAdd;

@@ -116,3 +115,3 @@ var timeToAdd = _options$timeToAdd === undefined ? timeValues.TEN_MINUTES : _options$timeToAdd;

var utcTime = getUtcTime(time);
var utcTime = getUtcTime(date);
return utcTime.add(timeToAdd, timeFormat);

@@ -119,0 +118,0 @@ }

{
"name": "cache-headers",
"version": "0.0.4",
"version": "0.0.5",
"description": "Generate browser and cdn cache header values",

@@ -5,0 +5,0 @@ "main": "dist/index.js",

@@ -17,3 +17,3 @@ /**

* @param {number} [options.maxAge] Additional time to add
* @param {object} [options.testDate] A test date object
* @param {object} [options.date] A test date object
* @param {string} [options.formatType] {@link module:utils#formatDate}

@@ -23,4 +23,4 @@ * @return {{ name: string, value: string }}

function generateExpiresHeader(options = {}) {
const { maxAge, testDate, formatType } = options;
const newTime = utils.addTime({ date: testDate, timeToAdd: maxAge });
const { maxAge, date, formatType } = options;
const newTime = utils.addTime({ date, timeToAdd: maxAge });
const value = utils.formatDate(newTime.toISOString(), formatType);

@@ -27,0 +27,0 @@

@@ -92,5 +92,4 @@ /**

/**
*
* @param {object} options
* @param {object} [options.time=new Date()] Date object
* @param {object} [options.date=new Date()] Date object
* @param {number} [options.timeToAdd=timeValues.TEN_MINUTES] A number of time to add, defaults in seconds

@@ -102,6 +101,6 @@ * @param {string} [options.timeFormat='s'] The time format based on momentjs {{@link http://momentjs.com/docs/#/manipulating/add/}}

const {
time = new Date(),
date = new Date(),
timeToAdd = timeValues.TEN_MINUTES,
timeFormat = 's' } = options;
const utcTime = getUtcTime(time);
const utcTime = getUtcTime(date);
return utcTime.add(timeToAdd, timeFormat);

@@ -108,0 +107,0 @@ }

@@ -214,27 +214,54 @@ /**

it('should setAdditionalHeaders (Expires, Last-Modified)', (done) => {
const testDate = new Date();
const lastModFormatted = utils.formatDate(testDate, 'test');
const timeToAdd = cacheControl.ONE_DAY;
const newDate = utils.addTime({ date: testDate, timeToAdd });
const expiresDate = utils.formatDate(newDate.toISOString(), 'test');
const options = {
expires: {
maxAge: timeToAdd,
testDate: testDate,
formatType: 'test'
},
lastModified: {
date: testDate,
formatType: 'test'
}
};
describe('setAdditionalHeaders (Expires, Last-Modified)', () => {
it("should set headers from today", (done) => {
const testDate = new Date();
const lastModFormatted = utils.formatDate(testDate, 'test');
const timeToAdd = cacheControl.ONE_DAY;
const newDate = utils.addTime({ timeToAdd });
const expiresDate = utils.formatDate(newDate.toISOString(), 'test');
const options = {
expires: {
maxAge: timeToAdd,
date: testDate,
formatType: 'test'
},
lastModified: {
date: testDate,
formatType: 'test'
}
};
app.use(cacheControl.setAdditionalHeaders(options));
agent
.get('/')
.expect('Expires', expiresDate)
.expect('Last-Modified', lastModFormatted)
.end(done);
app.use(cacheControl.setAdditionalHeaders(options));
agent
.get('/')
.expect('Expires', expiresDate)
.expect('Last-Modified', lastModFormatted)
.end(done);
});
it('should set headers from a date that is passed in', (done) => {
const testDate = new Date('2015-12-26');
const lastModFormatted = utils.formatDate(testDate, 'test');
const timeToAdd = cacheControl.ONE_WEEK;
const newDate = utils.addTime({ date: testDate, timeToAdd });
const expiresDate = utils.formatDate(newDate.toISOString(), 'test');
const options = {
expires: {
maxAge: timeToAdd,
date: testDate,
formatType: 'test'
},
lastModified: {
date: testDate,
formatType: 'test'
}
};
app.use(cacheControl.setAdditionalHeaders(options));
agent
.get('/')
.expect('Expires', expiresDate)
.expect('Last-Modified', lastModFormatted)
.end(done);
});
});
});

@@ -78,2 +78,9 @@ /**

});
it('should add time to a pre-existing date', () => {
const date = new Date('2015-12-25');
const utcTime = utils.getUtcTime(date);
const expect = utcTime.add(7, 'd');
const actual = utils.addTime({ date , timeToAdd: 7, timeFormat: 'd' });
assert.strictEqual(actual.toString(), expect.toString());
});
});

@@ -80,0 +87,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc