1. <strong id="7actg"></strong>
    2. <table id="7actg"></table>

    3. <address id="7actg"></address>
      <address id="7actg"></address>
      1. <object id="7actg"><tt id="7actg"></tt></object>

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

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

        每個(gè)前端開(kāi)發(fā)人都有自己的 utils 庫(kù), 這些方法我們高頻使用,但又要在每個(gè)項(xiàng)目中重寫(xiě)。 bbo 是一款超小且實(shí)用的函數(shù)工具庫(kù),來(lái)源于日常開(kāi)發(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)
        1. <strong id="7actg"></strong>
        2. <table id="7actg"></table>

        3. <address id="7actg"></address>
          <address id="7actg"></address>
          1. <object id="7actg"><tt id="7actg"></tt></object>
            爱福利视频一区二区 | 色色综合色色 | 国产性爱在线 | 两人做性最刺激视频 | 亚洲第一夜 | 天天曰天天日天天干天天干天天射 | 午夜影院91 | wwwav| 亚洲激情视频在线 | 99热官方网站 |