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

@witchcraft/expressit

v0.2.2

Published

A blazing fast, customizable, error-tolerant expression parser that creates safe to eval expressions + a few other goodies like autocomplete.

Downloads

87

Readme

🚧 WORK IN PROGRESS 🚧

NPM Version (with latest tag)

Build Docs Release

Expressit is a blazing fast, customizable, error-tolerant expression parser that creates safe to eval expressions + a few other goodies.

Docs

Demo

Install

pnpm install @witchcraft/expressit

Features

  • Error Recovery
    • The parser is designed to recover from ALL errors, even multiple errors, making it easy to provide things like syntax highlighting.
  • Custom Operator Keywords
    • You can use whatever keywords you want for the operators and their strictness (whether something like oregano will parse to or egano or oregano can be adjusted to allow the use of keywords (usually symbols) without whitespace).
  • Prefixed Group Parsing (optional)
    • Adds the ability do prefix(variable) which gets expanded into prefixvariable. You can also customize how they get prefixed (e.g. you can make prefix(variable) expand to prefix.variable instead).
  • Custom Property Operator
    • Extended with custom separator (e.g. :): property:OP:value.
    • Custom set (e.g. =, >, <, etc): property=value.
    • Array(optional), Regex(optional), and Group Values
      • Can be parsed alone, but intended for use with custom property operators: prop=[val1, val2], prop=/regex/flags, prop=(a || b).
  • Batteries Included
    • Can validate (for syntax highlighting) and evaluate ASTs according to custom rules.
  • Autosuggest/complete/replace Helpers
    • Never think about autocompletion ever again!
  • Other Useful Utility Functions:
    • extractTokens, getCursorInfo, getOppositeDelimiter, getSurroundingErrors - useful for adding custom syntax highlighting.
    • prettyAst - pretty prints a compact version of the ast for debugging
    • other minor utilities - isDelimiter, isQuote, etc.
  • Pre-Configured Example Parsers
    • Shortcut Context Parser / Boolean Parser - Intended for parsing shortcut contexts in a similar way to VS Code).
    • Experimental parser with SQL output support - Create an easy to read query language that can be used to generate safe SQL queries (it's flexible, but built to integrate easily with drizzle).
  • Lots of Docs and Tests

Usage

// while you can import from "@witchcraft/expressit", if using something like vite, it's recommended you do not use barrel imports.
import { Parser } from "@witchcraft/expressit/Parser.js"

const parser = new Parser({/* opts */})
	const context = {
		a: false,
		b: true
	}

	// USER INPUT
	const input = "a || b"
	const cursor = 1 // a| || b

	const ast = parser.parse(input)

	if (!ast.valid) {
		// ...show regular errors (no input, missing tokens, etc)
		if (ast.isToken) {
			// empty input
		}
	} else {
		// validation can be controlled by parser options
		const errors = parser.validate(ast)
		// ...show more complex errors, e.g. unknown variables, etc
	}

	// ON AUTOCOMPLETE
	const suggestions = parser.autosuggest(input, ast, cursor)
	const completions = parser.autocomplete(ast,suggestions, {
		// known possible suggestions
		variables: ["c", "d", "e"],
		// can also be values, prefixes, keywords, properties, etc
	})
	// ...show completions

	// ON ENTER/SUBMIT
	const res = parser.evaluate(ast, context)

Many more examples can be found in the tests, and there's also some example pre-configured parsers in src/examples whose usage can be seen in ./test/examples.spec.ts.

Development

Related

Shortcuts Manager

Parsekey (shortcuts parser)