PHPackages                             ralphschindler/calcdown - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. ralphschindler/calcdown

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

ralphschindler/calcdown
=======================

Text to calculator

v0.1.1(6mo ago)09MITPHPPHP ^8.4.0CI passing

Since Nov 2Pushed 6mo agoCompare

[ Source](https://github.com/ralphschindler/calcdown)[ Packagist](https://packagist.org/packages/ralphschindler/calcdown)[ RSS](/packages/ralphschindler-calcdown/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (8)Versions (3)Used By (0)

 [![Calcdown Logo](docs/calcdown.png)](docs/calcdown.png)Calcdown
========

[](#calcdown)

**A human-readable calculator DSL for web applications**

[![Tests](https://camo.githubusercontent.com/d940ad7f0752e2cbe0d63c50dcebf329078807390051c41fe63258f1b5c4e182/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f74657374732d70617373696e672d627269676874677265656e)](tests/)[![Coverage](https://camo.githubusercontent.com/32855e94577df9d0a30995653b17d33a5fbfdf644518f96ea0374313397d19b7/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f636f7665726167652d3130302532352d627269676874677265656e)](tests/)[![Type Coverage](https://camo.githubusercontent.com/04a36ae1deb005f897015614ed2851d4e5e0858d79d715d51ab649d1e0f8a17a/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f74797065732d3130302532352d627269676874677265656e)](phpstan.neon.dist)[![PHP](https://camo.githubusercontent.com/c9f64f714c636ba27a3bba6dfd52f98426832db1262747efa54b212d16943651/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d253545382e322d626c7565)](composer.json)[![License](https://camo.githubusercontent.com/b8cadaa967891081f8f165695470689986c028821dd8a040132f6e661795dc0d/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d626c7565)](LICENSE.md)

---

Why Calcdown?
-------------

[](#why-calcdown)

Ever wished you could add **[Numi](https://numi.app)**-style calculations to your web application? Calcdown brings that magic to PHP.

Instead of building complex calculator UIs with buttons and operators, let your users write natural calculations like they would in a notebook:

```
price = $8 times 3
tax = price + 15%
total = tax in EUR

```

**Perfect for:**

- 📊 Financial dashboards and invoice calculators
- 🧮 Educational platforms teaching math or finance
- 📝 Note-taking apps with computational capabilities
- 💰 Pricing calculators with unit conversions
- 📅 Date arithmetic for project planning

Features
--------

[](#features)

✨ **Human-Readable Syntax** - Write calculations the way you think
🔢 **Unit Conversions** - Currency, measurements, and more
📆 **Date Arithmetic** - Add days, calculate deadlines
💱 **Currency Support** - USD, EUR, GBP with conversions
🎯 **Variable Assignment** - Store and reuse values
📐 **Order of Operations** - Proper PEMDAS/BODMAS handling
💯 **100% Test Coverage** - Rock-solid and production-ready

Installation
------------

[](#installation)

```
composer require ralphschindler/calcdown
```

Quick Start
-----------

[](#quick-start)

```
use Calcdown\CalcdownParser;

$parser = new CalcdownParser();

// Simple calculation
$result = $parser->parseLine('2 + 2');
echo $result->result; // 4

// With units and conversions
$result = $parser->parseLine('$50 + 20%');
echo $result->result; // "60"
echo $result->resultUnits; // "USD"

// Multi-line calculations with variables
$block = result; // "1800"
```

Expression Examples
-------------------

[](#expression-examples)

### Basic Arithmetic

[](#basic-arithmetic)

```
2 + 2                    // 4
5 * (3 + 1)             // 20
10 / 2                  // 5
2 ^ 3                   // 8 (exponentiation)
10 % 3                  // 1 (modulo)
```

### Currency Calculations

[](#currency-calculations)

```
$100 + $50              // "150" (USD)
€200 - 10%              // 180 (EUR)
£50 in Euros            // 57.5 (EUR)
$7 * 4                  // "28" (USD)
```

### Unit Conversions

[](#unit-conversions)

```
100 cm in m             // 1 (m)
20 ml in teaspoons      // "4.05" (tsp)
50 cm in inches         // 50 (inches)
```

### Date Arithmetic

[](#date-arithmetic)

```
today + 7 days          // "2025-11-09" (date)
today + 30 days         // "2025-12-02" (date)
```

### Variables &amp; Assignment

[](#variables--assignment)

```
price = $8 times 3      // Assign $24 to price
tax = price * 8.5%      // Use price variable
total = price + tax     // "25.02" (USD approx)
```

### Percentage Calculations

[](#percentage-calculations)

```
100 + 20%               // 120
200 - 15%               // 170
20% of what is 50       // 250 (reverse percentage)
```

### Complex Expressions

[](#complex-expressions)

```
// Combining multiple features
base = $299 times 1
discount = base - 25%
tax = discount + 8.5%
final = tax in EUR      // Approx "207.06" (EUR)

// Construction calculations
length = 25 cm * 6
buffered = length + 5%
meters = buffered in m    // 1.58 (m)
```

### Comments

[](#comments)

```
2 + 2 # This is a comment
# Lines starting with # are ignored
price = $100 # inline comments work too
```

API Reference
-------------

[](#api-reference)

### CalcdownParser

[](#calcdownparser)

#### `parseLine(string $line, array $variables = []): LineEvaluation`

[](#parselinestring-line-array-variables---lineevaluation)

Parse and evaluate a single line expression.

**Parameters:**

- `$line` - The expression to parse
- `$variables` - Optional associative array of predefined variables

**Returns:** `LineEvaluation` object with:

- `expression` - Original expression string
- `result` - Calculated result (int|float|string)
- `resultUnits` - Unit of the result (string|null)
- `assignedVariables` - Variables defined in this line (array)

```
$result = $parser->parseLine('price = $50 + 20%');
$result->result;              // "60"
$result->resultUnits;         // "USD"
$result->assignedVariables;   // ['price' => "60"]
```

#### `parseBlock(string $block): BlockEvaluation`

[](#parseblockstring-block-blockevaluation)

Parse and evaluate multiple lines, maintaining variable context.

**Parameters:**

- `$block` - Multi-line string of expressions

**Returns:** `BlockEvaluation` object with:

- `lines` - Array of `LineEvaluation` objects
- `finalLine()` - Get the last evaluated line (or null if empty)
- `toArray()` - Convert all results to array format

```
$block = "a = 10\nb = 5\nresult = a + b";
$results = $parser->parseBlock($block);
$final = $results->finalLine();
$final->result; // 15
```

### LineEvaluation

[](#lineevaluation)

```
$line->toArray(); // Returns associative array:
// [
//     'expression' => '2 + 2',
//     'result' => 4,
//     'units' => null,
//     'assigned_variables' => []  // Only if variables were assigned
// ]
```

### BlockEvaluation

[](#blockevaluation)

```
$block->toArray(); // Returns array of line results
$block->finalLine(); // Returns last LineEvaluation or null
$block->lines; // Array of all LineEvaluation objects
```

Supported Operators
-------------------

[](#supported-operators)

OperatorDescriptionExample`+`Addition`5 + 3` → `8``-`Subtraction`10 - 4` → `6``*` or `times` or `x`Multiplication`4 * 3` → `12``/`Division`10 / 2` → `5``%`Modulo`10 % 3` → `1``^`Exponentiation`2 ^ 3` → `8``=`Assignment`x = 5``in`Unit conversion`100 cm in m` → `1``of what is`Reverse percentage`20% of what is 50` → `250`Supported Units
---------------

[](#supported-units)

### Currency

[](#currency)

- `$` or `USD` - US Dollars
- `€` or `EUR` - Euros
- `£` or `GBP` - British Pounds

### Length

[](#length)

- `cm` - Centimeters
- `m` - Meters

### Volume

[](#volume)

- `ml` - Milliliters
- `teaspoons` / `tsp` - Teaspoons

### Time

[](#time)

- `days` - Days (for date arithmetic)
- `date` - Date type (from `today` keyword)

### Percentages

[](#percentages)

- `%` - Percentage (e.g., `20%`)

Special Identifiers
-------------------

[](#special-identifiers)

- `today` - Current date (can be used with `+ X days`)

Use Cases
---------

[](#use-cases)

### 1. Invoice Calculator

[](#1-invoice-calculator)

```
$invoice = result; // 5
```

Development
-----------

[](#development)

### Running Tests

[](#running-tests)

```
# Run all tests
composer test

# Run with coverage
XDEBUG_MODE=coverage vendor/bin/pest --coverage

# Run type checking
composer test:types
```

### Code Quality

[](#code-quality)

- ✅ 100% Test Coverage
- ✅ 100% Type Coverage with PHPStan
- ✅ PSR-12 Coding Standards

Contributing
------------

[](#contributing)

Contributions are welcome! Please feel free to submit a Pull Request.

Roadmap
-------

[](#roadmap)

- More currency conversion rates (dynamic/configurable)
- Additional unit types (temperature, weight, speed)
- Function support (`sqrt()`, `round()`, etc.)
- Better error messages and validation
- Expression compilation for repeated use
- Plugin system for custom operators/units

License
-------

[](#license)

This project is licensed under the MIT License - see the [LICENSE.md](LICENSE.md) file for details.

Inspiration
-----------

[](#inspiration)

Calcdown is inspired by [Numi](https://numi.app), a beautiful calculator app for macOS. While Numi is a desktop application, Calcdown brings similar capabilities to web applications written in PHP.

Acknowledgments
---------------

[](#acknowledgments)

- Built with ❤️ using PHP 8.2+
- Tested with [Pest](https://pestphp.com)
- Type-safe with [PHPStan](https://phpstan.org)

---

 Made with ☕ and 🧮 [Report Bug](issues) · [Request Feature](issues)

###  Health Score

32

—

LowBetter than 72% of packages

Maintenance68

Regular maintenance activity

Popularity4

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity43

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~3 days

Total

2

Last Release

186d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/9c4a15cb4e97bc39a3aea8304fb04d56c0d753f2a6b79c83db0a894647ba8de7?d=identicon)[ralphschindler](/maintainers/ralphschindler)

---

Top Contributors

[![ralphschindler](https://avatars.githubusercontent.com/u/76674?v=4)](https://github.com/ralphschindler "ralphschindler (14 commits)")

---

Tags

calculatormathphpmathcalculator

###  Code Quality

TestsPest

Static AnalysisPHPStan

Code StyleLaravel Pint

Type Coverage Yes

### Embed Badge

![Health badge](/badges/ralphschindler-calcdown/health.svg)

```
[![Health](https://phpackages.com/badges/ralphschindler-calcdown/health.svg)](https://phpackages.com/packages/ralphschindler-calcdown)
```

###  Alternatives

[brick/math

Arbitrary-precision arithmetic library

2.1k504.0M276](/packages/brick-math)[markrogoyski/math-php

Math Library for PHP. Features descriptive statistics and regressions; Continuous and discrete probability distributions; Linear algebra with matrices and vectors, Numerical analysis; special mathematical functions; Algebra

2.4k7.1M39](/packages/markrogoyski-math-php)[phpseclib/bcmath_compat

PHP 5.x-8.x polyfill for bcmath extension

16720.7M17](/packages/phpseclib-bcmath-compat)[rubix/tensor

A library and extension that provides objects for scientific computing in PHP.

2751.4M5](/packages/rubix-tensor)[markrogoyski/ipv4-subnet-calculator

Network calculator for subnet mask and other classless (CIDR) network information.

177813.7k6](/packages/markrogoyski-ipv4-subnet-calculator)[jlawrence/eos

Parse and solve math equations without using 'eval()'.

1071.1M11](/packages/jlawrence-eos)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
