### Installation Source: https://github.com/3axap4ehko/ajoq/blob/master/README.md Installs the AJOQ library using npm. ```bash npm install ajoq ``` -------------------------------- ### Run Benchmarks Source: https://github.com/3axap4ehko/ajoq/blob/master/README.md Installs benchmarking dependencies and runs the benchmark suite for AJOQ against other libraries like Sift and Mingo. ```bash # Install dependencies npm install --save-dev sift mingo overtake # Run benchmark npx overtake benchmark.ts ``` -------------------------------- ### Complex Product Search with ajoq Source: https://github.com/3axap4ehko/ajoq/blob/master/README.md Demonstrates how to create a complex filter for e-commerce product searches using ajoq. This example combines multiple conditions including price range, category inclusion, brand or rating, and tag containment. ```ts // E-commerce product filtering const productFilter = createFilter({ $and: [ { price: { $gte: 50, $lte: 200 } }, { category: { $in: ['electronics', 'computers'] } }, { $or: [ { brand: 'Apple' }, { rating: { $gte: 4.5 } } ] }, { tags: { $con: 'wireless' } } ] }); const products = await fetch('/api/products').then(r => r.json()); const filtered = products.filter(productFilter); ``` -------------------------------- ### User Permission Check with ajoq Source: https://github.com/3axap4ehko/ajoq/blob/master/README.md Illustrates creating a filter for user permission checks. This example uses logical operators ($or, $and) and array/comparison operators ($sup, $ne) to define complex access rules based on roles, permissions, and user status. ```ts // Check complex permission rules const canEdit = createFilter({ $or: [ { role: 'admin' }, { $and: [ { role: 'editor' }, { permissions: { $sup: ['read', 'write'] } }, { suspended: { $ne: true } } ] } ] }); if (canEdit(currentUser)) { // Allow editing } ``` -------------------------------- ### ajoq Array Operators: $in, $con, $sub, $sup Source: https://github.com/3axap4ehko/ajoq/blob/master/README.md Provides examples of using ajoq's array operators to filter data based on array contents. Demonstrates `$in` for checking if a value exists in an array, `$con` for checking if an array contains a specific value, `$sub` for subset checks, and `$sup` for superset checks. ```ts import { createFilter } from "ajoq"; // $in - check if value is in array const roleFilter = createFilter({ role: { $in: ['admin', 'moderator'] } }); roleFilter({ role: 'admin' }); // true roleFilter({ role: 'user' }); // false // $con - check if array contains value const tagFilter = createFilter({ tags: { $con: 'javascript' } }); tagFilter({ tags: ['javascript', 'node'] }); // true tagFilter({ tags: ['python', 'django'] }); // false // $sub - check if array is subset const subsetFilter = createFilter({ skills: { $sub: ['js', 'html', 'css'] } }); subsetFilter({ skills: ['js', 'html'] }); // true (subset of allowed) subsetFilter({ skills: ['js', 'php'] }); // false (php not in allowed) // $sup - check if array is superset const supersetFilter = createFilter({ permissions: { $sup: ['read', 'write'] } }); supersetFilter({ permissions: ['read', 'write', 'delete'] }); // true supersetFilter({ permissions: ['read'] }); // false ``` -------------------------------- ### AJOQ Filter API - Logical Operators Source: https://github.com/3axap4ehko/ajoq/blob/master/README.md Details the logical operators supported by AJOQ's filter API, mirroring MongoDB's query syntax for advanced filtering. ```APIDOC Filter API Filters support all MongoDB query operators for maximum compatibility. Logical Operators - $and: Matches if all sub-conditions are true (logical AND). - $or: Matches if at least one sub-condition is true (logical OR). - $nor: Matches if none of the sub-conditions are true (logical NOR). - $not: Matches if the sub-condition is false (logical NOT). ``` -------------------------------- ### ajoq Filter Operators Source: https://github.com/3axap4ehko/ajoq/blob/master/README.md Defines a comprehensive set of filter operators for data querying and manipulation. These include equality, inequality, comparison, existence, string matching, bitwise operations, type checking, and various array-related operations like inclusion, subset, superset, and containment. ```APIDOC Filter Operators: $eq: Matches if the field equals the value. $ne: Matches if the field does not equal the value. $gt: Matches if the field is greater than the value. $gte: Matches if the field is greater than or equal to the value. $lt: Matches if the field is less than the value. $lte: Matches if the field is less than or equal to the value. $exists: Matches if the field exists or does not exist (true or false). $match: Matches if the field value matches a regex or string. $nmatch: Matches if the field value does not match a regex or string. $incl: Matches if the string field includes the specified substring. $nincl: Matches if the string field does not include the specified substring. $bits: Matches if any bits from the field value match the specified bitmask. $nbits: Matches if no bits from the field value match the specified bitmask. $type: Matches if the field's type matches the specified type. $ntype: Matches if the field's type does not match the specified type. $in: Matches if the field value is in the specified array. $nin: Matches if the field value is not in the specified array. $sub: Matches if all elements of the field array are in the specified array (subset). $nsub: Matches if the field array is not a subset of the specified array. $sup: Matches if the field array contains all elements of the specified array (superset). $nsup: Matches if the field array does not contain all elements of the specified array. $con: Matches if the field array contains the specified value. $ncon: Matches if the field array does not contain the specified value. ``` -------------------------------- ### Create Filter Function Source: https://github.com/3axap4ehko/ajoq/blob/master/README.md Generates a JavaScript function to filter an array of objects based on MongoDB-style query criteria. Supports logical operators like $and, $or, $nor, and $not. ```ts import { createFilter } from "ajoq"; interface Data { name: string; age: number; // data type } const values: Data[] = [{ name: 'John', age: 42 }, { name: 'Jane', age: 18 }]; const filterFn = createFilter({ name: 'John', age: { $gte: 21 } }); const filtered = values.filter(filterFn); // [{ name: 'John', age: 42 }] ``` ```ts // Complex user search with MongoDB-style queries const users = [ { name: 'Alice', age: 28, skills: ['js', 'react'], active: true }, { name: 'Bob', age: 32, skills: ['python'], active: false }, { name: 'Charlie', age: 25, skills: ['js', 'vue'], active: true } ]; // Find active users who know JavaScript and are under 30 const filter = createFilter({ active: true, age: { $lt: 30 }, skills: { $con: 'js' } }); const results = users.filter(filter); // → [{ name: 'Alice', ... }, { name: 'Charlie', ... }] ``` -------------------------------- ### Create Sort Function Source: https://github.com/3axap4ehko/ajoq/blob/master/README.md Generates a JavaScript function for sorting arrays of objects based on specified fields and order (ascending or descending). ```ts import { createSort } from "ajoq"; interface Data { name: string; age: number; // data type } const values: Data[] = [{ name: 'John', age: 42 }, { name: 'Jane', age: 18 }]; const sortFn = createSort({ name: 'asc', age: -1 }); const sorted = values.toSorted(sortFn); // [{ name: 'Jane', age: 18 }, { name: 'John', age: 42 }] ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.