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

tarkine

Package Overview
Dependencies
Maintainers
0
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

tarkine

tarkine - A powerful and flexible template engine for Node.js applications.

  • 0.0.3
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
0
Created
Source

Tarkine is a powerful and flexible template engine for Node.js applications. It provides a simple syntax for creating dynamic HTML templates with various features like comments, escaping, conditionals, loops, includes, blocks, and code execution.

npm version Downloads License

Installation

npm install tarkine

Usage

const tarkine = require('tarkine');

const output = tarkine.renderFile("./template.html", {
    username: "John Doe",
    html: "<span>Some HTML</span>",
    status: true,
    array: [1, 2, 3],
    object: {
        username: "johndoe",
        age: 30
    },
});

console.log(output);

Usage in expressjs:

const tarkine = require("tarkine") // import
const express = require("express")
const app = express()


app.set("view engine", "html")
app.engine("html", tarkine.renderFile)

app.get("/", (req, res) => {
    res.render("index", {
        username: "tarkine"
    })
})

app.listen(3000)

Syntax

  • Comments
{{# This is a comment }}
  • Escaping
{{ variable }} // Escaped output
{{- variable }} // Unescaped output
{{= variable }} // Fully escaped output (including includes)
  • Conditionals
{{ if(condition) }}
  // content
{{ else if(otherCondition) }}
  // content
{{ else }}
  // content
{{/}}
  • Loops
{{ for(value, index in array) }}
  // content
{{/}}

{{ for(value, key in object) }}
  // content
{{/}}
  • Includes
{{ include("./partial", { data: "value" }) }}
  • Code Execution
{{~
  // JavaScript code here
}}
  • Attributes
<div>
    <button disabled="isLoggedIn">Login</button>
    <button disabled="isLoggedIn === true">Login</button>
</div>

Add Custom Registers

  • Global data can be registered and used across all templates:
const tarkine = require('tarkine')

tarkine.register({ 
  siteName: 'My Website'
})

Built-in Registers

Text Manipulation
  • Capitalizes the first letter of a string.
<p>{{ capitalize('hello world') }}</p> <!-- Output: "Hello world" -->
  • Converts a string to uppercase.
<p>{{ uppercase('hello') }}</p> <!-- Output: "HELLO" -->
  • Converts a string to lowercase.
<p>{{ lowercase('HELLO') }}</p> <!-- Output: "hello" -->
Random Values
  • Generates a random number between the given min and max values.
<p>Random number: {{ randomNum(1, 100) }}</p> <!-- Output: Random number between 1 and 100 -->
  • Generates a random alphanumeric string of a given length.
<p>Random string: {{ randomStr(10) }}</p> <!-- Output: Random string of 10 characters -->
  • Generates a random character from the alphabet.
<p>Random character: {{ randomChar() }}</p> <!-- Output: A random letter -->
Date and Time Formatting
  • Formats a date according to the provided format.
<p>Formatted date: {{ formatDate('2024-01-01', 'MM/DD/YYYY') }}</p> <!-- Output: "01/01/2024" -->
  • Formats a time to HH:mm:ss.
<p>Formatted time: {{ formatTime('2024-01-01T15:30:00') }}</p> <!-- Output: "15:30:00" -->
  • Displays the time elapsed since a given date (e.g., "2 days ago").
<p>{{ timeSince('2023-01-01T00:00:00Z') }}</p> <!-- Output: "X days ago" -->
Text Processing
  • Truncates a string to a specified length.
<p>{{ truncate('This is a long sentence that needs truncation', 20) }}</p> <!-- Output: "This is a long se..." -->
  • Converts a string into a URL-friendly slug.
<p>{{ slugify('Hello World! This is a test') }}</p> <!-- Output: "hello-world-this-is-a-test" -->
Currency Formatting
  • Formats a number as a currency (USD by default).
<p>{{ currency(1234.56) }}</p> <!-- Output: "$1,234.56" -->
  • Formats a number as a currency in a different locale and currency.
<p>{{ currency(1234.56, 'EUR', 'de-DE') }}</p> <!-- Output: "1.234,56 €" -->
Pluralization
  • Returns the singular or plural form based on the count.
<p>{{ pluralize(1, 'apple', 'apples') }}</p> <!-- Output: "apple" -->
<p>{{ pluralize(2, 'apple', 'apples') }}</p> <!-- Output: "apples" -->
File Size Formatting
  • Converts a number of bytes to a human-readable file size (KB, MB, GB, etc.).
<p>{{ formatBytes(1024) }}</p> <!-- Output: "1 KB" -->
Email Validation
  • Checks if an email address is valid.
<p>{{ isEmail('test@example.com') }}</p> <!-- Output: true -->

Keywords

FAQs

Package last updated on 01 Dec 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