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

oregex

v1.0.2

Published

Regular Expression Grammar for Objects instead of Strings

Downloads

4

Readme

ORegEx.js

Regular Expressions for Objects

ORegEx is a JavaScript (Web and/or Node) module that allows for the use of a RegEx-like grammar on Objects, rather than Strings. Not only is ORegEx's grammar robust and powerful, it's also highly extensible, so that you can define your own helper functions, or even customize the way the parser handles things like: * Type Checking * Property Access * Property Value Testing etc. ORegEx does not care about whitespace, so you can have selector strings that span only one line, or hundreds, and they'll evaluate the same way.

ORegEx Selector Filters

  • * : Wild Card. Will match anything.
  • #$id : Checks if the given object's 'id' property (if one exists) matches $id
  • .$class : Checks if the given object is an instance of the class referred to by $class
  • ..$class : Checks if the given object is an instance of the class referred to by $class, or an instance of any subclass of $class
  • :$name : If a helper function is registered under $name, then invokes the helper function on the given object, otherwise, checks if the property of the given object referred to by $name is truthy
  • [$name] : Checks for the existence of $name as a property of the given object
  • [$name = $value] : Checks if the property $name of the given object is equal to $value
  • [$name != $value] : Checks that the $name property of the given object is not equal to $value
  • [$name .= $type] : Checks that the $name property of the given object is of type $type
  • [$name => $sel] : Checks that the property $name1 of the given object is matched by the nested filter $sel`
  • ($filter) : An encapsulated filter group
  • $filterOne | $filterTwo : Checks that the given object is matched by either $filterOne or $filterTwo
  • $filterOne & $filterTwo : Checks that the given object is matched by both $filterOne and $filterTwo
  • $condition ? $ifTrue : $ifNot : Ternary conditional filter. If the given object is matched by the $condition filter, then check that it is also matched by the $ifTrue filter, otherwise, ensure that it is matched by the $ifNot filter
  • /* $comment.. */ : ORegEx Comment

ORegEx API

ORegEx Object Methods

As of right now, the only useful method of the ORegEx Object is test, which accepts an object as its only argument, and returns whether that object was matched by this ORegEx.

Examples

Here's a simple example of ORegEx at work in NodeJS.

var oregex = require("oregex");

var obj = {
	"name" : "Ryan Davis",
	"age" : 18,
	"hobbies" : ["programming", "gaming", "..programming"],
	"exhausted" : true
};
var selector1 = oregex.compile("[name .= 'String'] [name = 'Ryan Davis'] [age .= Int] [age = 18] [hobbies .= 'Array'] :exhausted");
var selector2 = oregex.compile("[name .= 'String'] [name != 'Ryan Davis'] [age .= Int] [age != 18] [hobbies .= 'Array'] :exhausted");

selector1.test( obj ); //=> 'true'
selector2.test( obj ); //=> 'false'

You can also find several much more extensive examples in the 'examples' folder.