{"id":25115437,"url":"https://github.com/orbitturner/array-querier","last_synced_at":"2025-04-22T14:21:58.474Z","repository":{"id":57184121,"uuid":"354047195","full_name":"orbitturner/array-querier","owner":"orbitturner","description":"A TS/JS NPM Package to Filter an array of objects with multiple match-criteria.","archived":false,"fork":false,"pushed_at":"2021-04-05T15:16:45.000Z","size":141,"stargazers_count":14,"open_issues_count":0,"forks_count":3,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-13T00:20:02.882Z","etag":null,"topics":["array-helper","filter","json-array","query-array","ts-js"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/array-querier","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/orbitturner.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-04-02T14:44:13.000Z","updated_at":"2025-01-01T07:13:05.000Z","dependencies_parsed_at":"2022-08-23T01:20:43.050Z","dependency_job_id":null,"html_url":"https://github.com/orbitturner/array-querier","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/orbitturner%2Farray-querier","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/orbitturner%2Farray-querier/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/orbitturner%2Farray-querier/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/orbitturner%2Farray-querier/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/orbitturner","download_url":"https://codeload.github.com/orbitturner/array-querier/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250255776,"owners_count":21400411,"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-helper","filter","json-array","query-array","ts-js"],"created_at":"2025-02-08T02:28:43.402Z","updated_at":"2025-04-22T14:21:58.451Z","avatar_url":"https://github.com/orbitturner.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"﻿# 🟢 Array Querier 🔎\n[![Compatible Status](https://img.shields.io/badge/works%20with-ts/js-blue)](https://www.npmjs.com/package/array-querier)\n[![Code Size Status](https://img.shields.io/github/languages/code-size/orbitturner/array-querier)](https://www.npmjs.com/package/array-querier)\n[![Commit Status](https://img.shields.io/github/commit-activity/m/orbitturner/array-querier?color=red)](https://www.npmjs.com/package/array-querier)\n[![Issues Status](https://img.shields.io/github/issues/orbitturner/array-querier)](https://www.npmjs.com/package/array-querier)\n[![npm version](https://img.shields.io/npm/v/array-querier.svg)](https://www.npmjs.com/package/array-querier) [![license](https://img.shields.io/npm/l/array-querier.svg)](https://www.npmjs.com/package/array-querier)\n\n**Array-Querier** is a TS/JS [NPM](http://npmjs.com/) Package to Filter an Array of objects with multiple match-criteria.\n\n\u003cp align=\"center\"\u003e\n  \u003ca href=\"http://orbitturner.com/\"\u003e\u003cimg src=\"https://raw.githubusercontent.com/orbitturner/ORBIT_SUGAR_CODES/master/assets/arrayQuerier.png\" width=\"auto\" alt=\"array-querier COVER\"/\u003e\u003c/a\u003e\n\u003c/p\u003e\n\n\n\u003ch1 align=\"center\"\u003eINSTALLATION\u003c/h1\u003e\n\u003cp align=\"center\"\u003e\n\u003ca href=\"https://www.npmjs.com/package/array-querier\"\u003e\u003cimg src=\"https://img.shields.io/badge/DOWNLOAD-LATEST%20VERSION-lime?style=for-the-badge\u0026logo=docusign\u0026logoColor=lime\"\u003e\u003c/a\u003e\n\u003ca href=\"https://github.com/orbitturner/array-querier/issues/new/choose\"\u003e\u003cimg src=\"https://img.shields.io/badge/ISSUES-CREATE%20AN%20ISSUE-crimson?style=for-the-badge\u0026logo=indeed\u0026logoColor=CRIMSON\"\u003e\u003c/a\u003e\n\u003c/p\u003e\n\u003cbr/\u003e\n\n___\n## 📚 Table Of Contents 📑\n- [🟢 Array Querier 🔎](#---array-querier---)\n  * [📚 Table Of Contents 📑](#---table-of-contents---)\n  * [💨 What is this Library for? 🤔](#---what-is-this-library-for----)\n  * [✨ Key Features 🎯](#--key-features---)\n  * [📥 Installation 🔰](#---installation---)\n  * [🤔 One-Level vs Multi-Level Depth JSON ? 🤔](#---one-level-vs-multi-level-depth-json-----)\n  * [⚙ Usage: One-Level Depth Arrays (Simple Arrays) 🎚](#--usage--one-level-depth-arrays--simple-arrays----)\n    + [➤ Querier.filterSimpleArray(yourData, filterObject); 🟢](#--querierfiltersimplearray-yourdata--filterobject-----)\n  * [⚙ Usage: Multi-Level Depth Arrays (Complex Arrays) 🎛](#--usage--multi-level-depth-arrays--complex-arrays----)\n    + [➤ Querier.filterComplexArray(yourData, filterObject); 🟢](#--querierfiltercomplexarray-yourdata--filterobject-----)\n  * [Configuration Options](#configuration-options)\n  * [Contributing ❤](#contributing--)\n  * [Issue Reporting](#issue-reporting)\n  * [GREETINGS](#greetings)\n  * [Author](#author)\n  * [License](#license)\n\n___\n\n## 💨 What is this Library for? 🤔\n\n**array-querier** is a small library that is useful for filtering a `One Level or Multi Level Depth` array of objects with `multiple match-criteria`. The exposed methods **receives** an **array as the first argument**, and **a plain object describing the fields to filter as the last argument**.\n\n\n\u003e **Note:** This library can only be used with typescript or js but you already know that 🤦🏿‍♂️.\n\n\n\n## ✨ Key Features 🎯\n\n* Use it **without `Instanciation`**  because all the methods are `Static`.\n* **Multi Level Depth Filtering** with complex filtering condition.\n* Optimized for Great Performance even with **Big Fat @/@ Arrays** of Objects.\n* ✅ TOO EASY TO USE !! 🥳🥳\n\n___\n\n## 📥 Installation 🔰\n\n```bash\n# installation with npm\nnpm install array-querier\n\n# or you may prefer\nnpm i --save array-querier\n\n# installation with yarn\nyarn add array-querier\n```\n\n**This HELPER relies on NOTHING SO YOU DON'T NEED ADDITIONNAL PACKAGES.**\n\n___\n## 🤔 One-Level vs Multi-Level Depth JSON ? 🤔\n\nA JSON depth level is just an nesting of another object within a current JSON object.\nFor example :\nIf you have a User object as follows -\u003e\n```json\n// Nested Object Planet in User\nUser = {\n    \"name\": \"Orbit\",\n    \"age\": 21,\n    \"planet\": {\n        \"id\": 4,\n        \"codename\" : \"Shadow-Coders\",\n        \"galaxyName\" : \"Turner\"\n    }   \n}\n```\n**Then User is an Array of two level Depth.**\n\nOf course if you don't have any nested object then you got an One level Depth.\n___\n\n\n\n## ⚙ Usage: One-Level Depth Arrays (Simple Arrays) 🎚\n\n### ➤ Querier.filterSimpleArray(yourData, filterObject); 🟢\n\nIf you are only interested in filtering an simple array of **JSON objects** directly:\n\n```ts\nimport {Querier} from 'array-querier/lib/orbiter';\n\n/**\n * Your array of JSON Objects.\n * This can be pulled directly from your Backend Rest API.\n */\nconst products = [\n  { name: 'A', color: 'Blue', size: 50 },\n  { name: 'B', color: 'Blue', size: 60 },\n  { name: 'C', color: 'Black', size: 70 },\n  { name: 'D', color: 'Green', size: 50 },\n];\n\n// ⚠ You need a Filter Object to make your condition ⚠\nconst filters = {\n  color: ['BLUE', 'black'],\n  size: [70, 50],\n};\n\n/**\n * Calling Simple Array Filterer In Query.\n * Filters an array of objects (one level-depth) with multiple criteria.\n * The function returns an array of the same type as the input array.\n */\nconst MyFilteredResult = Querier.filterSimpleArray(products, filters);\n\nconsole.table(MyFilteredResult);\n/* 🟢 The Result Will Be :🟢\n      { name: 'A', color: 'Blue', size: 50 },\n      { name: 'C', color: 'Black', size: 70 },\n */\n```\n\u003e **⚠ Note: ⚠** The `filterSimpleArray` method **IS NOT** **Case-Sensitive** 🚨.\n\n___\n## ⚙ Usage: Multi-Level Depth Arrays (Complex Arrays) 🎛\n\n### ➤ Querier.filterComplexArray(yourData, filterObject); 🟢\n\nIn everyday life, as developers, our JSON arrays are often very complex because of foreign keys and / or the nesting of objects that allow us to better describe our entities.\n\nIn this case this Method is the most appropriate because it allows to apply very advanced filters to our Array regardless of the depth level. \n\n```ts\nimport {Querier} from 'array-querier/lib/orbiter';\n\n/**\n * Your Complex array of JSON Objects.\n * This can be pulled directly from your Backend Rest API.\n */\nconst products = [\n  { name: 'Orbit', color: 'Blue', size: 50, locations: ['USA', 'Europe'], details: { length: 20, width: 70 } },\n  { name: 'Galsen', color: 'Blue', size: 60, locations: [], details: { length: 20, width: 70 } },\n  { name: 'DaoudaBa', color: 'Black', size: 70, locations: ['Japan'], details: { length: 20, width: 71 } },\n  { name: 'Mmnl', color: 'Green', size: 50, locations: ['USA'], details: { length: 20, width: 71 } },\n];\n\n// ⚠ Filter Object with complex conditions ⚠\nconst filters = {\n  size: (size: number) =\u003e size === 50 || size === 70,\n  color: (color: string) =\u003e ['blue', 'black'].includes(color.toLowerCase()),\n  locations: (locations: any[]) =\u003e locations.find(x =\u003e ['JAPAN', 'USA'].includes(x.toUpperCase())),\n  details: (details: { length: number; width: number; }) =\u003e details.length \u003c 30 \u0026\u0026 details.width \u003e= 70,\n};\n\n/**\n * Calling Simple Array Filterer In Query.\n * Filters an array of objects (one level-depth) with multiple criteria.\n * The function returns an array of the same type as the input array.\n */\nconst MyFilteredResult = Querier.filterComplexArray(products, filters);\n\nconsole.table(MyFilteredResult);\n/* 🟢 The Result Will Be :🟢\n      { name: 'A', color: 'Blue', size: 50, locations: ['USA', 'Europe'], details: { length: 20, width: 70 } },\n      { name: 'C', color: 'Black', size: 70, locations: ['Japan'], details: { length: 20, width: 71 } },\n */\n```\n\n**The Filter can be more complex and advance like the following use case case :**\n\n```ts\n...\n\n// ⚠ Filter Object with VERY Complex Conditions 🏃🏾‍♂️🏃🏾‍♂️⚠\nconst filters = {\n  size: (size: number) =\u003e size === 50 || size === 70,\n  color: (color: string) =\u003e ['blue', 'black'].includes(color.toLowerCase()),\n  details: (details: { length: number; width: number; }) =\u003e details.length \u003c 30 \u0026\u0026 details.width \u003e= 70,\n  locations: (locations: string | string[]) =\u003e {\n    if (locations.includes('USA')) { return true; } // case sensitive\n    if (locations.includes('Japan')) { return true; } // case sensitive\n\n    const url = window.location.pathname.toLowerCase();\n    if (url.includes('/en-us/')) { return true; } // not case sensitive\n    if (url.includes('/es/')) { return true; } // not case sensitive\n    return false;\n  }\n};\n\nconst MyFilteredResult = Querier.filterComplexArray(products, filters);\n```\n\n\u003cbr/\u003e\n✨🤗 AS I SAID BEFORE : EASYYY 🤗✨\n\n___\n## Configuration Options\n\n*Coming Soon !*\n___\n## Contributing ❤\n\n👋🏾 Pull requests are welcome! \n___\n\n## Issue Reporting\n\nIf you have found a bug or if you have a feature request, please report them at this repository issues section. Please do not report security vulnerabilities on the public GitHub issue tracker. The [Responsible Disclosure Program](mailto:support@orbitturner.com) details the procedure for disclosing security issues.\n___\n\n## GREETINGS\n❤❤ *Coming Soon !* ❤❤\n\n___\n## Author\n\n[Orbit Turner](https://orbitturner.com)\n\n___\n## License\n\nThis project is licensed under the MIT license. See the [LICENSE](LICENSE) file for more info.\n______________________________________________________\n**❤ MADE WITH LOVE ❤**\n\n![Image of OT](https://raw.githubusercontent.com/orbitturner/orbitturner/master/LOGO-OT.png)\n\n\u003cimg src=\"https://github.com/orbitturner/challenger/blob/master/images/OrbitTurner_Gaming_GitHubBadge.png?raw=true\" align=\"right\" /\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Forbitturner%2Farray-querier","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Forbitturner%2Farray-querier","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Forbitturner%2Farray-querier/lists"}