https://github.com/ehanlin/coffee-replace
replace string like coffeescript's string interpolation
https://github.com/ehanlin/coffee-replace
Last synced: 8 months ago
JSON representation
replace string like coffeescript's string interpolation
- Host: GitHub
- URL: https://github.com/ehanlin/coffee-replace
- Owner: eHanlin
- License: mit
- Created: 2014-08-29T03:32:20.000Z (almost 12 years ago)
- Default Branch: master
- Last Pushed: 2017-08-02T08:13:28.000Z (almost 9 years ago)
- Last Synced: 2025-10-01T03:36:35.878Z (9 months ago)
- Language: CoffeeScript
- Size: 2.93 KB
- Stars: 0
- Watchers: 11
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# Coffee Replace
```javascript
// 使用範例
var str = "我是#{name},我的年紀#{age(歲)}。你可以叫我#{name}。#{#{up(a)}#{bc}}測試";
var data = {
name : "熱狗",
age : function(ageUnit){return 33+ageUnit;},
up : function(str){return str.toUpperCase();},
bc : function(){return "BC";},
ABC : "甲乙丙",
abc : "123"};
str.coffeeReplace(data);
// 執行過程
//我是#{name},我的年級#{age(歲)}。你可以叫我#{name}。#{#{up(a)}#{bc}}測試
//我是熱狗,我的年級#{age(歲)}。你可以叫我熱狗。#{#{up(a)}#{bc}}測試
//我是熱狗,我的年級33歲。你可以叫我熱狗。#{#{up(a)}#{bc}}測試
//我是熱狗,我的年級33歲。你可以叫我熱狗。#{A#{bc}}測試
//我是熱狗,我的年級33歲。你可以叫我熱狗。#{ABC}測試
//我是熱狗,我的年級33歲。你可以叫我熱狗。甲乙丙測試
// example
var str = "I am #{name},#{age( old)}. you can call me #{name}.#{#{up(a)}#{bc}} test";
var data = {
name : "hotdog",
age : function(ageUnit){return 33+ageUnit;},
up : function(str){return str.toUpperCase();},
bc : function(){return "BC";},
ABC : "I II III",
abc : "123"};
str.coffeeReplace(data);
//process
//I am #{name},#{age( old)}. you can call me #{name}.#{#{up(a)}#{bc}} test
//I am hotdog,#{age( old)}. you can call me hotdog.#{#{up(a)}#{bc}} test
//I am hotdog,33 old. you can call me hotdog.#{#{up(a)}#{bc}} test
//I am hotdog,33 old. you can call me hotdog.#{A#{bc}} test
//I am hotdog,33 old. you can call me hotdog.#{ABC} test
//I am hotdog,33 old. you can call me hotdog.I II III test
```