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' ? : thissi;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 valuevar obj =name: 'Jack'nickName: 'Jakie'address: 'Las Vegas'a:b: "ababab";// add customize function - appendsi;//object modeconsole;console;//values modeconsole;console;
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
Name | Function |
---|---|
inFunction | add customize function |
unFunction | remove customize function |
getFunction | return function with given name |
solve | infuse given string with values |
If you have any problem, please follow me @lucienlugeek on twitter.