1.0.1 • Published 2 years ago

chop-template v1.0.1

Weekly downloads
-
License
ISC
Repository
github
Last release
2 years ago

Chop

Template parsing lib

• The parameter "data" accepts object
• The parameter "template" only accepts string
• Both parameters are mandatory, if the package chop is called but missing one of the parameters, it returns an error with "template and dataset are mandatory parameters"
• By calling the "chop" package it "render" the template, replacing {{x}} with data[x], and returns the resulting string.
• The dataset only supports string & number values, and gives a useful error when we try to replace other types.
// Example:
import { chop } from “./chop.ts”;
const dataset = {
    bread: {
        white: “white bread”,
        grain: “whole grain bread”,
        rye: “rye bread”,
    }
    cheese: “brie cheese”,
}
const myTemplate = “I like to eat {{bread.white}} and {{cheese}}”;
chop(myTemplate, dataset); // >> ‘I like to eat white bread and brie cheese’

Project setup

npm install

Compile typescript to dist folder

npm run build
npm run build:watch

Run tests

npm run test
npm run test:watch

Run lint check

npm run lint

To see the code test coverage run the following command and browse:

npm run view:coverage
http://localhost:3000

image