Socket
Book a DemoInstallSign in
Socket

@blureffect/bigot

Package Overview
Dependencies
Maintainers
2
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@blureffect/bigot

--- Inspired by Mustache, this template engine seeks to add support for asynchronous operations in a simple way within context, functions, and decorators.

latest
Source
npmnpm
Version
0.1.2
Version published
Maintainers
2
Created
Source

Bigot

template engine inspired by mustache

Inspired by Mustache, this template engine seeks to add support for asynchronous operations in a simple way within context, functions, and decorators.

Usage

context

import { Bigot } from "@blureffect/bigot";

const bigot = new Bigot();

const result = await bigot.compile('context', '{{ data.user.id }}', { data: { user: { id: 1 } } });
const result = await bigot.compile('context', '{{ data.user.id }}', { data: { user: { id: () => 1 } } });
const result = await bigot.compile('context', '{{ data.user.id }}', { data: { user: { id: async (ctx) => 1 } } });
const result = await bigot.compile('context', '{{ data.user.id }}', { data: { user: async (ctx) => ({ id: 1 }) } });

functions

import { Bigot } from "@blureffect/bigot";

const bigot = new Bigot();

bigot.registerFunctions('now', () => new Date().toISOString());
bigot.registerFunctions('sum', (arg1: number, arg2: number) => arg1 + arg2);

const result = await bigot.compile('function_now', '{{#now}}', {});
const result = await bigot.compile('function_sum', '{{#sum 1 arg2}}', { arg2: 2 });

decorators

import { Bigot } from "@blureffect/bigot";

const bigot = new Bigot();

bigot.registerDecorator('for', async (list: number[], { render }: { render: Function }) => {
    return Promise.all(list.map(async (item, i) => render({ index: i, value: item }))).then((items) => {
        return items.join('')
    })
});

const result = await bigot.compile('list', getTemplate('list'), { list: ['a', 'b', 'c'] });

template/list

list
{{@for list}}
{{index}}: {{value}}
{{@end}}

The compile function receives a key, the template and the context. The key will be used to store the template once it has been analyzed and to make it faster in its next execution.

License

MIT

FAQs

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