1.0.0 • Published 3 years ago
@cristalnaya/chops v1.0.0
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
datasetparameter only accepts objects. - The
templateparameter must only accept strings. - Both parameters are mandatory. If the method
chopis called but missing one of the parameters, and error with "template and dataset are mandatory parameters" is returned. - The
datasetshould 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 testTools used
- TypeScript
- Jest
- ts-jest
- prettier
- @types/jest
- @types/node
- eslint
- GitHub Actions
1.0.0
3 years ago