0.0.9 • Published 6 years ago

string-infuse v0.0.9

Weekly downloads
4
License
MIT
Repository
github
Last release
6 years ago

String-infuse

1. Introduction

This light tool can infuse certain string template with given values by passing an object or just several individual values.

2. Get it

  • Browser: download this repository and include file dist/si.min.js.
  • Node: npm install --save string-infuse.

3. Use it

//------------------- Test Code -------------------//
var si = (typeof global === 'object') ? require('../index') : this.si;
var str = 'Append value: ${name|append(10)}\n' +
    'Repeat value : ${name|repeat(5)}\n' +
    'NickName in lowercase : ${nickName|toLowerCase}\n' +
    'Address in uppercase : ${address|toUpperCase};\n' +
    'object test : ${a.b};';
// json like value
var obj = {
    name: 'Jack',
    nickName: 'Jakie',
    address: 'Las Vegas',
    a: {
        b: "ababab"
    }
};
// add customize function - append
si.inFunction('append', function (x) { return '' + this + x });

//object mode
console.log('======= object mode (recommend) =======');
console.log(si.solve(str, obj));
//values mode
console.log('======= values mode =======');
console.log(si.solve(str, 'Ken', 'Ken', 'littleNickName', 'New York', { a: { b: "abcabc" } }));

The output will be

======= object mode (recommend) =======
Append value: Jack10
Repeat value : JackJackJackJackJack
NickName in lowercase : jakie
Address in uppercase : LAS VEGAS;
object test : ababab;
======= values mode =======
Append value: Ken10
Repeat value : KenKenKenKenKen
NickName in lowercase : littlenickname
Address in uppercase : NEW YORK;
object test : abcabc;

4. API

NameFunction
inFunctionadd customize function
unFunctionremove customize function
getFunctionreturn function with given name
solveinfuse given string with values

If you have any problem, please follow me @lucienlugeek on twitter.

0.0.9

6 years ago

0.0.8

6 years ago

0.0.7

6 years ago

0.0.6

6 years ago

0.0.5

6 years ago

0.0.4

6 years ago

0.0.3

6 years ago

0.0.2

6 years ago

0.0.1

6 years ago