{"id":16188270,"url":"https://github.com/konsumer/wequ","last_synced_at":"2026-04-16T11:03:10.622Z","repository":{"id":48290877,"uuid":"390927990","full_name":"konsumer/wequ","owner":"konsumer","description":"A logical-operator-style array-searching utility.","archived":false,"fork":false,"pushed_at":"2022-04-26T01:54:30.000Z","size":144,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-10-11T09:56:21.982Z","etag":null,"topics":["array","cli","nodejs","query","search","utility"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","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/konsumer.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-07-30T04:20:16.000Z","updated_at":"2022-01-31T21:35:39.000Z","dependencies_parsed_at":"2022-09-16T05:12:11.390Z","dependency_job_id":null,"html_url":"https://github.com/konsumer/wequ","commit_stats":null,"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"purl":"pkg:github/konsumer/wequ","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/konsumer%2Fwequ","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/konsumer%2Fwequ/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/konsumer%2Fwequ/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/konsumer%2Fwequ/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/konsumer","download_url":"https://codeload.github.com/konsumer/wequ/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/konsumer%2Fwequ/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31882886,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-16T09:23:21.276Z","status":"ssl_error","status_checked_at":"2026-04-16T09:23:15.028Z","response_time":69,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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","cli","nodejs","query","search","utility"],"created_at":"2024-10-10T07:25:41.780Z","updated_at":"2026-04-16T11:03:10.603Z","avatar_url":"https://github.com/konsumer.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# wequ\n\n\u003cimg src=\"https://github.com/konsumer/wequ/raw/main/logo.jpg\" alt=\"now we cool bro (picture of dog with sunglasses)\" align=\"right\" /\u003e\n\n[![npm version](https://badge.fury.io/js/wequ.svg)](https://badge.fury.io/js/wequ)\n\nA logical-operator-style array-searching utility.\n\nShort for \"We Query\". Pronounced like \"we koo\".\n\n\n## features\n\n- It's stupid-fast - it turns a nice query object into a function that performs series of logical comparisons (the fastest way to match a query)\n- It's stupid-simple - I mean I think it's easier to follow than regular filter functions, especially if they are complicated\n- it's tiny - `641B` gzipped, for web-build, and under `600B` for the 2 different node-side versions (commonjs and mjs.) That is nutso. I got dog-pictures bigger than that (the one on this page is almost 100X bigger.)\n- pre-compute queries-functions for slight speedup (especially if you run it in multiple places)\n- It has a `describe` function that outputs the string of an ES6 function, so you can see how it works, more easily\n- use it in an easy-to-install CLI util (no nodejs needed) that is streaming (any length is cool in a unix-pipe!)\n- use it direclty in the browser, if you want\n- use it in nodejs\n\n\n## library\n\nThe basic usage of wequ goes like this:\n\n```js\n\n// this is a query\nconst query = {\n  published: true,\n\n  and: {\n    category: 2\n  },\n\n  nand: {\n    preview: false\n  },\n\n  or: {\n    id: [0, 1, 2, 3]\n  },\n\n  nor: {\n    title: ['Bad', 'No'],\n    stupid: true\n  }\n}\n\n// this will describe the query as an ES6 function, so you can troubleshoot or just read it in another form\nconsole.log(describe(query))\n\n// pre-compute the query-function for use in other things\nconst q = wequ(query)\n\n// honestly, this is pretty similar to describe(), but with a more laid-back ES5 chillwave type of vibe:\nconsole.log(q.toString())\n\n// get all the items that match the query\nconst subset = bigArrayOfObjects.filter(q)\n\n// get the first item that matches the query\nconst single = bigArrayOfObjects.find(q)\n\n// get an array of true/false for every record\nconst report = bigArrayOfObjects.map(q)\n\n// get a true/false if every item matches your query\nconst report = bigArrayOfObjects.every(q)\n\n// get a true/false if any of your items match your query\nconst report = bigArrayOfObjects.some(q)\n```\n\nGenerally, I find it most useful to `a.filter(q)` for \"get all matches\" and `a.find(q)` for \"get first match\"\n\nAny fields other than `and|or|nor|nand` in the top-level are merged into `and`. This allows for quick `and` queries for a few fields, which is my most common use-case.\n\nIt might take a second to get used to it, but each keyword is about the relationship the fields have to each other, like \"if it's this or that or that\" or \"if this field is this and this other field is this\". `nand` and `nor` are the same but \"not matches\" so `nor` is \"this is not this or this other thing is not this\" `nand` is \"this is not this and this other thing is not this\".\n\nUsing `describe` you will discover the function the query above generates is like this:\n\n```js\nr =\u003e (\n     ( r[\"category\"] === 2 \u0026\u0026 r[\"published\"] === true )\n  \u0026\u0026 ( r[\"id\"] === 0 || r[\"id\"] === 1 || r[\"id\"] === 2 || r[\"id\"] === 3 )\n  \u0026\u0026 ( r[\"title\"] !== \"Bad\" || r[\"title\"] !== \"No\" || r[\"stupid\"] !== true )\n  \u0026\u0026 ( r[\"preview\"] !== false )\n)\n```\n\nThis is maybe a bit harder to read \u0026 maintain.\n\n## cli\n\nI love [jq](https://stedolan.github.io/jq/), but the syntax can be a little complicated to get what you need, especially with escaping and stuff. I made the wequ CLI to address this, so I don't need to lookup syntax, I can just do what I do all over:\n\n```sh\ncat file.json | wequ '{ title: \"COOL\" }'\n```\n\nor\n\n```sh\nwequ '{ title: \"COOL\" }' \u003c file.json\n```\n\nThe syntax is regular javascript, in a string. `stdin` data should be a JSON array of objects, so you might still need [jq](https://stedolan.github.io/jq/) to turn it into that.\n\n\nIf you do want to get super-jiggy with it, but just like js syntax better than jq:\n\n```sh\nwequ '{ [ (new Date()).getMonth() + 1 ]: \"COOL\" }' \u003c file.json\n```\n\nto find an object with the current month-number as a key, set to `\"COOL\"`.\n\nor the other way:\n\n```sh\nwequ '{ month: (new Date()).getMonth() + 1 }' \u003c file.json\n```\n\nto find records with `month` set to the current month-number.\n\n\nYou can `require` any installed npm-module (in node_modules in current directory) and do whatever nutso thing you want, in there.\n\n\u003e Remember it's building a query-object, so dynamic field-names need to be in square-brackets\n\nWhile we are talking about cool javascript CLI tools for finding what you need, I recommend [flat](https://www.npmjs.com/package/flat). It's extremely useful for flattening complex objects (in a way that can be unflattened easily) and search for stuff. It pairs very nicely with wequ:\n\n```sh\ncat foo.json | flat | wequ '{ \"deep.nested.object.is.no.problem.now\": true }'\n```\n\n\n### installation\n\nInstall the CLI tool a few ways:\n\n- Grab a ready-built CLI tool from [the releases](https://github.com/konsumer/wequ/releases). No node or other dev-tools needed.\n- Install globally with `npm i -g wequ` and it will be in your path\n- Use npx for 0-install: `npx wequ`\n\n## library\n\nYou can get the `wequ` and `describe` functions, from above, in a few ways, depending on how you are doing things.\n\n### browser script tag\n\nKick it oldschool, for a quick demo:\n\n```html\n\u003cscript src=\"https://unpkg.com/wequ\"\u003e\u003c/script\u003e\n```\n\nThis adds `window.wequ`, which has `wequ()` and `describe()` in it.\n\n### browser modules\n\nYou can use es6 modules in modern browsers.\n\n```html\n\u003cscript type=\"module\"\u003e\nimport { wequ, describe } from 'https://unpkg.com/wequ@latest/dist/wequ.module.js'\n\u003c/script\u003e\n```\n\nOr with [sick new import-maps](https://github.com/WICG/import-maps):\n\n```html\n\u003cscript type=\"importmap\"\u003e\n{\n  \"imports\": {\n    \"wequ\": \"https://unpkg.com/wequ@latest/dist/wequ.module.js\"\n  }\n}\n\u003c/script\u003e\n\u003cscript type=\"module\"\u003e\nimport { wequ, describe } from 'wequ'\n\u003c/script\u003e\n```\n\nThese are pretty new features, but if you want them in your old-browser-supporting-projects try [a polyfill](https://github.com/guybedford/es-module-shims). It doesn't add too much overhead, and the syntax is the wave of the future. \n\n### node\n\nInstall it in your project:\n\n```sh\nnpm i wequ\n```\n\nIt works with older commonjs style:\n\n```js\nconst { wequ, describe } = require('wequ')\n```\n\nor ES6 module (`type: module` or some sort of builder):\n\n```js\nimport { wequ, describe } from 'wequ'\n```\n\n### deno\n\n```js\nimport { wequ, describe } from 'https://unpkg.com/wequ@latest/dist/wequ.module.js'\n```\n\n\n## development\n\nThis is mostly just notes for myself.\n\nTo release, just tag with a version and push, and [CI](https://github.com/konsumer/wequ/blob/main/.github/workflows/publish.yml) will do the rest.\n\n```sh\nnpm version patch \u0026\u0026 git push --mirror\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkonsumer%2Fwequ","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkonsumer%2Fwequ","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkonsumer%2Fwequ/lists"}