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

@hubot-friends/hubot-templating

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@hubot-friends/hubot-templating

Javascript Server side templating engine with string literals

  • 1.0.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1
decreased by-50%
Maintainers
1
Weekly downloads
 
Created
Source

String Literal Templating Engine

Installation

npm i @hubot-friends/hubot-templating

Usage

import path from 'node:path'
import { fileURLToPath } from 'node:url'
import { Template } from '@hubot-friends/hubot-templating'

const __dirname = fileURLToPath(new URL('.', import.meta.url))
const WWW_FOLDER = `${path.resolve(__dirname, './www')}/`

// files like layout files to be leveraged in templates.
const partials = new Map()

// some functions to be used int the templates
const functions = {
    compare: (a, b)=> a == b,
    current: (a, b)=> a.endsWith(b) ? ' current' : '',
    difference: (posts, index)=> posts.length - index - 1,
    format: (date, format)=> date.toLocaleDateString(undefined, format),
    formatTime: (date, format)=> date.toLocaleTimeString(undefined, format),
    formatDate: (date, format)=> date.toLocaleDateString(undefined, format),
}

for await (let file of files){
    let data = await File.readFile(file, 'utf-8')
    let key = file.replace(`${WWW_FOLDER}/`, '').replace(/[\s|\-]/g, '_')
    if(key.indexOf('.html') > -1) {
        partials.set(key, data)
    }
}

const template = new Template('Some text with ${prop.content} in quotes', {prop: content = 'testing content'}, partials, functions)
const text = await template.render()

View index.test.mjs and test.html to see examples on how to create templates.

Keywords

FAQs

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