{"id":14957493,"url":"https://github.com/mcabreradev/filter","last_synced_at":"2025-10-01T17:30:48.627Z","repository":{"id":34295999,"uuid":"174906589","full_name":"mcabreradev/filter","owner":"mcabreradev","description":"Filters an array based on the provided expression.","archived":false,"fork":false,"pushed_at":"2024-03-21T13:47:23.000Z","size":273,"stargazers_count":7,"open_issues_count":1,"forks_count":1,"subscribers_count":3,"default_branch":"dev","last_synced_at":"2025-01-16T02:22:09.089Z","etag":null,"topics":["array","array-methods","arrays","arrow-functions","back-end","backend","es6","filter","front-end","frontend","javascript","next","nextjs","node","node-js","nodejs","object","search","toolset","typescript"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mcabreradev.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-03-11T01:50:48.000Z","updated_at":"2024-04-19T20:43:15.000Z","dependencies_parsed_at":"2023-11-14T16:41:07.544Z","dependency_job_id":"f6af3b5e-8373-4f9b-82b1-6044af2bf0db","html_url":"https://github.com/mcabreradev/filter","commit_stats":null,"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mcabreradev%2Ffilter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mcabreradev%2Ffilter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mcabreradev%2Ffilter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mcabreradev%2Ffilter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mcabreradev","download_url":"https://codeload.github.com/mcabreradev/filter/tar.gz/refs/heads/dev","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":234883314,"owners_count":18901366,"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","array-methods","arrays","arrow-functions","back-end","backend","es6","filter","front-end","frontend","javascript","next","nextjs","node","node-js","nodejs","object","search","toolset","typescript"],"created_at":"2024-09-24T13:14:58.863Z","updated_at":"2025-10-01T17:30:48.308Z","avatar_url":"https://github.com/mcabreradev.png","language":"TypeScript","readme":"# Filter\n\n\u003e Filters the array to a subset of it based on provided criteria.\n\n\u003cp\u003e\n  \u003ca aria-label=\"NPM version\" href=\"https://www.npmjs.com/package/classnames\"\u003e\n    \u003cimg alt=\"\" src=\"https://img.shields.io/npm/v/@mcabreradev/filter.svg?style=for-the-badge\u0026labelColor=0869B8\"\u003e\n  \u003c/a\u003e\n  \u003ca aria-label=\"License\" href=\"#\"\u003e\n    \u003cimg alt=\"\" src=\"https://img.shields.io/npm/l/classnames.svg?style=for-the-badge\u0026labelColor=579805\"\u003e\n  \u003c/a\u003e\n\n\u003c/p\u003e\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## Table of Contents\n\n- [Motivation](#motivation)\n- [About The Project](#about-the-project)\n- [Installation](#installation)\n- [Usage](#usage)\n- [Features](#features)\n  - [Array Filtering:](#array-filtering)\n  - [Case-Insensitive Search:](#case-insensitive-search)\n  - [Wildcard Matching:](#wildcard-matching)\n  - [Multiple Conditions:](#multiple-conditions)\n  - [Custom Predicate Functions:](#custom-predicate-functions)\n  - [Deep Comparison:](#deep-comparison)\n  - [Negation:](#negation)\n  - [Nested Objects:](#nested-objects)\n- [Advanced Examples of Use](#advanced-examples-of-use)\n  - [Filters customers with a specific city](#filters-customers-with-a-specific-city)\n  - [Filters customers with a specific city with wildcard `%`](#filters-customers-with-a-specific-city-with-wildcard-%25)\n  - [Filters customers with a specific city with wildcard \\_](#filters-customers-with-a-specific-city-with-wildcard-%5C_)\n  - [Filters customers based on objects](#filters-customers-based-on-objects)\n  - [Filters customers based on object key value with wilcards `%`](#filters-customers-based-on-object-key-value-with-wilcards-%25)\n  - [Filters customers based on a predicate function](#filters-customers-based-on-a-predicate-function)\n  - [Filters customers based on based on two cities](#filters-customers-based-on-based-on-two-cities)\n  - [Filters customers based on based on two cities if exists](#filters-customers-based-on-based-on-two-cities-if-exists)\n- [Tests](#tests)\n- [Philosophy](#philosophy)\n- [About the Author](#about-the-author)\n- [Copyright](#copyright)\n\n\u003c!-- END doctoc generated TOC please keep comment here to allow auto update --\u003e\n\n## Motivation\n\nThe motivation behind this project is to provide a robust, versatile, and comprehensive filter function that can handle a wide array of use cases. Filtering is a fundamental operation in programming, especially in data manipulation and analysis. However, the built-in filter function in JavaScript and TypeScript can sometimes be limited in its capabilities, especially when dealing with complex data structures and filtering conditions.\n\nThis project aims to overcome these limitations by providing a filter function that is not only more powerful, but also easier to use. It supports filtering arrays of primitive values, objects, and even nested objects. It also supports complex filtering expressions, including wildcard characters and regular expressions. This makes it a versatile tool that can be used in a wide variety of scenarios.\n\n## About The Project\n\nThis project provides a comprehensive implementation of a `filter` function in TypeScript. The `filter` function is a versatile tool that can be used to select a subset of items from an array based on a provided predicate function or expression.\n\nThe `filter` function in this project is designed to handle a wide variety of use cases. It can `filter` arrays of primitive values, objects, and even nested objects. The function also supports complex `filtering` expressions, including wildcard characters and regular expressions.\n\nWhether you need to `filter` an array in a complex way, or you're just interested in understanding how a robust `filter` function can be implemented, this project is a valuable resource.\n\n## Installation\n\nYou can install this package using various package managers. Here are the commands for each of them:\n\nnpm\n\n```shell\nnpm install @mcabreradev/filter\n```\n\nyarn\n\n```shell\nyarn add @mcabreradev/filter\n```\n\npnpm\n\n```shell\npnpm add @mcabreradev/filter\n```\n\nbun\n\n```shell\nbun install @mcabreradev/filter\n```\n\n## Usage\n\nAfter installation, you can import the filter function from the package like this:\n\n```ts\nimport filter from '@mcabreradev/filter';\n```\n\nIf you're working in a Node.js environment, the installation process is the same as mentioned before. However, you can use the CommonJS syntax to import the filter function:\n\n```ts\nconst filter = require('@mcabreradev/filter');\n```\n\n## Features\n\nThe `filter` function in the provided TypeScript code is a versatile function that allows you to select a subset of items from an array based on a variety of conditions. Here are some of its key features:\n\n\u003c/br\u003e\n\n### Array Filtering:\n\nThe primary purpose of the `filter` function is to filter an array. It takes an array and a predicate function as arguments, and returns a new array that includes only the items for which the predicate function returns `true`.\n\n```ts\nimport filter from '@mcabreradev/filter';\n\nconst numbers = [1, 2, 3, 4, 5];\nconst evenNumbers = filter(numbers, (n) =\u003e n % 2 === 0);\n\nconsole.log(evenNumbers); // Output: [2, 4]\n```\n\n\u003c/br\u003e\n\n### Case-Insensitive Search:\n\nThe `filter` function supports case-insensitive search. When you provide a string as the predicate, it will match any property of the objects in the array that contains the string, regardless of case.\n\n```ts\nimport filter from '@mcabreradev/filter';\n\nconst words = ['Apple', 'Banana', 'Cherry'];\nconst result = filter(words, 'a');\n\nconsole.log(result); // Output: ['Apple', 'Banana']\n```\n\n\u003c/br\u003e\n\n### Wildcard Matching:\n\nThe `filter` function supports wildcard matching with the `%` and `_` characters. The `%` character matches any sequence of characters, and the `_` character matches any single character. These wildcards also work in a case-insensitive manner.\n\n```ts\nimport filter from '@mcabreradev/filter';\n\nconst words = ['Apple', 'Banana', 'Cherry'];\nconst result = filter(words, 'A%e');\n\nconsole.log(result); // Output: ['Apple']\n```\n\n\u003c/br\u003e\n\n### Multiple Conditions:\n\nThe `filter` function allows you to filter an array based on multiple conditions. You can specify these conditions as an object, where each key-value pair represents a condition that the items in the array must meet to be included in the result.\n\n```ts\nimport filter from '@mcabreradev/filter';\n\nconst users = [\n  { name: 'Alice', age: 20 },\n  { name: 'Bob', age: 25 },\n  { name: 'Charlie', age: 30 },\n];\nconst result = filter(users, { name: 'A%', age: 20 });\n\nconsole.log(result); // Output: [{ name: 'Alice', age: 20 }]\n```\n\n\u003c/br\u003e\n\n### Custom Predicate Functions:\n\nThe `filter` function allows you to provide a custom predicate function to determine which items should be included in the result. This gives you maximum flexibility to define your own conditions for filtering the array.\n\n```ts\nimport filter from '@mcabreradev/filter';\n\nconst numbers = [1, 2, 3, 4, 5];\nconst result = filter(numbers, (n) =\u003e n \u003e 3);\n\nconsole.log(result); // Output: [4, 5]\n```\n\n\u003c/br\u003e\n\n### Deep Comparison:\n\nThe `filter` function supports deep comparison of objects. This means that it can compare the properties of nested objects, not just the top-level properties.\n\n```ts\nimport filter from '@mcabreradev/filter';\n\nconst users = [\n  { name: 'Alice', age: 20, address: { city: 'New York' } },\n  { name: 'Bob', age: 25, address: { city: 'Los Angeles' } },\n  { name: 'Charlie', age: 30, address: { city: 'Chicago' } },\n];\nconst result = filter(users, { address: { city: 'New York' } });\n\nconsole.log(result); // Output: [{ name: 'Alice', age: 20, address: { city: 'New York' } }]\n```\n\n\u003c/br\u003e\n\n### Negation:\n\nThe `filter` function supports negation. If the predicate is a string that starts with `!`, the function will include an item in the result only if it does not match the rest of the string.\n\n```ts\nimport filter from '@mcabreradev/filter';\n\nconst words = ['Apple', 'Banana', 'Cherry'];\nconst result = filter(words, '!Apple');\n\nconsole.log(result); // Output: ['Banana', 'Cherry']\n```\n\n\u003c/br\u003e\n\n### Nested Objects:\n\nThe `filter` function can filter arrays with a nested object that has 2 node levels:\n\n```ts\nimport filter from '@mcabreradev/filter';\n\nconst users = [\n  { name: 'Alice', age: 20, address: { city: 'New York', country: 'USA' } },\n  { name: 'Bob', age: 25, address: { city: 'Los Angeles', country: 'USA' } },\n  { name: 'Charlie', age: 30, address: { city: 'London', country: 'UK' } },\n];\nconst result = filter(users, { address: { country: 'USA' } });\n\nconsole.log(result);\n\n// Output:\n//[\n// { name: 'Alice', age: 20, address: { city: 'New York', country: 'USA' } },\n// { name: 'Bob', age: 25, address: { city: 'Los Angeles', country: 'USA' } }\n//]\n```\n\n\u003cbr/\u003e\n\nAnd here's an example of `filter` function with a nested object that has 3 node levels:\n\n```ts\nimport filter from '@mcabreradev/filter';\n\nconst users = [\n  {\n    name: 'Alice',\n    age: 20,\n    address: {\n      city: 'New York',\n      country: 'USA',\n      coordinates: { lat: 40.7128, long: 74.006 },\n    },\n  },\n  {\n    name: 'Bob',\n    age: 25,\n    address: {\n      city: 'Los Angeles',\n      country: 'USA',\n      coordinates: { lat: 34.0522, long: 118.2437 },\n    },\n  },\n  {\n    name: 'Charlie',\n    age: 30,\n    address: {\n      city: 'London',\n      country: 'UK',\n      coordinates: { lat: 51.5074, long: 0.1278 },\n    },\n  },\n];\n\nconst result = filter(users, { address: { coordinates: { lat: 40.7128 } } });\n\nconsole.log(result);\n\n// Output:\n// [{\n//   name: 'Alice',\n//   age: 20,\n//   address: {\n//       city: 'New York',\n//       country: 'USA',\n//       coordinates: {\n//           lat: 40.7128,\n//           long: 74.0060\n//       }\n//   }\n// }]\n```\n\n\u003c/br\u003e\n\n## Advanced Examples of Use\n\nThe `filter` function can be used in a wide variety of scenarios. Here are some examples of how it can be used:\n\n### Filters customers with a specific city\n\n```ts\nimport filter from '@mcabreradev/filter';\n\nconst customers = [\n  { name: 'Alfreds Futterkiste', city: 'Berlin' },\n  { name: 'Around the Horn', city: 'London' },\n  { name: \"B's Beverages\", city: 'London' },\n  { name: 'Bolido Comidas preparadas', city: 'Madrid' },\n  { name: 'Bon app', city: 'Marseille' },\n  { name: 'Bottom-Dollar Marketse', city: 'Tsawassen' },\n  { name: 'Cactus Comidas para llevar', city: 'Buenos Aires' },\n];\n\nfilter(customers, 'Berlin');\n\n// Output:\n// [{ name: 'Alfreds Futterkiste', city: 'Berlin' }]\n```\n\n### Filters customers with a specific city with wildcard `%`\n\nThe `%` wildcard represents any number of characters, even zero characters.\n\nreturn all customers that contains the pattern `'erlin'`:\n\n```ts\nimport filter from '@mcabreradev/filter';\n\nconst customers = [\n  { name: 'Alfreds Futterkiste', city: 'Berlin' },\n  { name: 'Around the Horn', city: 'London' },\n  { name: \"B's Beverages\", city: 'London' },\n  { name: 'Bolido Comidas preparadas', city: 'Madrid' },\n  { name: 'Bon app', city: 'Marseille' },\n  { name: 'Bottom-Dollar Marketse', city: 'Tsawassen' },\n  { name: 'Cactus Comidas para llevar', city: 'Buenos Aires' },\n];\n\nfilter(customers, '%erlin');\n\n// Output:\n// [{ name: 'Alfreds Futterkiste', city: 'Berlin' }]\n```\n\n\u003cbr/\u003e\n\nreturn all customers that contains the pattern `\"Ber\"`:\n\n```ts\nimport filter from '@mcabreradev/filter';\n\nconst customers = [\n  { name: 'Alfreds Futterkiste', city: 'Berlin' },\n  { name: 'Around the Horn', city: 'London' },\n  { name: \"B's Beverages\", city: 'London' },\n  { name: 'Bolido Comidas preparadas', city: 'Madrid' },\n  { name: 'Bon app', city: 'Marseille' },\n  { name: 'Bottom-Dollar Marketse', city: 'Tsawassen' },\n  { name: 'Cactus Comidas para llevar', city: 'Buenos Aires' },\n];\n\nfilter(customers, 'Ber%');\n\n// Output:\n// [{ name: 'Alfreds Futterkiste', city: 'Berlin' }]\n```\n\n\u003cbr/\u003e\n\nreturn all customers that contains the pattern `\"erli\"`:\n\n```ts\nimport filter from '@mcabreradev/filter';\n\nconst customers = [\n  { name: 'Alfreds Futterkiste', city: 'Berlin' },\n  { name: 'Around the Horn', city: 'London' },\n  { name: \"B's Beverages\", city: 'London' },\n  { name: 'Bolido Comidas preparadas', city: 'Madrid' },\n  { name: 'Bon app', city: 'Marseille' },\n  { name: 'Bottom-Dollar Marketse', city: 'Tsawassen' },\n  { name: 'Cactus Comidas para llevar', city: 'Buenos Aires' },\n];\n\nfilter(customers, '%erli%');\n\n// Output:\n// [{ name: 'Alfreds Futterkiste', city: 'Berlin' }]\n```\n\n---\n\n### Filters customers with a specific city with wildcard \\_\n\nThe `_` wildcard represents a single character. It can be any character or number, but each `_` represents one, and only one, character.\n\nreturn all customers with a City starting with any character, followed by `\"erlin\"`:\n\n\u003cbr/\u003e\n\n```ts\nimport filter from '@mcabreradev/filter';\n\nconst customers = [\n  { name: 'Alfreds Futterkiste', city: 'Berlin' },\n  { name: 'Around the Horn', city: 'London' },\n  { name: \"B's Beverages\", city: 'London' },\n  { name: 'Bolido Comidas preparadas', city: 'Madrid' },\n  { name: 'Bon app', city: 'Marseille' },\n  { name: 'Bottom-Dollar Marketse', city: 'Tsawassen' },\n  { name: 'Cactus Comidas para llevar', city: 'Buenos Aires' },\n];\n\nfilter(customers, '_erlin');\n\n// Output:\n// [{ name: 'Alfreds Futterkiste', city: 'Berlin' }]\n```\n\n\u003cbr/\u003e\n\nreturn all customers with a City witch contains `\"erli\"`:\n\n```ts\nimport filter from '@mcabreradev/filter';\n\nconst customers = [\n  { name: 'Alfreds Futterkiste', city: 'Berlin' },\n  { name: 'Around the Horn', city: 'London' },\n  { name: \"B's Beverages\", city: 'London' },\n  { name: 'Bolido Comidas preparadas', city: 'Madrid' },\n  { name: 'Bon app', city: 'Marseille' },\n  { name: 'Bottom-Dollar Marketse', city: 'Tsawassen' },\n  { name: 'Cactus Comidas para llevar', city: 'Buenos Aires' },\n];\n\nfilter(customers, '_erli_');\n\n// Output:\n// [{ name: 'Alfreds Futterkiste', city: 'Berlin' }]\n```\n\n\u003cbr/\u003e\n\nreturn all customers with a City starting with `\"L\"`, followed by any 2 characters, ending with `\"lin\"`:\n\n```ts\nimport filter from '@mcabreradev/filter';\n\nconst customers = [\n  { name: 'Alfreds Futterkiste', city: 'Berlin' },\n  { name: 'Around the Horn', city: 'London' },\n  { name: \"B's Beverages\", city: 'London' },\n  { name: 'Bolido Comidas preparadas', city: 'Madrid' },\n  { name: 'Bon app', city: 'Marseille' },\n  { name: 'Bottom-Dollar Marketse', city: 'Tsawassen' },\n  { name: 'Cactus Comidas para llevar', city: 'Buenos Aires' },\n];\n\nfilter(customers, 'B__lin');\n\n// Output:\n// [{ name: 'Alfreds Futterkiste', city: 'Berlin' }]\n```\n\n\u003cbr/\u003e\n\n### Filters customers based on objects\n\nreturn all customers with a City named `\"Berlin\"`:\n\n```ts\nimport filter from '@mcabreradev/filter';\n\nconst customers = [\n  { name: 'Alfreds Futterkiste', city: 'Berlin' },\n  { name: 'Around the Horn', city: 'London' },\n  { name: \"B's Beverages\", city: 'London' },\n  { name: 'Bolido Comidas preparadas', city: 'Madrid' },\n  { name: 'Bon app', city: 'Marseille' },\n  { name: 'Bottom-Dollar Marketse', city: 'Tsawassen' },\n  { name: 'Cactus Comidas para llevar', city: 'Buenos Aires' },\n];\n\nfilter(customers, { city: 'Berlin' });\n\n// Output:\n// [{ name: 'Alfreds Futterkiste', city: 'Berlin' }]\n```\n\n\u003cbr/\u003e\n\n### Filters customers based on object key value with wilcards `%`\n\nreturn all customers with a City witch contains `\"erlin\"` at the end of the string:\n\n```ts\nimport filter from '@mcabreradev/filter';\n\nconst customers = [\n  { name: 'Alfreds Futterkiste', city: 'Berlin' },\n  { name: 'Around the Horn', city: 'London' },\n  { name: \"B's Beverages\", city: 'London' },\n  { name: 'Bolido Comidas preparadas', city: 'Madrid' },\n  { name: 'Bon app', city: 'Marseille' },\n  { name: 'Bottom-Dollar Marketse', city: 'Tsawassen' },\n  { name: 'Cactus Comidas para llevar', city: 'Buenos Aires' },\n];\n\nfilter(customers, { city: '%erlin' });\n\n// Output:\n// [{ name: 'Alfreds Futterkiste', city: 'Berlin' }]\n```\n\n\u003cbr/\u003e\n\nreturn all customers with a City witch contains `\"erli\"` at the begining of the string:\n\n```ts\nimport filter from '@mcabreradev/filter';\n\nconst customers = [\n  { name: 'Alfreds Futterkiste', city: 'Berlin' },\n  { name: 'Around the Horn', city: 'London' },\n  { name: \"B's Beverages\", city: 'London' },\n  { name: 'Bolido Comidas preparadas', city: 'Madrid' },\n  { name: 'Bon app', city: 'Marseille' },\n  { name: 'Bottom-Dollar Marketse', city: 'Tsawassen' },\n  { name: 'Cactus Comidas para llevar', city: 'Buenos Aires' },\n];\n\nfilter(customers, { city: 'Berl%' });\n\n// Output:\n// [{ name: 'Alfreds Futterkiste', city: 'Berlin' }]\n```\n\n\u003cbr/\u003e\n\nreturn all customers with a City witch contains `\"erlin\"` at the end of the string:\n\n```ts\nimport filter from '@mcabreradev/filter';\n\nconst customers = [\n  { name: 'Alfreds Futterkiste', city: 'Berlin' },\n  { name: 'Around the Horn', city: 'London' },\n  { name: \"B's Beverages\", city: 'London' },\n  { name: 'Bolido Comidas preparadas', city: 'Madrid' },\n  { name: 'Bon app', city: 'Marseille' },\n  { name: 'Bottom-Dollar Marketse', city: 'Tsawassen' },\n  { name: 'Cactus Comidas para llevar', city: 'Buenos Aires' },\n];\n\nfilter(customers, { city: '_erlin' });\n\n// Output:\n// [{ name: 'Alfreds Futterkiste', city: 'Berlin' }]\n```\n\n\u003cbr/\u003e\n\nreturn all customers with a City witch contains `\"erl\"` in the string:\n\n```ts\nimport filter from '@mcabreradev/filter';\n\nconst customers = [\n  { name: 'Alfreds Futterkiste', city: 'Berlin' },\n  { name: 'Around the Horn', city: 'London' },\n  { name: \"B's Beverages\", city: 'London' },\n  { name: 'Bolido Comidas preparadas', city: 'Madrid' },\n  { name: 'Bon app', city: 'Marseille' },\n  { name: 'Bottom-Dollar Marketse', city: 'Tsawassen' },\n  { name: 'Cactus Comidas para llevar', city: 'Buenos Aires' },\n];\n\nfilter(customers, { city: '_erl__' });\n\n// Output:\n// [{ name: 'Alfreds Futterkiste', city: 'Berlin' }]\n```\n\n\u003cbr/\u003e\n\nreturn all customers with a City witch contains the characters `\"e,li\"` in the string:\n\n```ts\nimport filter from '@mcabreradev/filter';\n\nconst customers = [\n  { name: 'Alfreds Futterkiste', city: 'Berlin' },\n  { name: 'Around the Horn', city: 'London' },\n  { name: \"B's Beverages\", city: 'London' },\n  { name: 'Bolido Comidas preparadas', city: 'Madrid' },\n  { name: 'Bon app', city: 'Marseille' },\n  { name: 'Bottom-Dollar Marketse', city: 'Tsawassen' },\n  { name: 'Cactus Comidas para llevar', city: 'Buenos Aires' },\n];\n\nfilter(customers, { city: '_e_li_' });\n\n// Output:\n// [{ name: 'Alfreds Futterkiste', city: 'Berlin' }]\n```\n\n\u003cbr/\u003e\n\n### Filters customers based on a predicate function\n\n```ts\nimport filter from '@mcabreradev/filter';\n\nconst customers = [\n  { name: 'Alfreds Futterkiste', city: 'Berlin' },\n  { name: 'Around the Horn', city: 'London' },\n  { name: \"B's Beverages\", city: 'London' },\n  { name: 'Bolido Comidas preparadas', city: 'Madrid' },\n  { name: 'Bon app', city: 'Marseille' },\n  { name: 'Bottom-Dollar Marketse', city: 'Tsawassen' },\n  { name: 'Cactus Comidas para llevar', city: 'Buenos Aires' },\n];\n\nfilter(customers, ({ city }) =\u003e city === 'Berlin');\n\n// Output:\n// [{ name: 'Alfreds Futterkiste', city: 'Berlin' }]\n```\n\n\u003cbr/\u003e\n\n### Filters customers based on based on two cities\n\n```ts\nimport filter from '@mcabreradev/filter';\n\nconst customers = [\n  { name: 'Alfreds Futterkiste', city: 'Berlin' },\n  { name: 'Around the Horn', city: 'London' },\n  { name: \"B's Beverages\", city: 'London' },\n  { name: 'Bolido Comidas preparadas', city: 'Madrid' },\n  { name: 'Bon app', city: 'Marseille' },\n  { name: 'Bottom-Dollar Marketse', city: 'Tsawassen' },\n  { name: 'Cactus Comidas para llevar', city: 'Buenos Aires' },\n];\n\nfilter(customers, ({ city }) =\u003e city === 'Berlin' || city === 'London');\n\n// Output:\n// [\n//  { name: 'Alfreds Futterkiste', city: 'Berlin' },\n//  { name: 'Around the Horn', city: 'London' },\n//  { name: 'Bs Beverages', city: 'London' }\n// ]\n```\n\n\u003cbr/\u003e\n\n### Filters customers based on based on two cities if exists\n\n```ts\nimport filter from '@mcabreradev/filter';\n\nconst customers = [\n  { name: 'Alfreds Futterkiste', city: 'Berlin' },\n  { name: 'Around the Horn', city: 'London' },\n  { name: \"B's Beverages\", city: 'London' },\n  { name: 'Bolido Comidas preparadas', city: 'Madrid' },\n  { name: 'Bon app', city: 'Marseille' },\n  { name: 'Bottom-Dollar Marketse', city: 'Tsawassen' },\n  { name: 'Cactus Comidas para llevar', city: 'Buenos Aires' },\n];\n\nfilter(customers, ({ city }) =\u003e city === 'Berlin' \u0026\u0026 city === 'Caracas');\n\n// Output:\n// []\n```\n\n## Tests\n\n```bash\n$ npm run test\n```\n\n## Philosophy\n\nThe philosophy behind this project is to provide a robust, flexible, and efficient solution for filtering arrays in TypeScript. We believe in the power of simplicity and readability, and we strive to make our code as clear and understandable as possible. We also believe in the importance of performance, and we have designed our filter function to be highly efficient, even when dealing with large arrays and complex filtering conditions.\n\n## About the Author\n\nThis project is maintained by [Miguelangel Cabrera](https://mcabrera.dev), a passionate software developer with a deep interest in TypeScript and functional programming. Miguelangel has years of experience in software development and a strong commitment to code quality, performance, and maintainability.\n\n## Copyright\n\nCopyright (c) 2024. All rights reserved. This project is licensed under the MIT license. This means you are free to use, modify, and distribute the code, as long as you include the original copyright notice and disclaimers. Please see the LICENSE file in the project root for the full license text.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmcabreradev%2Ffilter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmcabreradev%2Ffilter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmcabreradev%2Ffilter/lists"}