{"id":19196630,"url":"https://github.com/steveswork/timed-map","last_synced_at":"2026-06-19T17:33:29.498Z","repository":{"id":58400591,"uuid":"454691427","full_name":"steveswork/timed-map","owner":"steveswork","description":"A map with aged entries. Outdated entries are routinely removed from the map.  ","archived":false,"fork":false,"pushed_at":"2025-07-13T07:34:21.000Z","size":674,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-10-31T04:57:18.002Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"HTML","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/steveswork.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-02-02T08:12:29.000Z","updated_at":"2025-07-13T07:34:19.000Z","dependencies_parsed_at":"2023-01-18T20:04:53.478Z","dependency_job_id":null,"html_url":"https://github.com/steveswork/timed-map","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/steveswork/timed-map","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/steveswork%2Ftimed-map","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/steveswork%2Ftimed-map/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/steveswork%2Ftimed-map/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/steveswork%2Ftimed-map/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/steveswork","download_url":"https://codeload.github.com/steveswork/timed-map/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/steveswork%2Ftimed-map/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34541990,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-19T02:00:06.005Z","response_time":61,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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-11-09T12:14:08.503Z","updated_at":"2026-06-19T17:33:29.477Z","avatar_url":"https://github.com/steveswork.png","language":"HTML","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Timed-Map\n\n**Name:** Timed-Map\n\n**Install:**\\\nnpm i -S @webkrafters/timed-map\n\n## Description\n\nAn observable timed map javascript data structure.\nTracks and removes outdated infrequently `read` entries.\n\n## Ideal Use-case\n\nIdeal for in-app Application Level Memoization and Caching.\n\n\n## Usage\n\n```js\nimport TimedMap from '@webkrafters/timed-map';\n\nconst timedMap = new TimedMap( 1000 ); // max-age of 1-second per infrequently-used map entries\n\nconst timedMap = new TimedMap(); // defaults to 30 mins max-age\n\n```\n\n### MapEntry\n\nA map entry object holds the following information:\n```js\n{\n\tcreatedAt: int // Date in millis since epoch\n\tkey: string\n\tvalue: any\n\tttl: int // Duration in millis\n}\n```\n\n## Requirement\n\nThe TimedMap `close()` instance method must be called prior to `delete`ing or setting this map to null.\nThis cleans up the underlying driver along with any system resources used such as cpu timers etc.\n\n## Public Interface\n\n### constructor(maxEntryAgeMillis?: int): TimedMap\n\nCreates an instance of TimedMap. The optional `maxEntryAgeMillis` value is a class-level TTL in milliseconds applied to all entries in the map. A default of 1800000ms (i.e. 30 minutes) is assigned if omitted. Any entry which remained `un-read` at the end of the TTL-cycle is removed. `get(key)` and `getEntry(key)` methods constitute the only valid entry `read` operations. To obtain entry value without restarting the entry TTL-cycle, see the `peak(key)` method. Individual TTLs may be assigned to entries upon insertion. See the `put(...)` method. The individual TTL supersedes the class-level TTL for the individual entry.\n\n### entries: MapEntry[] - readonly\n\nComputed property: available entries.\n\n### isEmpty: boolean - readonly\n\nComputed property: check-flag confirming a map containing no entries.\n\n### keys: string[] - readonlys\n\nComputed property: keys to all available entries.\n\n### maxEntryAge: int\n\nProperty: TTL value in milliseconds applied to map entries. Setting this property triggers adjustments in the map's internal TTL cycle processes.\n\n### size: int - readonly\n\nComputed property: number of entries in the map\n\n### clear(): void\n\nRemoves all entries from the map\n\n### close(): void\n\nRecommended pre-delete method: please use this method to release system resources and clean up the internal driver prior to `delete`ing this TimeMap instance or setting it to null.\n\n### get(key: string): any\n\nReturns the value at key and restarts the entry's TTL cycle. This constitutes a valid `read` operation.\n\n### getEntry(key: string): MapEntry\n\nReturns the entry object residing at key. This constitutes a valid `read` operation.\n\n### has(key: string): boolean\n\nVerifies the presence of a valid map entry at this key\n\n### off(type: EventType, listener: Eventlistener): void\n\nCancels event by listener function reference. Please see Events section below for more on event types and event listener.\n\n### offById(eventId: string): void\n\nCancels event by event ID. Please see Events section below for more on event ID.\n\n### on(type: EventType, listener: Eventlistener, attributes?: Object): string\n\nSubscribes to event of event type and returns unique eventId. Supply any additional info to capture as part of this event to the optional `attributes` object argument. Please see Events section below for more on event types, event ID and event listener.\n\n### once(type: EventType, listener: Eventlistener, attributes?: Object): string\n\nSubscribes to one-use event of event type and returns unique eventId. Supply any additional info to capture as part of this event to the optional `attributes` object argument. Please see Events section below for more on event types, event ID and event listener.\n\n### peak(key: string): any\n\nReturns the value at key without restarting the entry's TTL cycle. \n\n### put(key: string, value: any, ttl?: int ): MapEntry\n\nCreates a new map entry. If an entry existed at the key, it is overriden and returned. When the optional `ttl` value is supplied, it takes precedence over the class-level TTL value for calculating TTL cycles for this entry. Please see the `get` and `getEntry` methods.\n\n### remove( key: string): MapEntry\n\nIf an entry existed at the key, it is removed and returned.\n\n## Events\n\nThis map is observable and provides pathways for notifying observers of relevant changes within. For this purpose, six event types have been provided.\n\n### Event Map Table\n-----------------------------------------------------------------------------------------------------\n|Event Type   |Trigger\t\t\t\t\t\t\t\t\t\t\t\t  |Event Data\n|-------------|-------------------------------------------------------|-------------------------------\n|AUTO_RENEWED | After an entry read (See valid read operations above) |key: string\u003cbr/\u003ecreatedAt: int\u003cbr /\u003epreviouslyCreatedAt: int\n|CLEARED      | After a map `clear` operation\t\t\t\t\t\t  |removed: MapEntry[]\n|CLOSING      | The `close` method call prior to clean up operation.  |undefined\n|PRUNED       | After pruning outdated entries\t\t\t\t\t\t  |removed: MapEntry[]\n|PUT          | After a `put` method call operation\t\t\t\t\t  |current: MapEntry\u003cbr /\u003eprevious: MapEntry\n|REMOVED      | After a `remove` method call operation\t\t\t\t  |removed: MapEntry\n--------------------------------------------------------------------------------------------------------\n\n\u003cu\u003e\u003cb\u003eTiming:\u003c/b\u003e\u003c/u\u003e Excluding the `CLOSING` event, all event listeners are scheduled to run at the conclusion of previously scheduled tasks. `CLOSING` event listeners are run immediately.\n\n-------------------------------------------------------------------------------------------------\n\n### Event Listener\n\nThe event listener is triggered with a lone argument: the event payload. The event payload object emitted contains the following information:\n\n\u003cb\u003eattributes:\u003c/b\u003e Object (Please see the `on` method discussion above)\u003cbr /\u003e\n\u003cb\u003edata:\u003c/b\u003e Event Data Object (See Event Map Table above)\u003cbr /\u003e \n\u003cb\u003edate:\u003c/b\u003e Date - event date\u003cbr /\u003e\n\u003cb\u003eid:\u003c/b\u003e string - event ID\u003cbr /\u003e\n\u003cb\u003etimestamp:\u003c/b\u003e int - event date in milliseconds\u003cbr /\u003e\n\u003cb\u003etype:\u003c/b\u003e Event Type (See Event Map Table above)\u003cbr /\u003e\n\n\u003ci\u003e\u003cu\u003e\u003cb\u003eImmutability:\u003c/b\u003e\u003c/u\u003e With the exception of `attributes` and `date`, immutability is maintained on all properties of the event payload. The `date` property is a native Date instance object. The `attributes` property is presented to the user exactly as defined by the user.\u003c/i\u003e\n\n### Event ID\n\nEvery subscribed event listener is assigned a unique event ID during subscription. The `on` and `once` methods constitute the two avenues for event subscription. These methods return the unique event ID correspondingly. While the listener function reference remains the most popular means for identifying events for cancellation, the event ID is the surest means of accomplishing same purpose. Please see the `off` and `offById` methods.\n\n## License\n\n\tISC\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsteveswork%2Ftimed-map","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsteveswork%2Ftimed-map","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsteveswork%2Ftimed-map/lists"}