A simple text templating engine ( string interpolation ). It reads strings and looks for expressions embedded in curly braces and replaces the expression with a value stored in a variable.
Instalation
npm i --save protypa
const protypa = require('protypa')
let doc = "... Hello, {{name}}, you have subscribed to our {{planName}} plan ..."
let extracted = protypa.extract(doc);
extracted.name = "Jack"
extracted.planName = "VIP"
let result = protypa.write(doc, extracted);
console.log(result)
output: ... Hello, Jack, you have subscribed to our VIP plan ...
const protypa = require('protypa');
let str = "Hello, {{name}}!"
let result = protypa.write(str, {name: "Jack"});
console.log(result);
output
Hello, Jack!
- Extracting single variable.
const protypa = require('protypa');
let str = "Hello, {{name}}!";
let result = protypa.extract(str);
console.log(JSON.stringify(result));
output : {"name":""}
- Extracting multiple variables.
const protypa = require('protypa');
let str = "Hello, {{name}}!. you are a {{gender}}";
let result = app.extract(str);
console.log(JSON.stringify(result));
output : {"name":"", "gender":""}
- Working on it!
- Muhammad Noman - e4coder