{"id":13685504,"url":"https://github.com/lukechilds/expired","last_synced_at":"2025-04-14T16:24:56.939Z","repository":{"id":53725935,"uuid":"77140464","full_name":"lukechilds/expired","owner":"lukechilds","description":"Calculate when HTTP cache headers expire","archived":false,"fork":false,"pushed_at":"2021-03-17T19:17:19.000Z","size":76,"stargazers_count":74,"open_issues_count":6,"forks_count":4,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-04-03T05:33:07.103Z","etag":null,"topics":["cache","headers","http"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/lukechilds.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-12-22T11:51:06.000Z","updated_at":"2023-09-08T17:18:36.000Z","dependencies_parsed_at":"2022-09-10T12:11:22.019Z","dependency_job_id":null,"html_url":"https://github.com/lukechilds/expired","commit_stats":null,"previous_names":[],"tags_count":19,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lukechilds%2Fexpired","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lukechilds%2Fexpired/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lukechilds%2Fexpired/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lukechilds%2Fexpired/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lukechilds","download_url":"https://codeload.github.com/lukechilds/expired/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248804803,"owners_count":21164134,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cache","headers","http"],"created_at":"2024-08-02T14:00:52.683Z","updated_at":"2025-04-14T16:24:56.917Z","avatar_url":"https://github.com/lukechilds.png","language":"JavaScript","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"readme":"# expired\n\n\u003e Calculate when HTTP responses expire from the cache headers\n\n[![Build Status](https://travis-ci.org/lukechilds/expired.svg?branch=master)](https://travis-ci.org/lukechilds/expired)\n[![Coverage Status](https://coveralls.io/repos/github/lukechilds/expired/badge.svg?branch=master)](https://coveralls.io/github/lukechilds/expired?branch=master)\n[![npm](https://img.shields.io/npm/v/expired.svg)](https://www.npmjs.com/package/expired)\n\n`expired` accepts HTTP headers as an argument and will return information on when the resource will expire. `Cache-Control` and `Expires` headers are supported, if both exist `Cache-Control` takes priority ([Why?](http://stackoverflow.com/a/7549558/5625059)).\n\n## Install\n\n```shell\nnpm install --save expired\n```\n\n## Usage\n\n```js\nconst expired = require('expired');\n\nconst headers = `\nAge: 0\nCache-Control: public, max-age=300\nContent-Encoding: gzip\nContent-Type: application/json;charset=utf-8\nDate: Fri, 23 Dec 2016 05:50:31 GMT\nLast-Modified: Fri, 23 Dec 2016 05:23:23 GMT`;\n\nexpired(headers);\n// false\n\nexpired.in(headers);\n// 500000\n\nexpired.on(headers);\n// Date('2016-12-23T05:55:31.000Z')\n\ndelay(600000).then(() =\u003e {\n\n  expired(headers);\n  // true\n\n  expired.in(headers);\n  // -100000\n\n  expired.on(headers);\n  // Date('2016-12-23T05:55:31.000Z')\n\n});\n```\n\nMany HTTP modules will parse response headers into an object for you. `expired` will also accept headers in this format:\n\n```js\nconst expired = require('expired');\n\nconst headers = {\n  'age': '0',\n  'cache-control': 'public, max-age=300',\n  'content-encoding': 'gzip',\n  'content-type': 'application/json;charset=utf-8',\n  'date': 'Fri, 23 Dec 2016 05:50:31 GMT',\n  'last-modified': 'Fri, 23 Dec 2016 05:23:23 GMT'\n};\n\nexpired(headers);\n// false\n```\n\n## Pure Usage\n\nYou can make the functions pure by passing in a JavaScript `Date` object to compare to instead of depending on `new Date()`. This isn't necessary for `expired.on` as it doesn't compare dates and is already pure.\n\nThe following are all pure functions:\n\n```js\nconst headers = `...`;\nconst date = new Date();\n\nexpired(headers, date);\nexpired.in(headers, date);\nexpired.on(headers);\n```\n\n## API\n\n### expired(headers, [date])\n\nReturns a boolean relating to whether the resource has expired or not. `true` means it's expired, `false` means it's fresh.\n\n### expired.in(headers, [date])\n\nReturns the amount of milliseconds from the current date until the resource will expire. If the resource has already expired it will return a negative integer.\n\n### expired.on(headers)\n\nReturns a JavaScript `Date` object for the date the resource will expire.\n\n## License\n\nMIT © Luke Childs\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flukechilds%2Fexpired","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flukechilds%2Fexpired","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flukechilds%2Fexpired/lists"}