Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

kstpl

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

kstpl

Ksike Template Engine

  • 1.1.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

KsTpl: Template Compilation Made Easy

KsTpl is a versatile and extensible Node.js library designed for seamless template compilation in various formats, including Markdown, Twig, EJS, and more. It's a part of the robust Ksike ecosystem, ensuring reliability and compatibility with a range of applications.

Key Features:

  • Format Agnostic: KsTpl supports multiple template formats, allowing you to work with your preferred syntax effortlessly.
  • Extensibility: Easily integrate new template formats by creating custom drivers. KsTpl follows a simple and intuitive driver concept.
  • Cache Management: Benefit from an efficient caching system that you can adapt to your needs, ensuring optimal performance.

This library belong to the Ksike ecosystem:

  • KsMf - Microframework (WEB, REST API, CLI, Proxy, etc)
  • Ksdp - Design Patterns Library (GoF, GRASP, IoC, DI, etc)
  • KsCryp - Cryptographic Library (RSA, JWT, x509, HEX, Base64, Hash, etc)
  • KsHook - Event Driven Library
  • KsEval - Expression Evaluator Library
  • KsWC - Web API deployment Library
  • KsTpl - Template Engine
  • KsDoc - Document Engine

Driver

Quick overview

Installation

npm install kstpl

Load the library

const KsTpl = require("kstpl");

Compile: Template Simple Format

const html = KsTpl.compile(
    "{{name}}:{{age}}", 
    { name: "Mit", age: 15 }, 
    { driver: "str" }
);

console.log(
    html === "Mit:15"
)

Compile: Template Twig Format

const html = KsTpl.compile(
    "{{name}}:{{age}}", 
    { name: "Mit", age: 15 }, 
    { driver: "twing" }
);

console.log(
    html === "Mit:15"
)

Compile: Template Ejs Format

const html = KsTpl.compile(
    '<%= people.join(","); %>', 
    { people: ['geddy', 'neil', 'alex'] }, 
    { driver: "ejs" }
);

console.log(
    html === "geddy,neil,alex"
)

Compile: Template Markdown Format

const html = KsTpl.compile(
    '# Hello, Markdown!', 
    null, 
    { driver: "markdown" }
);

console.log(
    html === "<h1>Hello, Markdown!</h1>\n"
)

Template engine format autodetection

KsTpl.configure({ 
    map: { "md": "markdown", "html": "twing", "twig": "twing", "ejs": "ejs", "htmljs": "ejs" }, 
    path: __dirname,
    ext: ""
});

const ejs2html = await KsTpl.render("simple.ejs", { user: { name: "Mit", age: 15 } });
const md2html = await KsTpl.render("linked.md", {}, { page: {}, next: "Highlight" });
const twig2html = await KsTpl.render("simple.twig", {
    list: [
        { name: "Mat", age: 3, twig: true },
        { name: "Deg", age: 4, twig: false },
        { name: "Ste", age: 5, twig: true }
    ]
});

Keywords

FAQs

Package last updated on 19 Mar 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc