kasper-js

Kasper-js 1.0.1

Kasper-js is a work-in-progress JavaScript HTML template parser and renderer designed to help create and learn core mechanics of modern JavaScript frameworks.

> Try it out in playground!

Here you can find a small demo of Kanban board done with kasper-js

> KasperJS Kanban board demo

Project Vision

Kasper-js aims to bridge the gap between simple templating engines and full-fledged JavaScript frameworks by providing a lightweight, extensible solution that emphasizes performance and developer experience. As web applications continue to evolve, the need for flexible and efficient frameworks has never been greater.

Project Goals

The primary goal of Kasper-js is to create a comprehensive modern JavaScript framework. This includes:

Template syntax goals

Kasper’s template syntax aims to maintain valid HTML syntax, ensuring compatibility with any HTML editor. The syntax is designed to be:

Best Practices

The framework adheres to the following best practices:

Features Implemented So Far

To use Kasper, follow these steps:

  1. Include the kasper.js script in your HTML file.
  2. Create a <template> element for your UI.
  3. Extend the KasperApp class to create your application.
  4. Render the app by calling Kasper.
<html>
  <head>
    <script src="kasper.min.js"></script>
  </head>
  <body>
    <template>
      <div></div>
    </template>
    <script>
      class MyApp extends KasperApp {
        myAppName = "MyAppName"
      }
      Kasper(MyApp);
    </script>
  </body>
</html>

Conditional expression

  <div @if="this.something > 20">less 20</div>
  <div @elseif="this.something === 30">its 30</div>
  <div @else>other</div>

Foreach expression

<ul>
  <li @each="item of this.items">
    <button @on:click="this.open(index)"></button>
  </li>
</ul>

Let expression

Evaluated during element creation

<div @let="student = {name: person.name, degree: 'Masters'}; console.log(student.name)">
    
</div>

While expression

<span @while="index < 3">
  ,
</span>

Event listener expression

<button @on:click="alert('Hello World')">
  Button
</button>

Template string expression

Evaluates the expression to string and inserts it into the dom as a TextNode

Hello

Template Expression Interpreter

The Kasper expression interpreter is designed to emulate basic JavaScript expressions, providing a versatile framework for template rendering and dynamic content management. It allows developers to use familiar JavaScript syntax and constructs, enhancing the functionality and flexibility of the templates.

Supported JavaScript Expressions

Currently, the interpreter supports the following expressions:

Future Enhancements

Future updates will focus on expanding the capabilities of the expression interpreter, incorporating additional expressions and features to enhance the framework’s power and usability.

Testing

Kasper-js employs Jasmine for unit testing to ensure code reliability and maintainability. The tests are organized in the /specs folder, allowing for easy navigation and management of test cases. However, the current test coverage needs improvement, and additional tests are encouraged to enhance the robustness of the framework.

Todo