<kbd id="afajh"><form id="afajh"></form></kbd>
<strong id="afajh"><dl id="afajh"></dl></strong>
    <del id="afajh"><form id="afajh"></form></del>
        1. <th id="afajh"><progress id="afajh"></progress></th>
          <b id="afajh"><abbr id="afajh"></abbr></b>
          <th id="afajh"><progress id="afajh"></progress></th>

          Fasty極快 JavaScript 模板引擎

          聯(lián)合創(chuàng)作 · 2023-09-23 02:58

          Fasty 是一個極快的 JavaScript 模板引擎。

          Fasty 是一個簡約、超快的 JavaScript 模板引擎, 它使用了非常獨特的緩存技術,從而獲得接近 JavaScript 極限的運行性能,并且同時支持 NodeJS 和瀏覽器。

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

          Fasty 特點

          • 1、極高性能:Fasty 會直接把模板內容編譯成 JavaScript 源碼執(zhí)行,而不是使用正則替換,因此,F(xiàn)asty 的渲染性能超過很多其他模板引擎 100 倍或以上。
          • 2、極度簡單:Fasty 只內置了輸出指令 {{ }} 和 邏輯指令 {{~ }}
          • 3、非常靈活:Fasty 直接與 JavaScript 打通,比如當我們引用 JQuery 之后,可以直接這樣使用 {{ $("#id").text() }}

          使用方法

          示例 1

          var template = '<div> hello {{ name }} </div>'
          var data = {name: "fasty"}
          
          var fasty = new Fasty();
          var result = fasty.render(template,data);
          // result: <div> hello fasty </div>
           

          示例 2

          var template = ' {{attr}} hello {{ func1(name) }} ---'
          var data = {name: "fasty"}
          
          var fasty = new Fasty({
              //共享的模板數(shù)據(jù) 或者 方法
              share : {
                  attr:'text...',
                  func1:function (v){
                      return v + " kiss~~"
                  },
              }
          });
          
          var result = fasty.render(template,data);
          // result: text... hello fasty kiss~~
           

          Fasty 語法

          輸出

          // #1 變量
          {{~ var x = 100}}
          {{x}}
          //輸出: 100
          
          
          // #2 字符串
          {{"hello world"}}
          //輸出:hello world
          
          
          // #3 安全輸出,對 html 進行 escape
          {{# "<div> hello world </div>"}}
          //輸出:&lt;div&gt; hello world &lt;/div&gt;
          
          
          // #4 強制轉換 html 輸出
          {{! "&lt;div&gt; hello world &lt;/div&gt;"}}
          //輸出:<div> hello world </div>
           

          變量定義

          #1
          {{~ var a =100}}
          
          #2
          {{~ var a =100,b = 200,c=300}}
          
          #3
          #{{~ let a =100}}
          
          #4
          #{{~ let a =100,b=200,c=300}}
          
          #4
          #{{~ const a =100}}
          
          #5
          #{{~ const a =100,b=200,c=300}}
           

          if-else

          {{~ if (x == 100) }}
          
          {{~ elseif(x == 200) }}
          
          {{~ else if(x == 300) }}
          
          {{~ else }}
          
          {{~ end }}
           

          同時支持 'elseif' or 'else if'

          for 循環(huán)

          // #1
          {{~ for (item of array) }}
          
          {{~end}}
          
          // #2
          {{~ for (item in array) }}
          
          {{~end}}
          
          // #3
          {{~ for (let item of array) }}
          
          {{~end}}
          
          // #4
          {{~ for (const item in array) }}
          
          {{~end}}
          
          // #5
          {{~ for (key of Object.keys(item) )}}
          
          {{~end}}
          
          // #6
          {{~ for (var x = i;x < 100;x++) }}
          
          {{~ end }}
          
          // #7
          {{~ for (item of someMethodInvoke().other()) }}
          
          {{~end}}
          
          // #8
          {{~ for (var x = i;x < someMethodInvoke().other();x++) }}
          
          {{~ end }}
           

          安全訪問

          #1
          {{a?.b?.c}}
          
          #2
          {{a.bbbb?().ccc?.ddd}}
           

          初始化配置

          var options = {
              //共享模板方法和數(shù)據(jù)
              share : {
                  attr:'text...',
                  func1:function (v){
                      return v + " kiss~~"
                  },
              },
              // 是否是共享數(shù)據(jù)優(yōu)先
              // 默認 false,即: render 方法傳入的 data 數(shù)據(jù)優(yōu)先
              shareDataFirst: false, //default is false
              
              //是否開啟安全訪問,這個功能不支持 IE 瀏覽器
              //IE 下需要設置為 false,同時配置 false 后會得到更高的運行性能
              safelyAccess: true,
          
              //自定義 html 安全輸出方法
              //當使用 {{# ... }} 的時候使用該方法轉換
              $escape:function (html){return html},
          
              //自定義 unescape 方法
              //當使用 {{! ... }} 的時候使用該方法轉換
              $unescape:function (value){return value}
          }
          
          var fasty = new Fasty(options);
          fast.render(template,data)
           

          作者

          License

          Fasty is licensed under the MIT License.

          開源地址

          https://gitee.com/fuhai/fasty

          瀏覽 34
          點贊
          評論
          收藏
          分享

          手機掃一掃分享

          編輯 分享
          舉報
          評論
          圖片
          表情
          推薦
          點贊
          評論
          收藏
          分享

          手機掃一掃分享

          編輯 分享
          舉報
          <kbd id="afajh"><form id="afajh"></form></kbd>
          <strong id="afajh"><dl id="afajh"></dl></strong>
            <del id="afajh"><form id="afajh"></form></del>
                1. <th id="afajh"><progress id="afajh"></progress></th>
                  <b id="afajh"><abbr id="afajh"></abbr></b>
                  <th id="afajh"><progress id="afajh"></progress></th>
                  超碰免费网站 | 性爱av免费在线观看 | 丁香婷婷五月天av | 超碰免费97 | 青娱乐精品视觉盛宴 |