Options
All
  • Public
  • Public/Protected
  • All
Menu

Module dobby-templater-core

dobby - templater-core

Known Vulnerabilities CICD codecov

The core templating package. It's purpose is simple: bind valid models into templates.

Usage

Method: bind(template: string, model: object, schema? object) => string

A template string is required, using Moustache templating syntax.

A model is a simple object that has properties you want to bind into the template.

The optional schema is a JSON Schema definition that can be used to validate your model. Validation is skipped if no schema is provided. Schemas require the $id property as these are used for internal compilation and reuse of schema validators.

import { bind } from "templater-core";

const template =`Hello {{name}}!`;

const model = { name:`bob` };

const schema = {
    $id: `http://example.com/person.json`,
    type: `object`,
    properties: {
        name: { $ref: `defs.json#/definitions/str` },
    }
};

const stringResult = bind(template, model, schema);
console.log(stringResult);
// "Hello bob!"

Index

Classes

Type aliases

Variables

Functions

Type aliases

TemplateSchema

TemplateSchema: object

Type declaration

  • $id: string

    The unique identifier of the schema as per JSON Schema draft 7

Variables

Const ajv

ajv: Ajv = new AJV({ allErrors: true })

Functions

assertValidModel

bind

  • bind(template: string, model: object, schema?: TemplateSchema): string

Generated using TypeDoc