@cristalnaya/chops
v1.0.0
Published
NPM package that will add a TypeScript method called chops
Downloads
4
Readme
Introduction
The chop
method is a TypeScript method that accepts two parameters: template
and dataset
. The method is designed to render template
, replacing {{x}}
with data[x]
, and return the resulting string.
Requirements
- The
dataset
parameter only accepts objects. - The
template
parameter must only accept strings. - Both parameters are mandatory. If the method
chop
is called but missing one of the parameters, and error with "template and dataset are mandatory parameters" is returned. - The
dataset
should only support & number values. If other types are provided, a useful error is given.
Usage
To use the chop
method, simply import it and provide the template
and dataset
parameters, then call the method:
import {chop} from '@cristalnaya/chops/src/chop';
const dataset = {
bread: 'baguette',
cheese: 'brie cheese',
}
const template = 'I like to eat {{bread}} and {{cheese}}';
chop(template, dataset);
Testing
The method chop
has been tested using Jest. To run the tests, simply run the following command in your terminal:
npm run test
Tools used
- TypeScript
- Jest
- ts-jest
- prettier
- @types/jest
- @types/node
- eslint
- GitHub Actions