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

bodmas-formula-engine

v1.4.1

Published

A powerful React component for building mathematical formulas with visual interface, real-time validation, and comprehensive function library

Readme

BODMAS Formula Engine

A powerful React component for building mathematical formulas with visual interface, real-time validation, and comprehensive function library.

🚀 Live Demo

Try the Interactive Demo →

Quick Examples

✨ Features

  • 🎯 Visual Formula Builder - Drag-and-drop interface
  • Real-time Validation - Instant feedback
  • 🧮 70+ Built-in Functions - Math, String, Date, Financial, Statistical
  • 🎨 Material-UI Integration - Beautiful, responsive design
  • 🔧 Extensible - Custom functions and variables
  • 📱 Mobile Friendly - Works on all devices
  • 🎪 Monaco Editor - Professional code editor with syntax highlighting

📦 Installation

npm install bodmas-formula-engine

Install peer dependencies:

npm install react react-dom @mui/material @emotion/react @emotion/styled @mui/icons-material @mui/lab

🎮 Quick Start

import React, { useState } from 'react';
import { FormulaBuilder } from 'bodmas-formula-engine';
import { ThemeProvider, createTheme } from '@mui/material/styles';
import CssBaseline from '@mui/material/CssBaseline';

const theme = createTheme();

function App() {
  const [formula, setFormula] = useState('');
  const variables = { 
    price: 100, 
    quantity: 5, 
    discount: 0.1 
  };

  const handleFormulaChange = (newFormula, validation) => {
    setFormula(newFormula);
    if (validation.valid) {
      console.log('Result:', validation.result);
    }
  };

  return (
    <ThemeProvider theme={theme}>
      <CssBaseline />
      <FormulaBuilder
        initialFormula={formula}
        onFormulaChange={handleFormulaChange}
        variables={variables}
      />
    </ThemeProvider>
  );
}

export default App;

🎯 Use Cases

  • E-commerce: Dynamic pricing calculators
  • Finance: Investment and loan calculators
  • Analytics: Custom metric calculations
  • Business Rules: Complex business logic
  • Reporting: Dynamic report formulas
  • Configuration: User-defined calculations

📚 Examples

Explore comprehensive examples in the /examples directory:

Basic Usage

// Simple price calculation
price * quantity * (1 - discount)

Custom Functions

// Business logic functions
DISCOUNT(price, customerType) + LOYALTY_BONUS(points)

E-commerce Calculator

// Complex pricing with multiple factors
(basePrice * quantity * SEASONAL_MULTIPLIER(period) * (1 - TIER_DISCOUNT(tier))) +
SHIPPING_COST(weight, destination) - COUPON_DISCOUNT(code, orderValue)

🔧 Advanced Usage

Custom Functions

const customFunctions = {
  DISCOUNT: {
    name: 'DISCOUNT',
    description: 'Calculate discount based on customer type',
    execute: (amount, customerType) => {
      const rates = { VIP: 0.2, REGULAR: 0.1 };
      return amount * (rates[customerType] || 0);
    }
  }
};

<FormulaBuilder customFunctions={customFunctions} />

Custom Variables

const CustomVariablePanel = ({ onVariableSelect }) => (
  <div>
    <button onClick={() => onVariableSelect('customVar')}>
      Custom Variable
    </button>
  </div>
);

<FormulaBuilder 
  CustomVariableComponent={CustomVariablePanel}
  variables={{ customVar: 42 }}
/>

🎨 Theming

const theme = createTheme({
  palette: {
    primary: { main: '#1976d2' },
    secondary: { main: '#dc004e' }
  }
});

<ThemeProvider theme={theme}>
  <FormulaBuilder />
</ThemeProvider>

📖 API Reference

FormulaBuilder Props

| Prop | Type | Default | Description | |------|------|---------|-------------| | initialFormula | string | '' | Initial formula value | | onFormulaChange | function | - | Callback when formula changes | | variables | object | {} | Available variables | | customFunctions | object | {} | Custom function definitions | | CustomVariableComponent | component | - | Custom variable panel | | readOnly | boolean | false | Read-only mode | | showValidation | boolean | true | Show validation panel | | showPreview | boolean | true | Show preview panel |

Built-in Functions

Mathematical

ABS, CEIL, FLOOR, ROUND, SQRT, POW, LOG, EXP, SIN, COS, TAN, MIN, MAX, SUM, AVERAGE

String Functions

CONCAT, LEFT, RIGHT, MID, LEN, UPPER, LOWER, TRIM, REPLACE, FIND

Date Functions

NOW, TODAY, YEAR, MONTH, DAY, WEEKDAY, DATEDIFF, DATEADD

Logical Functions

IF, AND, OR, NOT, ISBLANK, ISNUMBER, ISTEXT

Financial Functions

PV, FV, PMT, RATE, NPER, NPV, IRR

🤝 Contributing

We welcome contributions! Please see our Contributing Guide for details.

📄 License

MIT © Sandeep Bhatkande

🔗 Links


Made with ❤️ for the React community