Skip to content

v0.1.0

Choose a tag to compare

@junedkhatri31 junedkhatri31 released this 27 Jul 04:08
· 15 commits to main since this release

v0.1.0 - Initial Release (2025-07-27)

🎉 First stable release of @peedief/template-engine!

Overview

A fast, secure, and lightweight template engine for JavaScript/TypeScript that supports variable interpolation, conditional logic, and loops. Perfect for generating dynamic HTML, emails, configuration files, and more.

✨ Features

Core Template Engine

  • Variable Interpolation: Support for {{ variable }} syntax with nested property access
  • Conditional Logic: Full {% if %}...{% else %}...{% endif %} support
  • Loop Support: Iterate over arrays with {% for item in array %}...{% endfor %}
  • Nested Templates: Complex nested structures with multiple levels of conditions and loops

Security & Safety

  • XSS Protection: Automatic HTML escaping for all variable interpolations
  • Secure Evaluation: Sandboxed expression evaluation to prevent code injection
  • Safe Property Access: Graceful handling of missing or undefined properties
  • Input Validation: Robust error handling for malformed templates and invalid contexts

Performance & Optimization

  • Fast Parsing: Efficient tokenization and AST generation
  • Pre-compilation: Compile templates once, render multiple times for better performance
  • Large Dataset Support: Tested with 1000+ items rendering in <1 second
  • Memory Efficient: Low memory footprint with minimal overhead

Developer Experience

  • TypeScript First: Full TypeScript support with comprehensive type definitions
  • Zero Dependencies: No external runtime dependencies
  • Detailed Error Messages: Clear error reporting with position information
  • Comprehensive Testing: 80%+ test coverage with extensive edge case handling

🚀 API

Main Functions

import { render, compile } from '@peedief/template-engine';

// Direct rendering
const result = render(template, context);

// Pre-compilation for better performance
const compiledTemplate = compile(template);
const result = compiledTemplate(context);

Supported Syntax

  • Variables: {{ variable }}, {{ object.property }}, {{ array.0 }}
  • Conditionals: {% if condition %}...{% endif %}, {% if condition %}...{% else %}...{% endif %}
  • Loops: {% for item in array %}...{% endfor %}

📦 Installation

npm install @peedief/template-engine
yarn add @peedief/template-engine
pnpm add @peedief/template-engine

🔧 Technical Details

Architecture

  • 4-Phase Processing: Tokenizer → Parser → AST → Evaluator
  • Token Types: TEXT, VARIABLE, IF_START, ELSE, IF_END, FOR_START, FOR_END
  • AST Nodes: Text, Variable, Conditional, Loop nodes with proper nesting

Browser & Runtime Support

  • Node.js: 16.x, 18.x, 20.x, 22.x+
  • TypeScript: 5.0+
  • Modern Browsers: Chrome, Firefox, Safari, Edge

Build & Development

  • Language: TypeScript with full type safety
  • Testing: Jest with comprehensive test suites
  • Linting: ESLint with TypeScript rules
  • CI/CD: GitHub Actions with automated testing and publishing

🧪 Test Coverage

  • Integration Tests: End-to-end template rendering scenarios
  • Security Tests: XSS prevention and safe evaluation
  • Performance Tests: Large dataset handling and deep nesting
  • Edge Cases: Malformed templates, missing context, circular references
  • Unit Tests: Individual component testing (tokenizer, parser, evaluator)

📝 Use Cases

Perfect for:

  • Dynamic HTML Generation: Web applications, email templates
  • Configuration Files: Dynamic config generation
  • Report Generation: Data-driven document creation
  • Content Management: Blog posts, articles, product listings
  • Dashboard Rendering: Statistics, user interfaces, admin panels

🔒 Security Features

  • Automatic HTML Escaping: All variables are HTML-escaped by default
  • Expression Sandboxing: Safe evaluation prevents code injection
  • No Script Execution: Templates cannot execute arbitrary JavaScript
  • XSS Prevention: Built-in protection against cross-site scripting attacks

🚀 Performance Benchmarks

  • Large Arrays: 1000 items rendered in <1 second
  • Deep Nesting: 4+ levels of nested loops and conditions supported
  • Memory Usage: Minimal footprint with efficient AST representation
  • Compilation Cache: Pre-compiled templates significantly improve repeated rendering

📚 Documentation

  • Comprehensive README: Full usage examples and API documentation
  • TypeScript Definitions: Complete type safety and IntelliSense support
  • Code Examples: Real-world use cases including e-commerce, blogs, dashboards
  • Error Handling: Detailed error messages with position information

🛠️ Development Features

  • GitHub Actions: Automated CI/CD pipeline
  • NPM Publishing: Automated publishing on tag creation
  • Code Quality: ESLint, TypeScript checking, test coverage
  • Multi-Node Testing: Tested on Node.js 16, 18, 20, and 22

🔄 Breaking Changes

None - this is the initial release.

📋 Known Limitations

  • Templates are processed synchronously
  • No built-in template inheritance or includes
  • Limited to HTML escaping (no other output formats)

🎯 Next Steps

Future releases may include:

  • Template inheritance and includes
  • Custom filters and functions
  • Multiple output format support
  • Async template processing
  • Performance optimizations

Full Changelog: Initial release

Download: npm install @peedief/template-engine@0.1.0