{"id":18064375,"url":"https://github.com/alrik/filter-iterable-javascript","last_synced_at":"2025-06-23T07:08:43.308Z","repository":{"id":57236017,"uuid":"120823000","full_name":"alrik/filter-iterable-javascript","owner":"alrik","description":"A javascript lib for filtering any iterable or plain object with a simple, convenient api.","archived":false,"fork":false,"pushed_at":"2018-02-08T23:47:04.000Z","size":5,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-06-12T05:48:28.121Z","etag":null,"topics":["array-filter","filter","iterable","javascript","js","map","map-filter","object","object-filter","set","set-filter","string-filter"],"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/alrik.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":"2018-02-08T21:57:47.000Z","updated_at":"2018-02-08T23:44:53.000Z","dependencies_parsed_at":"2022-08-23T16:20:14.609Z","dependency_job_id":null,"html_url":"https://github.com/alrik/filter-iterable-javascript","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/alrik/filter-iterable-javascript","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alrik%2Ffilter-iterable-javascript","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alrik%2Ffilter-iterable-javascript/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alrik%2Ffilter-iterable-javascript/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alrik%2Ffilter-iterable-javascript/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/alrik","download_url":"https://codeload.github.com/alrik/filter-iterable-javascript/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alrik%2Ffilter-iterable-javascript/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":261434132,"owners_count":23157204,"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":["array-filter","filter","iterable","javascript","js","map","map-filter","object","object-filter","set","set-filter","string-filter"],"created_at":"2024-10-31T06:06:13.321Z","updated_at":"2025-06-23T07:08:38.297Z","avatar_url":"https://github.com/alrik.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# filter-iterable-javascript\n\nA handy function for filtering any iterable and objects in javascript.\n\n## Installation\n\n```bash\n$ yarn add filter-it\n# or\n$ npm i -S filter-it\n```\n\n## Usage\n\nThe api is straight forward and oriented on [Array.prototype.filter](https://developer.mozilla.org/de/docs/Web/JavaScript/Reference/Global_Objects/Array/filter).\n\n```js\nconst newIterable = filter(iterable, callback);\n```\n\n### Parameters\n\n#### iterable\nThe iterable or object to filter.\nSupported types are String, Array, TypedArray, Map, Set, (any Iterable) \u0026 Object.\n\n#### callback\nA function to test every element or value of the iterable.\nThe current item will be preserved when the callback returns a truthy value.\n\nThe function takes 3 parameters:\n\n* **value**: The current element being processed.\n* **key**: The corresponding key\n* **iterable**: The iterable passed to filter\n\n### Return Value\n`filter()` returns a new instance of the iterable with only the entries passed the callback.\n\n### Examples\n\n#### Filtering strings\n```js\nfilter(\"a1b2c3d4e5\", char =\u003e char \u003e= \"0\" \u0026\u0026 char \u003c= \"9\"); \n// =\u003e \"12345\"\nfilter(new String(\"a1b2c3d4e5\"), (char, index) =\u003e index \u0026 1); \n// =\u003e [String: '12345']\n```\n\n#### Filtering maps\n```js\nconst map = new Map([['a', 1], ['b', 2], ['c', 3], ['d', 4], ['e', 5]]);\n\nfilter(map, (value, key) =\u003e key === 'b' || value \u0026 1); \n// =\u003e Map { 'a' =\u003e 1, 'b' =\u003e 2, 'c' =\u003e 3, 'e' =\u003e 5 } \n```\n\n#### Filtering sets\n```js\nconst set = new Set(['a', 1, 'b', 2, 'c', 3]);\n\nfilter(set, (value, key) =\u003e value === key \u0026\u0026 typeof value === 'string'); \n// =\u003e Set { 'a', 'b', 'c' } \n```\n\n#### Filtering arrays\n```js\nconst arr = ['a', 1, 'b', 2, 'c', 3];\n\nfilter(arr, (value, index) =\u003e index \u0026 1); \n// =\u003e [ '1', '2', '3' ] \n```\n\n#### Filtering typed arrays\n```js\nconst typedArr = new Int32Array([1, 2, -3, -4, 5]);\n\nfilter(typedArr, i =\u003e i \u003c 0);\n// =\u003e Int32Array [ -3, -4 ]\n```\n\n#### Filtering plain objects\n```js\nconst obj = { a: 1, b: 2, c: 3, d: 4, e: 5 };\n\nfilter(obj, (value, key) =\u003e key === 'b' || value \u0026 1); \n// =\u003e { a: 1, b: 2, c: 3, e: 5 } \n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falrik%2Ffilter-iterable-javascript","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falrik%2Ffilter-iterable-javascript","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falrik%2Ffilter-iterable-javascript/lists"}