File: readme.md

Recommend this page to a friend!
  Packages of ikhsan   jQuery Calx   readme.md   Download  
File: readme.md
Role: Documentation
Content type: text/markdown
Description: Documentation
Class: jQuery Calx
Calculate form input values based on formulas
Author: By
Last change:
Date: 6 months ago
Size: 8,083 bytes
 

Contents

Class file image Download

jQuery Calx 3.0

<div align="center">

Version TypeScript License Tests

Modern spreadsheet-like calculation engine for the web

Transform your HTML forms into powerful spreadsheet calculators with real-time formula evaluation, cell dependencies, and Excel-compatible functions.

Documentation โ€ข Examples โ€ข Legacy Docs

</div>

โœจ Features

  • ๐Ÿ”ง TypeScript Rewrite - Complete modern rewrite with improved type safety
  • โšก Dynamic Dependencies - Automatic dependency tracking and calculation
  • ๐Ÿ’ฐ Input Masking - Built-in formatters (currency, percent, number, etc.)
  • ๐ŸŽจ Conditional Styling - Apply CSS styles based on cell values
  • ๐Ÿท๏ธ Named Variables - Use readable names instead of cell addresses
  • ๐Ÿ“Š Multi-Sheet Support - Work with multiple calculation sheets
  • ๐Ÿš€ Auto Addresses - Formula cells get automatic CALX addresses
  • ๐Ÿ“ฑ Responsive - Mobile-friendly with modern UI
  • ๐Ÿงฎ Excel Functions - 400+ Excel-compatible functions via FormulaJS
  • ๐Ÿ”„ Backward Compatible - Works with jQuery Calx 2.x code

๐Ÿš€ Quick Start

Installation

Via NPM

npm install @xsanisty/calxjs

Via CDN (Coming Soon)

<!-- jQuery (required for plugin) -->
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>

<!-- jQuery Calx -->
<script src="https://cdn.jsdelivr.net/npm/@xsanisty/[email protected]/dist/jquery.calx.js"></script>

Basic Example

<form id="calculator">
    <input type="number" data-cell="A1" value="10">
    <input type="number" data-cell="A2" value="20">
    <input type="text" data-formula="A1+A2" readonly>
</form>

<script>
    $('#calculator').calx();
</script>

With Formatters

<form id="invoice">
    <input data-cell="A1" data-var="PRICE" value="100" data-format="currency">
    <input data-cell="A2" data-var="QTY" value="5">
    <input data-cell="A3" data-var="TAX" value="0.08" data-format="percent">
    <input data-formula="PRICEQTY(1+TAX)" data-format="currency" readonly>
</form>

<script>
    $('#invoice').calx({ autoCalculate: true });
</script>

๐Ÿ“š Documentation

๐Ÿ’ก Examples

Explore interactive examples in the examples/ directory:

๐Ÿ“– Usage

jQuery Plugin

// Initialize
$('#form').calx({
    autoCalculate: true,
    data: {
        A1: { value: 100, format: 'currency' }
    },
    variables: {
        TAX: 'A1'
    },
    functions: {
        CUSTOM: function(x) { return x * 2; }
    }
});

// Methods
$('#form').calx('getCellValue', 'A1');
$('#form').calx('setCellValue', 'A1', 100);
$('#form').calx('calculate');

TypeScript API

import { Calx } from '@xsanisty/calxjs';

const workbook = Calx.createWorkbook();
const sheet = workbook.createSheet('sheet1');

sheet.mount('#element');
sheet.setCell('A1', 10);
sheet.setCell('A2', 20);
sheet.setCell('A3', '=A1+A2');

sheet.calculate();
console.log(sheet.getCell('A3').value); // 30

๐Ÿ”ง Development

Prerequisites

  • Node.js 16+
  • npm or yarn

Setup

# Install dependencies
npm install

# Build both core and jQuery plugin
npm run build

# Run tests
npm test

# Run tests in watch mode
npm test:watch

# Generate coverage report
npm run test:coverage

Build Commands

| Command | Description | |---------|-------------| | npm run build | Build both core and jQuery plugin | | npm run build:core | Build core library only | | npm run build:jquery | Build jQuery plugin only | | npm run build-parser | Regenerate formula parser (rarely needed) |

Project Structure

calx.js/
โ”œโ”€โ”€ src/                    # TypeScript source
โ”‚   โ”œโ”€โ”€ Calx.ts            # Main entry point
โ”‚   โ”œโ”€โ”€ Calx/              # Core classes
โ”‚   โ”‚   โ”œโ”€โ”€ Cell.ts
โ”‚   โ”‚   โ”œโ”€โ”€ Sheet.ts
โ”‚   โ”‚   โ”œโ”€โ”€ Workbook.ts
โ”‚   โ”‚   โ”œโ”€โ”€ Formula/       # Formula engine
โ”‚   โ”‚   โ”œโ”€โ”€ Parser/        # Expression parser
โ”‚   โ”‚   โ””โ”€โ”€ Utility/       # Helper functions
โ”‚   โ””โ”€โ”€ jquery.calx.ts     # jQuery plugin
โ”œโ”€โ”€ dist/                   # Compiled output
โ”‚   โ”œโ”€โ”€ calx.js            # Core library
โ”‚   โ””โ”€โ”€ jquery.calx.js     # jQuery plugin
โ”œโ”€โ”€ examples/               # Live examples
โ”œโ”€โ”€ test/                   # Jest tests
โ”œโ”€โ”€ docs/                   # Documentation
โ””โ”€โ”€ legacy/                 # jQuery Calx 2.x

๐Ÿงช Testing

Currently 209 out of 223 tests passing (93.7%).

# Run all tests
npm test

# Watch mode
npm test:watch

# With coverage
npm run test:coverage

# Performance benchmarks
npm run test:performance

Performance Benchmarks

The test suite includes comprehensive performance tests that measure:

  • Formula Parsing - 1000+ formulas in <2s
  • Calculation Speed - 1000 cells in <1s
  • Dependency Chains - 100-cell chain in <500ms
  • Large Datasets - 10x100 grid (1000 cells) in <3s
  • SUM Ranges - 10 SUMs over 1000 cells in <1s
  • Complex Formulas - Nested IF, SUMIF, mathematical operations
  • Multi-Sheet - Cross-sheet references
  • Real-World Scenarios - Invoice calculations, mortgage amortization

Run npm run test:performance to see detailed timing metrics for your system.

๐Ÿค Contributing

Contributions are welcome! Please read our Contributing Guide for details.

  1. Fork the repository
  2. Create your feature branch (`git checkout -b feature/amazing-feature`)
  3. Commit your changes (`git commit -m 'Add amazing feature'`)
  4. Push to the branch (`git push origin feature/amazing-feature`)
  5. Open a Pull Request

๐Ÿ“ License

MIT License - see LICENSE file for details.

๐Ÿ™ Acknowledgments

  • Original jQuery Calx 2.x by @xsanisty
  • FormulaJS for Excel function implementations
  • Chevrotain for parser infrastructure
  • All contributors and users of jQuery Calx

๐Ÿ“ž Support

<div align="center">

Made with โค๏ธ by Xsanisty

โญ Star us on GitHub โ€” it helps!

GitHub โ€ข npm

</div>