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

cel-javascript

v0.0.19

Published

## Common Expression Language for JavaScript

Downloads

127

Readme

Not production ready yet

Common Expression Language for JavaScript

The Common Expression Language (CEL) is a non-Turing complete language designed for simplicity, speed, safety, and portability. The goal of this library is to adhere to the language definition of CEL and enable its use within a JavaScript project.

This library uses Peggy to match the CEL language definition. To utilize the pegjs file for making modifications, you can copy the following File and access the Online Editor. There, you can directly test the parser's outcomes.

Installation

To install cel-javascript:

npm install cel-javascript 

Usage

Presently, it's possible to evaluate a string without custom types. To do so, add the following line:

import { parseString } from 'cel-javascript';

And then you can do the following:

parseString("0"); // => {int64_value: 0}
parseString("0u"); // => {uint64_value: 0}
parseString("r'banana'"); // => {string_value: "banana"}
parseString("10 + 10 + 10"); // => {double_value: 30}
parseString("3 > 2 ? 1 : 4"); // => {int64_value: 1}

Additionally, you can use custom types by adding:

import { parseStringWithOptions } from 'cel-javascript';

To utilize custom types, pass a JSON object as a String to the function for reference:

let json = `{"banana": {"score": 1}}`
parseStringWithOptions("banana.score", json); // => {int64_value: 1}

The reason why it currently needs the JSON as a string is that I was currently not able because of the limitation of javascript and how it handles numbers to make sure that 1.0 would be read as a double instead of an int. To currently fix this I added the lossless-json library which enables me to at the time of fetching the value make the correct call to return a Double, Int64 or String value. This is something I want to try to fix in the future.