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

@rsql/ast

v1.6.0

Published

RSQL AST definitions and functions

Downloads

41,263

Readme

@rsql/ast

Abstract Syntax Tree definitions and functions for RSQL

npm lerna code style: prettier commitizen friendly tested with jest auto release

Installation

# with npm
npm install --save @rsql/ast

# with yarn
yarn add @rsql/ast

API

create<Node>(...args): Node

function createSelectorNode(selector): SelectorNode;
function createValueNode(value): ValueNode;
function createComparisonNode(selector, operator, value): ComparisonNode;
function createLogicNode(left, operator, right): LogicNode;

Creates new Node, can throw InvalidArgumentError for invalid arguments

is<Node>(candidate): boolean

function isNode(candidate): boolean;
function isSelectorNode(candidate): boolean;
function isValueNode(candidate): boolean;
function isComparisonNode(candidate, operator?): boolean;
function isLogicNode(candidate, operator?): boolean;
function isExpressionNode(candidate): boolean;

Checks if candidate is an instance of Node (actually it doesn't use instanceof operator as Nodes are simple objects - not instances of a class). Additionally we can pass operator argument to the isComparisonNode and isLogicNode to check if node uses given operator. It automatically maps operators to canonical versions so for example isComparisonNode(node, '=le=') is same as isComparisonNode(node, '<=').

getSelector(comparison): string

Returns selector for a given ComparisonNode. Can throw InvalidArgumentError if passed argument is not a ComparisonNode.

getValue(comparison): string | string[]

Returns value for a given ComparisonNode. Can throw InvalidArgumentError if passed argument is not a ComparisonNode.

getSingleValue(comparison): string

Returns single value for a given ComparisonNode. Can throw InvalidArgumentError if passed argument is not a ComparisonNode or contains array instead of string.

getMultiValue(comparison): string[]

Returns multi value for a given ComparisonNode. Can throw InvalidArgumentError if passed argument is not a ComparisonNode or contains string instead of array.

ComparisonOperator

const EQ = "==";
const NEQ = "!=";
const LE = "<=";
const GE = ">=";
const LT = "<";
const GT = ">";
const IN = "=in=";
const OUT = "=out=";
const LE_VERBOSE = "=le=";
const GE_VERBOSE = "=ge=";
const LT_VERBOSE = "=lt=";
const GT_VERBOSE = "=gt=";

const CanonicalComparisonOperators = [EQ, NEQ, LE, GE, LT, GT, IN, OUT];
const VerboseComparisonOperators = [LE_VERBOSE, GE_VERBOSE, LT_VERBOSE, GT_VERBOSE];
const ComparisonOperators = [...CanonicalComparisonOperators, ...VerboseComparisonOperators];

function isComparisonOperator(candidate, operator?): boolean;

Defines built-in comparison operators and isComparisonOperator function which checks if given candidate is a valid ComparisonOperator. Additionally you can pass operator argument which checks if given candidate equals operator from a semantic perspective - so for example isComparisonOperator(candidate, LE) will give you the same result as isComparisonOperator(candidate, LE_VERBOSE)

LogicOperator

const AND = ";";
const OR = ",";
const AND_VERBOSE = "and";
const OR_VERBOSE = "or";

const CanonicalLogicOperators = [AND, OR];
const VerboseLogicOperators = [AND_VERBOSE, OR_VERBOSE];
const LogicOperators = [...CanonicalLogicOperators, ...VerboseLogicOperators];

function isLogicOperator(candidate, operator?): boolean;

Defines logic operators and isLogicOperator function which checks if given candidate is a valid LogicOperator. Additionally you can pass operator argument which checks if given candidate equals operator from a semantic perspective - so for example isLogicOperator(candidate, AND) will give you the same result as isLogicOperator(candidate, AND_VERBOSE)

ReservedChars

const ReservedChars = ['"', "'", "(", ")", ";", ",", "=", "!", "~", "<", ">", " ", "\n", "\t", "\r"];

Defines list of chars that are reserved in the RSQL. Used internally to validate selectors, parse RSQL, and escape values.

Types

Node

It's a base type for all node types. Defines an object which contains type property which defines type of the node (instead of basing on the instanceof operator).

SelectorNode

Node which represents selector. Defines an object which, besides Node properties, contains a selector property which stores selector.

ValueNode

Node which represents value. Defines an object which, besides Node properties, contains a value property which stores value.

BinaryNode

It's a base type for nodes which consists of two operands and one operator. Defines an object which, besides Node properties, contains left and right property which stores operands and operator property which stores an operator.

ComparisonNode

Node which represents comparison expression. It's a constrained version of the BinaryNode where left has to be SelectorNode, right has to be a ValueNode and operator has to be a ComparisonOperator.

LogicNode

Node which represents logic expression. It's a constrained version of the BinaryNode where left and right has to be an ExpressionNode and operator has to be a LogicOperator.

ExpressionNode

It's a type union between ComparisonNode and LogicNode.

ComparisonOperator

It's a string literal type which defines built-in comparison operators.

LogicOperator

It's a string literal type which defines built-in logic operators.

License

MIT