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 🙏

© 2025 – Pkg Stats / Ryan Hefner

digia_expr

v1.0.0

Published

Expression evaluator for React Native - TypeScript port of digia_expr

Readme

Digia Expression Evaluator for React Native

A powerful and flexible expression evaluator for React Native and JavaScript, built on an extensible visitor pattern architecture.

Features

  • Extensible Visitor Pattern - Create custom analyzers by extending Visitor<T>
  • AST Access - Full access to the Abstract Syntax Tree
  • Expression Parsing - Built-in scanner and parser
  • TypeScript Support - Full type definitions included
  • React Native Compatible - Works seamlessly in React Native apps
  • Variables & Functions - Support for variables and function calls
  • Property Access - Navigate nested properties with dot notation

Installation

npm install @digia/expr-rn
# or
yarn add @digia/expr-rn

Quick Start

Basic Expression Parsing

import { createAST } from '@digia/expr-rn';

const ast = createAST('user.name');
console.log(ast);

Creating Custom Visitors

import { Visitor, ASTProgram, ASTVariable, createAST } from '@digia/expr-rn';

// Custom visitor to collect variable names
class VariableCollectorVisitor extends Visitor<string[]> {
  visitProgram(node: ASTProgram): string[] {
    const vars: string[] = [];
    for (const expr of node.body) {
      vars.push(...expr.visit(this));
    }
    return vars;
  }

  visitASTVariable(node: ASTVariable): string[] {
    return [node.name.lexeme];
  }

  visitASTGetExpr(node: ASTGetExpr): string[] {
    return node.expr.visit(this);
  }

  // Implement other required methods...
}

// Use the visitor
const ast = createAST('user.name');
const collector = new VariableCollectorVisitor();
const variables = ast.visit(collector);
console.log(variables); // ['user']

Collecting Property Access Paths

class PropertyPathVisitor extends Visitor<string[]> {
  visitASTVariable(node: ASTVariable): string[] {
    return [node.name.lexeme];
  }

  visitASTGetExpr(node: ASTGetExpr): string[] {
    const basePaths = node.expr.visit(this);
    return basePaths.map(base => `${base}.${node.name.lexeme}`);
  }

  // Implement other methods...
}

const ast = createAST('appState.user.profile.name');
const pathCollector = new PropertyPathVisitor();
const paths = ast.visit(pathCollector);
console.log(paths); // ['appState.user.profile.name']

React Native Example

import React, { useState } from 'react';
import { View, Text, TextInput } from 'react-native';
import { createAST, Visitor, ASTProgram, ASTVariable } from '@digia/expr-rn';

class VariableExtractor extends Visitor<string[]> {
  // Implement visitor methods...
}

function ExpressionAnalyzer() {
  const [expression, setExpression] = useState('');
  const [variables, setVariables] = useState<string[]>([]);

  const analyzeExpression = (expr: string) => {
    try {
      const ast = createAST(expr);
      const extractor = new VariableExtractor();
      const vars = ast.visit(extractor);
      setVariables(vars);
    } catch (error) {
      console.error('Parse error:', error);
    }
  };

  return (
    <View>
      <TextInput
        value={expression}
        onChangeText={(text) => {
          setExpression(text);
          analyzeExpression(text);
        }}
        placeholder="Enter expression"
      />
      <Text>Variables: {variables.join(', ')}</Text>
    </View>
  );
}

API Reference

Core Functions

  • createAST(expression: string): ASTNode - Parse an expression into an AST

AST Node Types

  • ASTProgram - Root program node
  • ASTVariable - Variable reference
  • ASTGetExpr - Property access (dot notation)
  • ASTCallExpression - Function call
  • ASTNumberLiteral - Number literal
  • ASTStringLiteral - String literal
  • ASTStringExpression - String with embedded expressions
  • ASTBooleanLiteral - Boolean literal

Visitor Pattern

Extend Visitor<T> where T is your return type:

abstract class Visitor<T> {
  abstract visitProgram(node: ASTProgram): T;
  abstract visitASTVariable(node: ASTVariable): T;
  abstract visitASTGetExpr(node: ASTGetExpr): T;
  abstract visitCallExpression(node: ASTCallExpression): T;
  abstract visitASTNumberLiteral(node: ASTNumberLiteral): T;
  abstract visitASTStringLiteral(node: ASTStringLiteral): T;
  abstract visitASTStringExpression(node: ASTStringExpression): T;
}

Use Cases

  1. Static Analysis - Analyze expressions to extract variable dependencies
  2. Code Generation - Transform expressions into different formats
  3. Validation - Validate expressions before evaluation
  4. Custom Evaluators - Build domain-specific expression evaluators
  5. Dependency Tracking - Track what data an expression accesses

License

MIT

Author

Digia Technology Private Limited