Fasty 极快 JavaScript 模板引擎开源项目

我要开发同款
匿名用户2022年05月26日
49阅读
开发技术JavaScript
所属分类Web应用开发、浏览器/JS引擎
授权协议MIT

作品详情

Fasty是一个极快的JavaScript模板引擎。

Fasty是一个简约、超快的JavaScript模板引擎,它使用了非常独特的缓存技术,从而获得接近JavaScript极限的运行性能,并且同时支持NodeJS和浏览器。

Fasty的渲染速度,超过很多市面上的JavaScript引擎100倍以上。

Fasty特点1、极高性能:Fasty会直接把模板内容编译成JavaScript源码执行,而不是使用正则替换,因此,Fasty的渲染性能超过很多其他模板引擎100倍或以上。2、极度简单:Fasty只内置了输出指令 {{}} 和逻辑指令 {{~}}3、非常灵活:Fasty直接与JavaScript打通,比如当我们引用JQuery之后,可以直接这样使用 {{$("#id").text()}}使用方法示例1

vartemplate='<div>hello{{name}}</div>'vardata={name:"fasty"}varfasty=newFasty();varresult=fasty.render(template,data);//result:<div>hellofasty</div> 示例2

vartemplate='{{attr}}hello{{func1(name)}}---'vardata={name:"fasty"}varfasty=newFasty({//共享的模板数据或者方法share:{attr:'text...',func1:function(v){returnv+"kiss~~"},}});varresult=fasty.render(template,data);//result:text...hellofastykiss~~ Fasty语法输出//#1变量{{~varx=100}}{{x}}//输出:100//#2字符串{{"helloworld"}}//输出:helloworld//#3安全输出,对html进行escape{{#"<div>helloworld</div>"}}//输出:&lt;div&gt;helloworld&lt;/div&gt;//#4强制转换html输出{{!"&lt;div&gt;helloworld&lt;/div&gt;"}}//输出:<div>helloworld</div> 变量定义#1{{~vara=100}}#2{{~vara=100,b=200,c=300}}#3#{{~leta=100}}#4#{{~leta=100,b=200,c=300}}#4#{{~consta=100}}#5#{{~consta=100,b=200,c=300}} if-else{{~if(x==100)}}{{~elseif(x==200)}}{{~elseif(x==300)}}{{~else}}{{~end}} 同时支持'elseif'or'elseif'

for循环//#1{{~for(itemofarray)}}{{~end}}//#2{{~for(iteminarray)}}{{~end}}//#3{{~for(letitemofarray)}}{{~end}}//#4{{~for(constiteminarray)}}{{~end}}//#5{{~for(keyofObject.keys(item))}}{{~end}}//#6{{~for(varx=i;x<100;x++)}}{{~end}}//#7{{~for(itemofsomeMethodInvoke().other())}}{{~end}}//#8{{~for(varx=i;x<someMethodInvoke().other();x++)}}{{~end}} 安全访问#1{{a?.b?.c}}#2{{a.bbbb?().ccc?.ddd}} 初始化配置varoptions={//共享模板方法和数据share:{attr:'text...',func1:function(v){returnv+"kiss~~"},},//是否是共享数据优先//默认false,即:render方法传入的data数据优先shareDataFirst:false,//defaultisfalse//是否开启安全访问,这个功能不支持IE浏览器//IE下需要设置为false,同时配置false后会得到更高的运行性能safelyAccess:true,//自定义html安全输出方法//当使用{{#...}}的时候使用该方法转换$escape:function(html){returnhtml},//自定义unescape方法//当使用{{!...}}的时候使用该方法转换$unescape:function(value){returnvalue}}varfasty=newFasty(options);fast.render(template,data) 作者Micahel(fuhai999@gmail.com)-小码科技Wechat:wx198819880LicenseFastyislicensedundertheMITLicense.

开源地址https://gitee.com/fuhai/fasty

查看全文
声明:本文仅代表作者观点,不代表本站立场。如果侵犯到您的合法权益,请联系我们删除侵权资源!如果遇到资源链接失效,请您通过评论或工单的方式通知管理员。未经允许,不得转载,本站所有资源文章禁止商业使用运营!
下载安装【程序员客栈】APP
实时对接需求、及时收发消息、丰富的开放项目需求、随时随地查看项目状态

评论