1.1.7 • Published 3 years ago

protypa v1.1.7

Weekly downloads
1
License
ISC
Repository
github
Last release
3 years ago

prótypa

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.

Getting Started

Instalation

npm i --save protypa

Basic Usage

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 ...

Example - write()

const protypa = require('protypa');

let str = "Hello, {{name}}!"

let result = protypa.write(str, {name: "Jack"});

console.log(result);

output

Hello, Jack!

Example - extract()

  • 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":""}

Contribution Guide

  • Working on it!

Authors

1.1.7

3 years ago

1.1.6

3 years ago

1.1.5

3 years ago

1.1.4

3 years ago

1.1.3

4 years ago

1.1.2

4 years ago

1.1.1

4 years ago

1.1.0

4 years ago

1.0.7

4 years ago

1.0.6

4 years ago

1.0.2

4 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago