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 🙏

© 2026 – Pkg Stats / Ryan Hefner

object-expression

v0.1.1

Published

Object Expression matching

Readme

ObjExp

Matches objects using object expressions.

Installation

npm install object-expression

Usage

The example bellow shows how to filter an array of objects using ObjExp.

var ObjExp = require('../');

var people = [
    {
        'name': 'Malcolm Reynolds', 'birth_year': 2468, 'aim': 'misbehave',
        'accessories': [{'name': 'floral bonnet', 'description': 'pretty'}],
    },
    {
        'name': 'Zoë Alleyne Washburne', 'birth_year': 2484,
        'occupation': 'smuggler'
    },
    {
        'name': 'Inara Serra',
        'occupation': 'companion'
    },
    {
        'name': 'Kaywinnet Lee Frye',
        'occupation': 'mechanic'
    },
    {
        'name': 'Hoban Washburne',
        'accessories': [{'name': 'allosaurus', 'description': 'evil laugh'}],
        'occupation': 'pilot'
    },
    {
        'name': 'Jayne Cobb',
        'accessories': [{'name': 'earflap hat', 'description': 'cunning'}, {'name': 'vera', 'description': 'very favorite gun'}],
        'occupation': 'public relations'
    },
    {
        'name': 'Derrial Book',
        'accessories': [{'name': 'book', 'description': 'broken'}],
        'occupation': 'Shepherd'
    },
    {
        'name': 'River Tam'
    },
    {
        'name': 'Simon Tam',
        'occupation': 'surgeon'
    }
];

var pattern = new ObjExp({ 'name': { '$regex': /mal.*/i }, 'birth_year': { '$gt': 2450, '$lt': 2475 } });
pattern.and({ 'aim': 'misbehave' });
pattern.or({ 'accessories': { '$any': { '$or': [{ 'name': 'floral bonnet' }, { 'name': 'earflap hat' }] } } });
pattern.or({ 'occupation': { '$in': ['companion', 'mechanic'] } });
pattern.and(ObjExp.not({ 'occupation': { '$in': ['reavers', 'public relations'] } }));

var matches = people.filter(pattern.test);
console.log(matches);

/*
output:

[ { name: 'Malcolm Reynolds',
    birth_year: 2468,
    aim: 'misbehave',
    accessories: [ [Object] ] },
  { name: 'Inara Serra', occupation: 'companion' },
  { name: 'Kaywinnet Lee Frye', occupation: 'mechanic' } ]

 */

API

new ObjExp([expression])

This creates and retuns a new ObjExp.

Static Methods

ObjExp.and(expressions)

Returns an expression that would be true if and only if all passed expressions are true.

ObjExp.or(expressions)

Returns an expression that would be true if at least one of the passed expressions is true.

ObjExp.not(expression)

Returns an expression that would be true if the passed expression is false.

ObjExp.test(value, operator, expression)

Tests if the value matches the expression using the operator.

Operators

$and(value, expressions)

Returns true if the value matches all expressions.

$or(value, expressions)

Returns true if the value matches at least one expression.

$not(value, expression)

Returns true if the value does not match the expression.

$eq(value, expression)

Returns true if the value is equal to the expression.

$gt(value, expression)

Returns true if the value is greater than the expression.

$gte(value, expression)

Returns true if the value is greater than or equal to the expression.

$lt(value, expression)

Returns true if the value is lesser than the expression.

$lte(value, expression)

Returns true if the value is lesser than or equal to the expression.

$in(value, array)

Returns true if the value is in the array.

$exists(value, expression)

Returns true if the value existance is reflected by the expression.

$regex(value, regex)

Returns true if the value matches the regular expression.

$all(value, expression)

Returns true if the value is an array with all elements matching the expression.

$any(value, expression)

Returns true if the value is an array with at least one element matching the expression.

$size(value, expression)

Returns true if the value is an array with length matching the expression.

Prototype Methods

ObjExp#and(expressions)

Modifies the ObjExp, matching if the current expression and all passed expressions is true.

ObjExp#or(expressions)

Modifies the ObjExp, matching if the current expression or at least one of the passed expressions is true.

ObjExp#test(value)

Tests if the value matches the expression using the operator.

TODO

  • Tests
  • Optimizations