{"id":15592039,"url":"https://github.com/derhuerst/ttl-buffer","last_synced_at":"2026-03-05T12:30:18.137Z","repository":{"id":57382006,"uuid":"49350269","full_name":"derhuerst/ttl-buffer","owner":"derhuerst","description":"A buffer that removes its entries after a certain time.","archived":false,"fork":false,"pushed_at":"2021-06-25T11:05:22.000Z","size":24,"stargazers_count":2,"open_issues_count":2,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-07T21:45:28.796Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://github.com/derhuerst/ttl-buffer","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"isc","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/derhuerst.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"license.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-01-10T02:29:25.000Z","updated_at":"2021-06-25T15:25:51.000Z","dependencies_parsed_at":"2022-09-13T11:31:45.375Z","dependency_job_id":null,"html_url":"https://github.com/derhuerst/ttl-buffer","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/derhuerst%2Fttl-buffer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/derhuerst%2Fttl-buffer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/derhuerst%2Fttl-buffer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/derhuerst%2Fttl-buffer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/derhuerst","download_url":"https://codeload.github.com/derhuerst/ttl-buffer/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239889939,"owners_count":19713868,"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":[],"created_at":"2024-10-02T23:53:24.548Z","updated_at":"2026-03-05T12:30:18.096Z","avatar_url":"https://github.com/derhuerst.png","language":"JavaScript","readme":"# ttl-buffer ⌛️\n\n*ttl-buffer* is a data structure that represents a **series of values, which can be map-reduced to a result, each having a time to live** (TTL), after which they are removed again. Like [roll-reduce](https://github.com/raineorshine/roll-reduce#roll-reduce), but time-based.\n\n[![npm version](https://img.shields.io/npm/v/ttl-buffer.svg)](https://www.npmjs.com/package/ttl-buffer)\n[![build status](https://img.shields.io/travis/derhuerst/ttl-buffer.svg)](https://travis-ci.org/derhuerst/ttl-buffer)\n[![dev dependency status](https://img.shields.io/david/dev/derhuerst/ttl-buffer.svg)](https://david-dm.org/derhuerst/ttl-buffer#info=devDependencies)\n![ISC-licensed](https://img.shields.io/github/license/derhuerst/ttl-buffer.svg)\n[![support me via GitHub Sponsors](https://img.shields.io/badge/support%20me-donate-fa7664.svg)](https://github.com/sponsors/derhuerst)\n[![chat with me on Twitter](https://img.shields.io/badge/chat%20with%20me-on%20Twitter-1da1f2.svg)](https://twitter.com/derhuerst)\n\n\n## Installing\n\n```\nnpm install ttl-buffer\n```\n\n\n## Example\n\n```javascript\nconst ttlBuffer = require('ttl-buffer')\n\nconst sumOfLastSecond = ttlBuffer({\n\tttl:          1000, // time in milliseconds\n\tinitialValue: 0,\n\t// This function will be called once you `push` a value.\n\tin:           (before, entry) =\u003e before + entry,\n\t// This function will be called once a value's TTL is over.\n\tout:          (before, entry) =\u003e before - entry\n})\n\nsumOfLastSecond.push(1).push(2)\nsumOfLastSecond.valueOf() // -\u003e 3\n\n// 500ms later\nsumOfLastSecond.push(3)\nsumOfLastSecond.valueOf() // -\u003e 6\n\n// 600ms later, TTL of `1` and `2` is over\nsumOfLastSecond.valueOf() // -\u003e 3\n\n// 500ms later, TTL of `3` is over\nsumOfLastSecond.valueOf() // -\u003e 0\n```\n\n\n\n## Contributing\n\nIf you **have a question**, **found a bug** or want to **propose a feature**, have a look at [the issues page](https://github.com/derhuerst/ttl-buffer/issues).\n","funding_links":["https://github.com/sponsors/derhuerst"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fderhuerst%2Fttl-buffer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fderhuerst%2Fttl-buffer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fderhuerst%2Fttl-buffer/lists"}