{"id":20099176,"url":"https://github.com/ryanfarber/collector","last_synced_at":"2026-06-07T03:33:17.489Z","repository":{"id":215348151,"uuid":"738735449","full_name":"ryanfarber/collector","owner":"ryanfarber","description":"a collector with persistance","archived":false,"fork":false,"pushed_at":"2024-01-04T00:06:29.000Z","size":18,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-19T18:06:51.079Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","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/ryanfarber.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-01-03T23:30:56.000Z","updated_at":"2024-01-03T23:31:33.000Z","dependencies_parsed_at":null,"dependency_job_id":"2897b00f-4cfa-4b8a-99f6-44f30c857512","html_url":"https://github.com/ryanfarber/collector","commit_stats":{"total_commits":13,"total_committers":1,"mean_commits":13.0,"dds":0.0,"last_synced_commit":"cf08ba667c584caaf79dffe83bfcd8fbbb8664f5"},"previous_names":["ryanfarber/collector"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ryanfarber%2Fcollector","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ryanfarber%2Fcollector/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ryanfarber%2Fcollector/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ryanfarber%2Fcollector/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ryanfarber","download_url":"https://codeload.github.com/ryanfarber/collector/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241502894,"owners_count":19972956,"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-11-13T17:08:38.618Z","updated_at":"2025-03-02T16:41:42.212Z","avatar_url":"https://github.com/ryanfarber.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# collector\n \nA persistant collector, useful when making long polling requests for data.  This will continuously write data to a local JSON file, to persist, even in the event of network errors, or anything else that would cause you to loose data if it was in-memory.\n\n```javascript\nconst Collector = require(\"@ryanforever/collector\")\nconst collector = new Collector({\n\tname: \"test\",\n\tsavePath: \"../tmp\"\n})\n\nlongPollingFunction.on(\"data\", data =\u003e {\n\tcollector.push(\"items\", data) // push data with a key and value. collector will save it to the JSON file\n\tcollector.push(\"items\" ...data) // if data is an array\n})\n\nlongPollingFunction.on(\"done\", () =\u003e {\n\tlet result = collector.get() // get \n\tconsole.log(result)\n\tcollector.delete() // delete the collector's json file\n})\n```\n\n## usage\n\nInitialize the collector.  This will create a JSON file at `../temp/test_collector.json`\n```javascript\nconst Collector = require(\"@ryanforever/collector\")\nconst collector = new Collector({\n\tname: \"test\",\n\tsavePath: \"../tmp\"\n})\n````\n\nPush data into a collector\n```javascript\n// push an array of items in, using the spread operator.  same functionality as javascripts Array.prototype.push\nlet arrayOfItems = [\"apple\", \"orange\", \"banana\", \"pear\"]\ncollector.push(\"items\", ...arrayOfItems)\n\n// push a single item\ncollector.push(\"items\", \"strawberry\")\n````\n\nGet data from collector\n```javascript\n// get a single collector\nlet items = collector.get(\"items\")\n\n// get all collectors\nlet allCollectorData = collector.get()\n````\n\n---\n\n## methods\n```javascript\ncollector.push(\"key\", value) // will create a new key if not exist, and push data into it\ncollector.add(\"key\", value) // alias for .push()\n\ncollector.get(\"key\") // get collector array by key\ncollector.get() // get all collector arrays\n\ncollector.has(\"key\") // returns true if key exists\n\ncollector.clear(\"key\") // clear a single collector array\ncollector.clear() // clear all collector arrays\n\ncollector.delete() // ⚠️ deletes the actual JSON file of the collector\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fryanfarber%2Fcollector","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fryanfarber%2Fcollector","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fryanfarber%2Fcollector/lists"}