Download the PHP package ralphschindler/calcdown without Composer
On this page you can find all versions of the php package ralphschindler/calcdown. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download ralphschindler/calcdown
More information about ralphschindler/calcdown
Files in ralphschindler/calcdown
Package calcdown
Short Description Text to calculator
License MIT
Informations about the package calcdown
Why Calcdown?
Ever wished you could add Numi-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:
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
โจ 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
Quick Start
Expression Examples
Basic Arithmetic
Currency Calculations
Unit Conversions
Date Arithmetic
Variables & Assignment
Percentage Calculations
Complex Expressions
Comments
API Reference
CalcdownParser
parseLine(string $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 stringresult- Calculated result (int|float|string)resultUnits- Unit of the result (string|null)assignedVariables- Variables defined in this line (array)
parseBlock(string $block): BlockEvaluation
Parse and evaluate multiple lines, maintaining variable context.
Parameters:
$block- Multi-line string of expressions
Returns: BlockEvaluation object with:
lines- Array ofLineEvaluationobjectsfinalLine()- Get the last evaluated line (or null if empty)toArray()- Convert all results to array format
LineEvaluation
BlockEvaluation
Supported Operators
| Operator | Description | Example |
|---|---|---|
+ |
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
Currency
$orUSD- US DollarsโฌorEUR- EurosยฃorGBP- British Pounds
Length
cm- Centimetersm- Meters
Volume
ml- Millilitersteaspoons/tsp- Teaspoons
Time
days- Days (for date arithmetic)date- Date type (fromtodaykeyword)
Percentages
%- Percentage (e.g.,20%)
Special Identifiers
today- Current date (can be used with+ X days)
Use Cases
1. Invoice Calculator
2. Project Timeline Calculator
3. Unit Conversion Tool
4. Financial Calculator
Error Handling
Currently, Calcdown focuses on parsing valid expressions. Invalid tokens or unrecognized operators are handled gracefully:
Development
Running Tests
Code Quality
- โ 100% Test Coverage
- โ 100% Type Coverage with PHPStan
- โ PSR-12 Coding Standards
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
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
This project is licensed under the MIT License - see the LICENSE.md file for details.
Inspiration
Calcdown is inspired by Numi, a beautiful calculator app for macOS. While Numi is a desktop application, Calcdown brings similar capabilities to web applications written in PHP.
Acknowledgments
All versions of calcdown with dependencies
markrogoyski/math-php Version 2.*
php-units-of-measure/php-units-of-measure Version ^2.2