1.1.2 • Published 6 years ago

kisphp-format-string v1.1.2

Weekly downloads
-
License
MIT
Repository
gitlab
Last release
6 years ago

Javascript Format String

pipeline status

This repository started as a need to replace text in javascript in tiny templates without a framework.

Installation

npm install --save kisphp-format-string

Integrate script

require('kisphp-format-string');

Or simply include the js file in your browser

<script async src="node_modules/kisphp-format-string/src/format-string.js"></script>

Usage

var data = {
    name: "John Doe",
    info: "Software Engineer"
};

var template_1 = '<div><h3>{name}</h3><h5>{info}</h5></div>';
var template_2 = '<div><h3>{0}</h3><h5>{1}</h5></div>';

// use with object 
console.log(template_1.formatString(data));

// use with direct elements
console.log(template_2.formatString(data.name, data.info));

// use with array
console.log(template_2.formatString([
    data.name, 
    data.info
]));
1.1.2

6 years ago

1.1.1

7 years ago

1.1.0

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago