Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@rsql/parser

Package Overview
Dependencies
Maintainers
1
Versions
30
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@rsql/parser

RSQL parser

  • 0.0.1-next.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
7.2K
increased by20.19%
Maintainers
1
Weekly downloads
 
Created
Source

@rsql/parser

RSQL parser for Node.js and Browsers

⚠️ WARNING: This package is still in development - API may break compatibility without upgrading major version! ⚠️

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

Installation

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

# with yarn
yarn add @rsql/parser

API

parse(rsql: string): ExpressionNode

Parses RSQL string and returns Abstract Syntax Tree. It can throw the following errors:

  • InvalidArgumentError - in the case of invalid argument type passed to the parse function
  • ParsingError - in the case of any problems encountered during parsing
new ParsingError(message: string, source: string)

A runtime error that should be thrown in the case of encountering any problem with the parsing (invalid character, invalid token, etc.)

Example

import { parse, ParsingError } from "@rsql/parser";
import { isEqNode, getSingleValue } from "@rsql/ast";

function getUserNameFromRsql(rsql) {
  let ast;

  try {
    ast = parse(rsql);
  } catch (error) {
    if (error instanceof ParsingError) {
      return undefined;
    } else {
      throw error;
    }
  }

  if (isEqNode(ast) && getSelector(ast) === "user.name") {
    return getSingleValue(ast);
  } else {
    return undefined;
  }
}

License

MIT

FAQs

Package last updated on 05 May 2020

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc