<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>

          bbo前端實(shí)用函數(shù)工具庫

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

          每個(gè)前端開發(fā)人都有自己的 utils 庫, 這些方法我們高頻使用,但又要在每個(gè)項(xiàng)目中重寫。 bbo 是一款超小且實(shí)用的函數(shù)工具庫,來源于日常開發(fā)總結(jié)。

          項(xiàng)目地址:github.com/tnfe/bbo

          文檔地址:https://tnfe.github.io/bbo/

          使用示例:

          // base case
          bbo.getCookie('username'); // => 'userName'
          bbo.cookie().getJson(); //  => {a: 1, b: 2}
          bbo.isiPhone(); // => true or false
          bbo.numberFormat(1234.56, 2, ',', ' '); // => '1 234,56';
          bbo.split([1, 2, 3, 4, 5], 2); // => [[1,2], [3,4], [5]]
          bbo.entries({ c: 8, a: 4 }); // => [['c', 8], ['a', 4]]
          bbo.toPath("a.b.c"); // => ['a', 'b', 'c']
          bbo.get({ a: { aa: { aaa: 2 } }, b: 4 }, "a.aa.aaa"); // => 2
          bbo.union([1, 2, 3], [4, 3, 2]); // => [1, 2, 3, 4]
          bbo.intersect([1, 2, 3], [4, 3, 2]); // => [2, 3]
          bbo.unionBy([2.1], [1.2, 2.3], Math.floor); // [2.1, 1.2]
          bbo.mapValues({ a: 3, b: 5, c: 9 }, (value) => value + 1); //=> {a: 4, b: 6, c: 10}
          bbo.compact([0, 1, false, 2, "", 3]); // [1, 2, 3]
          bbo.flush({a: 2, b: null, c: 4, d: undefined}); // => {a: 2, c: 4}
          bbo.differenceBy([2.1, 1.2], [2.3, 3.4], Math.floor); // => [1]
          bbo.search("3", { a: 3, b: 5, c: 7 }); // => 'a'
          bbo.size({ a: 1, b: 2 }); // => 2
          
          var users = [
            { user: "barney", age: 36, active: true },
            { user: "fred", age: 40, active: false },
          ];
          bbo.find(users, { age: 1, active: true }); // => {"active": true, "age": 36, "user": "barney"}
          bbo.findIndex(users, ["active", false]); // => 1
          
          // chain case
          var array1 = [1, 2, 3, null];
          var array2 = [3, 4, 5, ''];
          var object1 = { a: 6, b: 7 };
          var object2 = { c: 8, d: 9 };
          
          bbo
            .chain(object1)
            .extend(object2) // => {a: 6, b: 7, c: 8, d: 9}
            .entries() // =>  [["a", 6], ["b", 7], ["c", 8], ["d", 9]]
            .thru((words) => {
              const temp = [];
              bbo.forEach(words, (item, index) => {
                temp.push(item[1]);
              });
              return temp;
            }) // => [6, 7, 8, 9]
            .union(array1) // => [6, 7, 8, 9, 1, 2, 3, null]
            .union(array2) // => [6, 7, 8, 9, 1, 2, 3, null, 4, 5, ""]
            .compact() // => [6, 7, 8, 9, 1, 2, 3, 4, 5]
            .thru((array) => {
              return array.sort();
            }) // => [1, 2, 3, 4, 5, 6, 7, 8, 9]
            .value();
          // return  => [1, 2, 3, 4, 5, 6, 7, 8, 9]
          
          ... ∞

           

          瀏覽 23
          點(diǎn)贊
          評(píng)論
          收藏
          分享

          手機(jī)掃一掃分享

          編輯 分享
          舉報(bào)
          評(píng)論
          圖片
          表情
          推薦
          點(diǎn)贊
          評(píng)論
          收藏
          分享

          手機(jī)掃一掃分享

          編輯 分享
          舉報(bào)
          <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>
                  欧美日高清视频免费在线播放 | 成人αV| 国产美女91 呻吟求XX网站 | 黑人大几巴入口 | 美腿丝袜中文字幕精品 |