
Security News
/Research
Wallet-Draining npm Package Impersonates Nodemailer to Hijack Crypto Transactions
Malicious npm package impersonates Nodemailer and drains wallets by hijacking crypto transactions across multiple blockchains.
odata-search-builder
Advanced tools
A lightweight and flexible TypeScript library for building OData filter queries.
A lightweight and flexible TypeScript library for building and parsing OData filter queries. This library provides both a fluent API for constructing OData filter expressions and a powerful parser for converting existing OData filter strings into SearchBuilder instances that can be further modified or executed.
npm install odata-search-builder
# or
yarn add odata-search-builder
# or
bun add odata-search-builder
import { SearchBuilder } from 'odata-search-builder';
// Create a new instance
const searchBuilder = new SearchBuilder();
// Build a simple query
const filter = searchBuilder
.eq('name', 'Miguel')
.and()
.gt('age', 18)
.build();
console.log(filter); // name eq 'Miguel' and age gt 18
// Build a more complex query with grouping
const complexFilter = new SearchBuilder()
.openGroup()
.eq('firstName', 'Debora')
.or()
.eq('firstName', 'Miguel')
.closeGroup()
.and()
.openGroup()
.ge('age', 30)
.and()
.le('age', 18)
.closeGroup()
.build();
console.log(complexFilter); // (firstName eq 'Debora' or firstName eq 'Miguel') and (age ge 30 and age le 18)
// Using the any operator for collections
const anyQuery = new SearchBuilder()
.any('tags', { operator: 'eq', value: 'important' })
.build();
console.log(anyQuery); // (tags/any(x:(x eq 'important'))
You can also parse existing OData filter strings into SearchBuilder instances:
import { SearchParser } from 'odata-search-builder';
// Parse a simple filter
const searchBuilder = SearchParser.parse("name eq 'John' and age gt 30");
console.log(searchBuilder.build()); // name eq 'John' and age gt 30
// Parse and then modify a filter
const parsedBuilder = SearchParser.parse("name eq 'John'");
parsedBuilder.and().contains('department', 'Sales');
console.log(parsedBuilder.build()); // name eq 'John' and contains(department, 'Sales')
// Parse a complex filter with grouping
const complexBuilder = SearchParser.parse("(firstName eq 'John' or firstName eq 'Jane') and age ge 25");
// Add more conditions to the parsed builder
complexBuilder.and().in('status', ['Active', 'Pending']);
console.log(complexBuilder.build());
// (firstName eq 'John' or firstName eq 'Jane') and age ge 25 and status in ('Active','Pending')
build()
: Builds and returns the OData filter query string.clone()
: Creates a copy of the current SearchBuilder instance.and()
: Adds the 'and' operator to the query.or()
: Adds the 'or' operator to the query.not()
: Adds the 'not' operator to the query.openGroup()
: Adds an opening parenthesis to the query.closeGroup()
: Adds a closing parenthesis to the query.eq(field: string, value: Value)
: Equality operator (==).ne(field: string, value: Value)
: Inequality operator (!=).gt(field: string, value: Value)
: Greater than operator (>).lt(field: string, value: Value)
: Less than operator (<).ge(field: string, value: Value)
: Greater than or equal operator (>=).le(field: string, value: Value)
: Less than or equal operator (<=).in(field: string, values: Value[])
: Checks if the field value is in the provided array.contains(field: string, value: Value)
: Checks if the field contains the specified value.startswith(field: string, value: Value)
: Checks if the field starts with the specified value.endswith(field: string, value: Value)
: Checks if the field ends with the specified value.any(field: string, options: { operator: Operators; value: Value })
: Applies the specified operator to any element in a collection.All comparison operators and string functions are also available as static methods:
SearchBuilder.eq('name', 'Miguel'); // Returns: "name eq 'Miguel'"
The SearchParser
class provides powerful functionality to parse OData filter expressions into SearchBuilder instances, allowing you to convert existing OData filter strings into modifiable SearchBuilder objects. This is particularly useful when working with existing OData systems or when you need to parse user-provided filter strings.
// Parse a simple filter
const searchBuilder = SearchParser.parse("name eq 'John' and age gt 30");
console.log(searchBuilder.build()); // name eq 'John' and age gt 30
// Parse a complex filter with grouping and logical operators
const complexBuilder = SearchParser.parse("(firstName eq 'John' or firstName eq 'Jane') and not (age lt 25)");
console.log(complexBuilder.build()); // (firstName eq 'John' or firstName eq 'Jane') and not (age lt 25)
See LICENSE.md for details.
FAQs
A lightweight and flexible TypeScript library for building OData filter queries.
We found that odata-search-builder demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
/Research
Malicious npm package impersonates Nodemailer and drains wallets by hijacking crypto transactions across multiple blockchains.
Security News
This episode explores the hard problem of reachability analysis, from static analysis limits to handling dynamic languages and massive dependency trees.
Security News
/Research
Malicious Nx npm versions stole secrets and wallet info using AI CLI tools; Socket’s AI scanner detected the supply chain attack and flagged the malware.