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.
Here you can find a small demo of Kanban board done with kasper-js
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.
The primary goal of Kasper-js is to create a comprehensive modern JavaScript framework. This includes:
Kasper’s template syntax aims to maintain valid HTML syntax, ensuring compatibility with any HTML editor. The syntax is designed to be:
The framework adheres to the following best practices:
To use Kasper, follow these steps:
kasper.js
script in your HTML file.<template>
element for your UI.KasperApp
class to create your application.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>
<div @if="this.something > 20">less 20</div>
<div @elseif="this.something === 30">its 30</div>
<div @else>other</div>
<ul>
<li @each="item of this.items">
<button @on:click="this.open(index)"></button>
</li>
</ul>
Evaluated during element creation
<div @let="student = {name: person.name, degree: 'Masters'}; console.log(student.name)">
</div>
<span @while="index < 3">
,
</span>
<button @on:click="alert('Hello World')">
Button
</button>
Evaluates the expression to string and inserts it into the dom as a TextNode
Hello
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.
Currently, the interpreter supports the following expressions:
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.
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.