{"id":16814910,"url":"https://github.com/jonasba/recent-searches","last_synced_at":"2025-03-17T03:31:39.158Z","repository":{"id":34606212,"uuid":"180563003","full_name":"JonasBa/recent-searches","owner":"JonasBa","description":"A JavaScript module that helps anyone build recent searches functionality.","archived":false,"fork":false,"pushed_at":"2023-02-28T14:30:18.000Z","size":1337,"stargazers_count":21,"open_issues_count":8,"forks_count":3,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-02-27T17:35:17.453Z","etag":null,"topics":["javascript","search","searchbar","typescript"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","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/JonasBa.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":"2019-04-10T11:00:16.000Z","updated_at":"2025-02-24T18:08:59.000Z","dependencies_parsed_at":"2024-06-18T21:29:55.552Z","dependency_job_id":"a292cf01-97bf-47c6-b0e8-b904d64f41b1","html_url":"https://github.com/JonasBa/recent-searches","commit_stats":{"total_commits":24,"total_committers":3,"mean_commits":8.0,"dds":0.375,"last_synced_commit":"4b5e9dbfd09fc5c51f4274913848f20755e42075"},"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JonasBa%2Frecent-searches","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JonasBa%2Frecent-searches/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JonasBa%2Frecent-searches/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JonasBa%2Frecent-searches/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/JonasBa","download_url":"https://codeload.github.com/JonasBa/recent-searches/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243841207,"owners_count":20356443,"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":["javascript","search","searchbar","typescript"],"created_at":"2024-10-13T10:31:34.184Z","updated_at":"2025-03-17T03:31:38.733Z","avatar_url":"https://github.com/JonasBa.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003ch1 align=\"center\"\u003e\n  recent-searches 🕵️‍♀️🕵️‍♂️\n  \u003cbr\u003e\n  \u003cbr\u003e\n\u003c/h1\u003e\n\u003cp align=\"center\" style=\"font-size: 1.2rem;\"\u003eA zero dependency JavaScript module that helps anyone build recent searches functionality into their search bar.\n\u003c/p\u003e\n\n\n\u003chr /\u003e\n\n[![Build Status][build-badge]][build]\n[![downloads][downloads-badge]][npmcharts] [![version][version-badge]][package]\n[![MIT License][license-badge]][license]\n[![PRs Welcome][prs-badge]][prs]\n[![size][size-badge]][unpkg-dist] [![gzip size][gzip-badge]][unpkg-dist]\n\n![Example implementation](https://raw.githubusercontent.com/JonasBa/recent-searches/master/RecentSearchesUX.gif)\n\n## The problem\n\nBuilding recent searches experience can be trickier than you think (expiry of queries, ranking of recent queries, handling storage etc...)\n\n## Solution\nrecent-searches module helps you build that experience without having to focus on the edge cases and technical details. If available, uses [localStorage](https://developer.mozilla.org/en-US/docs/Web/API/Window/localStorage) to store suggestions cross sessions and in the rare cases where it might not be available uses a fallback memory storage, thus loosing it's cross session functionality.\n\n__The module handles:__\n- Searching and retrieving recent searches\n- Ranking of searches and decaying their popularity (with different ranking options)\n- Saving and expiring of searches through LocalStorage or MemoryStorage\n- LocalStorage feature detection (with fallback to MemoryStorage)\n- Safe LocalStorage usage (feature detection, limiting storage)\n\n## Table of Contents\n\n\u003c!-- START doctoc generated TOC please keep comment here to allow auto update --\u003e\n\u003c!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE --\u003e\n\n- [Installation](#installation)\n- [Usage](#usage)\n- [LICENSE](#license)\n\n\u003c!-- END doctoc generated TOC please keep comment here to allow auto update --\u003e\n\n## Installation\n\nrecent-searches is published on npm's public registry, you can install it as a dependancy of your project with the following command.\n```\nnpm install --save recent-searches\n```\n\n## Usage\n\n\u003e [Standalone codesandbox example](https://codesandbox.io/s/8k21924m5l) \u003cbr/\u003e\n\u003e [Algolia react-instantsearch codesandbox example](https://codesandbox.io/s/m18wjy69) \u003cbr/\u003e\n\u003e [Algolia InstantSearch.js codesandbox example](https://codesandbox.io/s/62j3k7097r)\nInitializing the module\n\n```ts\nimport RecentSearches from 'recent-searches'\n\nconst searches = new RecentSearches({\n  ttl: number, // Optional: ttl of searches in milliseconds, default to 24h (1000 * 60 * 60 * 24)\n  limit: number, // Optional: max number of entries that will be persisted, default is 50\n  namespace: string, // Optional: custom localStorage namespace\n  ranking: string // Optional: ranking strategy of recent searches, \"PROXIMITY\" | \"TIME\" | \"PROXIMITY_AND_TIME\", default is \"PROXIMITY_AND_TIME\"\n})\n\n```\n\nSetting and retrieving relevant searches.\n\n```ts\n// Retrieve searches for a given query\nconst previousSearchesForJohn = searches.getRecentSearches(\"John\")\n/* \n  [ \n    {query: \"John\", data: {...}, timestamp: ...},\n    {query: \"Marc John\", data: {...}, timestamp: ...}\n  ] \n*/\n\n// To set a recent search\nsearches.setRecentSearch(\"John\", resultData)\n\n```\n\nIf you built something using recent-searches that you want to show, feel free to send us a link and we'll include it to the documentation!\n\n## Contributing\n\nThis project is open to contributions, if you have a question, proposal or feedback please open a pull request or issue, we only ask you to be kind and respectful :)\n\nSpecial thanks to [Kent C. Dodds](https://twitter.com/kentcdodds?ref_src=twsrc%5Egoogle%7Ctwcamp%5Eserp%7Ctwgr%5Eauthor) for building downshift (making that demo was much easier)\n\n## LICENSE\n\nMIT\n\n[npm]: https://www.npmjs.com/\n[node]: https://nodejs.org\n[build-badge]: https://circleci.com/gh/JonasBa/recent-searches/tree/master.svg?style=svg\n[build]: https://circleci.com/gh/JonasBa/recent-searches\n[coverage-badge]: https://img.shields.io/codecov/c/github/recent-searches/recent-searches.svg?style=flat-square\n[coverage]: https://codecov.io/github/recent-searches/recent-searches\n[version-badge]: https://img.shields.io/npm/v/recent-searches.svg?style=flat-square\n[package]: https://www.npmjs.com/package/recent-searches\n[downloads-badge]: https://img.shields.io/npm/dm/recent-searches.svg?style=flat-square\n[npmcharts]: http://npmcharts.com/compare/recent-searches\n[license-badge]: https://img.shields.io/npm/l/recent-searches.svg?style=flat-square\n[license]: https://github.com/recent-searches/recent-searches/blob/master/LICENSE\n[prs-badge]: https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square\n[prs]: http://makeapullrequest.com\n[react-badge]: https://img.shields.io/badge/%E2%9A%9B%EF%B8%8F-(p)react-00d8ff.svg?style=flat-square\n[react]: https://facebook.github.io/react/\n[gzip-badge]: http://img.badgesize.io/https://unpkg.com/recent-searches/dist/index.min.js?compression=gzip\u0026label=gzip%20size\u0026style=flat-square\n[size-badge]: http://img.badgesize.io/https://unpkg.com/recent-searches/dist/index.min.js?label=size\u0026style=flat-square\n[unpkg-dist]: https://unpkg.com/recent-searches/dist/\n[module-formats-badge]: https://img.shields.io/badge/module%20formats-umd%2C%20cjs%2C%20es-green.svg?style=flat-square\n[spectrum-badge]: https://withspectrum.github.io/badge/badge.svg\n[spectrum]: https://spectrum.chat/recent-searches\n[emojis]: https://github.com/kentcdodds/all-contributors#emoji-key\n[all-contributors]: https://github.com/kentcdodds/all-contributors\n[ryan]: https://github.com/ryanflorence\n[compound-components-lecture]: https://courses.reacttraining.com/courses/advanced-react/lectures/3060560\n[react-autocomplete]: https://www.npmjs.com/package/react-autocomplete\n[jquery-complete]: https://jqueryui.com/autocomplete/\n[examples]: https://codesandbox.io/search?refinementList%5Btags%5D%5B0%5D=recent-searches%3Aexample\u0026page=1\n[yt-playlist]: https://www.youtube.com/playlist?list=PLV5CVI1eNcJh5CTgArGVwANebCrAh2OUE","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjonasba%2Frecent-searches","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjonasba%2Frecent-searches","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjonasba%2Frecent-searches/lists"}