New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

@avanzu/template-renderer

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@avanzu/template-renderer

## Usage

latest
Source
npmnpm
Version
1.1.5
Version published
Weekly downloads
7
Maintainers
1
Weekly downloads
 
Created
Source

template-renderer

Usage

Simple setup to render markdown and cache the last 100 results for one hour.

const { Engine, RenderJob } = require('@avanzu/template-renderer')
// select your storage
const { LRUStorage } = require('@avanzu/template-renderer/storages')
// select your renderer
const { MarkdownRenderer } = require('@avanzu/template-renderer/renderers')

// setup the rendering engine
const engine = new Engine({
    renderer: new MarkdownRenderer(),
    storage: new LRUStorage({ maxEntries: 100, ttl: 3_600_000 }),
})

// render your template(s)
const output = await engine.render(RenderJob.markdown('***hello world***'))

Extend

Renderer

const { Renderer, RenderJob } = require('@avanzu/template-renderer')

exports.CustomRenderer = class CustomRenderer extends Renderer {
    supports(syntax) {
        return syntax.includes('custom-template')
    }

    /**
     *
     * @param {RenderJob} job
     * @returns {Promise<string>}
     */
    async render(job) {
        const { template, vars } = job
        // do your rendering, return the rendered string
    }
}

storage

const { Storage, CacheMiss } = require('@avanzu/template-renderer')

exports.CustomStorage = class CustomStorage extends Storage {
    constructor(options) {
        super(options)
    }

    async has(job) {
        const { hash } = job
        // test whether your storage does contain the job hash
    }

    async hydrate(job) {
        // fetch the stored contents
        job.update(contents)
        return job
    }

    async store(job) {
        const { hash, content } = job
        // store the contents using hash as key

        return job
    }
}

FAQs

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