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

expired

Package Overview
Dependencies
Maintainers
1
Versions
20
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

expired

Calculate when HTTP responses expire from the cache headers

  • 1.0.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
12
decreased by-64.71%
Maintainers
1
Weekly downloads
 
Created
Source

expired

Calculate when HTTP responses expire from the cache headers

Build Status Coverage Status

expired accepts HTTP headers as an argument and will return information on when the resource will expire.

Install

npm install --save expired

Usage

const expired = require('expired');

const headers = {
  'access-control-allow-origin': '*',
  'age': '0',
  'cache-control': 'public, max-age=300',
  'content-encoding': 'gzip',
  'content-type': 'application/json;charset=utf-8',
  'date': 'Fri, 23 Dec 2016 05:50:31 GMT',
  'last-modified': 'Fri, 23 Dec 2016 05:23:23 GMT',
  'vary': 'Accept-Encoding, User-Agent',
  'via': '1.1 varnish-v4'
};

new Date()
// Date('2016-12-23T05:50:31.000Z')

expired(headers)
// false

expired.in(headers)
// 500000

expired.on(headers)
// Date('2016-12-23T05:55:31.000Z')

delay(600000).then(() => {

  new Date()
  // Date('2016-12-23T05:56:31.000Z')

  expired(headers)
  // true

  expired.in(headers)
  // -100000

  expired.on(headers)
  // Date('2016-12-23T05:55:31.000Z')

});

You can also pass headers in as raw text:

const expired = require('expired');

const headers = `
Access-Control-Allow-Origin: *
Age: 0
Cache-Control: public, max-age=300
Content-Encoding: gzip
Content-Type: application/json;charset=utf-8
Date: Fri, 23 Dec 2016 05:50:31 GMT
Last-Modified: Fri, 23 Dec 2016 05:23:23 GMT
Vary: Accept-Encoding, User-Agent
Via: 1.1 varnish-v4`;

expired(headers)
// false

API

expired(headers)

Returns a boolean relating to whether the resource has expired or not. true means it's expired, false means it's fresh.

expired.in(headers)

Returns the amount of milliseconds until the resource will expire. If the resource has already expired it will return a negative integer.

expired.on(headers)

Returns a JavaScript Date object for the date the resource will expire.

License

MIT © Luke Childs

Keywords

FAQs

Package last updated on 23 Dec 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

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