npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

prepared-query-options

v1.2.2

Published

JS Library for managing OData query parameter building and parsing

Downloads

11

Readme

Build Status PreparedQueryOptions

A simple set of JS classes to help build and parse OData queries

##New in 1.2.2

  • Case insensitive matching on 'and' and 'or'
  • Added Predicate.GROUP_OPERATOR.AND and .OR for convenience

##Fix in 1.2.1

  • Filter contains uses correct syntax: contains(property, value)

##Breaking Changes in 1.2.0

  • Renamed "parseOptions" and "parsePredicate" to "toString"
  • Renamed "parser" property on predicate to "getValue"

##New in 1.2.0

  • Fixed predicate test to check do a string insensitive match for startswith, endswith and contains

##New in 1.1.x

  • Get and Clear values stored in PreparedQueryOptions. Passing no value returns the current value. Passing null clears the current value.
options.$top(); // Return the current $top value
options.$top(null); // Clears the current $top value
  • Predicate.fromString(filterString): create a predicate from a filter query string.
  • Evaluate an object to see if it matches a predicates filter conditions
var testObject = { age: 25 };
var predicate = new Predicate('age').greaterThan(21);
predicate.test(testObject); // Returns true.
  • predicate.startsWith(value): parses as "startswith(property, 'value')"
  • predicate.endsWith(value): parses as "endswith(property, 'value')"
  • predicate.contains(value): parses as "contains(property, 'value')"

##Breaking Changes in 1.1.0

The predicate class has been significantly updated for better management of the predicate structure. You can now create a predicate object from a filter string in the URL. On the client side, this means you can take an existing PreparedQueryOptions object and modify/extend the filter string that is stored. On the server side, you now have the ability to take an incoming query string and parse a predicate from it making it easier to parse into SQL or into an ORM for querying the database.

Furthermore, the Predicate class now supports the OData standard startswith, endswith and contains methods. These are accessed via the startsWith(), endsWith() and contains() methods respectivly.

To accomodate these changes, there is one breaking change:

The signature of the constructor for a Predicate has changed and no longer takes the operator or value. It instead just takes the property (and a parser method that is used internally for cloning a predicate). To set the operator and value, you should now use the methods on the Predicate to set the operator and value (equals(), notEqualTo(), greaterThan()...).

new Predicate('age', 'gt', 21);

Should now be:

new Predicate('age').greaterThan(21);

##PreparedQueryOptions.js

PreparedQueryOptions are used to set, store and parse OData query parameters. Instead of passing multiple arguments to methods for each query option, simply pass the preparedQueryOptions object. Use the parseOptions method on the object to return an OData string for a query.

###Get Started

  • Include preparedQueryOptions.js in your index.html file or if using RequireJS, just require the file as a dependency.

  • Create a new preparedQueryOptions object

var options = new PreparedQueryOptions();
  • Set new options
options.$top(10);
// Parsed result looks like "?$top=10"
  • Chain any number of options
var options = new PreparedQueryOptions().$top(10).$orderBy("name asc");
options.$expand("address").$filter("age gt 16");
  • Parse the options into a query string
var options = new PreparedQueryOptions().$top(10).$orderBy("name asc");
var urlParameters = options.parseOptions();
// Parsed result looks like "?$top=10&$orderby=name asc"
  • Get and clear the current values
var options = new PreparedQueryOptions().$top(10).$orderBy("name asc");
options.$top(); // Returns 10
options.$top(null); // Clears the top value

##Predicate.js

Predicates are used to define complex filter clauses for use in an OData query string.

###Get Started

  • Include predicate.js in your index.html file or if using RequireJS, just require the file as a dependency.

  • Create a new predicate object passing the property and using chained operation methods

var predicate = new Predicate('age').greaterThan(21);
  • Join existing predicates with an 'and' separator
var pred1 = new Predicate('age').greaterThan(21);
var pred2 = new Predicate('age').lessThan(50);
pred1.join(pred2);
// Parsed result looks like "age gt 21 and age lt 50"
  • Optionally use the Predicate class to join an array of predicates
var pred1 = new Predicate('age').greaterThan(21);
var pred2 = new Predicate('age').lessThan(50);
var joinedPredicate = Predicate.join([pred1, pred2]);
  • Parse the predicate into a query string
var predicate = new Predicate('age').greaterThan(21);
var urlString = predicate.parsePredicate();
// urlString result looks like "age gt 21"