• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript underscore.mapObject函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了TypeScript中underscore.mapObject函数的典型用法代码示例。如果您正苦于以下问题:TypeScript mapObject函数的具体用法?TypeScript mapObject怎么用?TypeScript mapObject使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了mapObject函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。

示例1: newCertsToLinks

 newCertsToLinks(newCerts:any, updates:any) {
   let newLinks:any = {};
   _.mapObject(newCerts, function(certs:any, pubkey:string) {
     newLinks[pubkey] = _.pluck(certs, 'from');
   });
   _.mapObject(updates, function(certs:any, pubkey:string) {
     newLinks[pubkey] = (newLinks[pubkey] || []).concat(_.pluck(certs, 'pubkey'));
   });
   return newLinks;
 }
开发者ID:Kalmac,项目名称:duniter,代码行数:10,代码来源:blockGenerator.ts


示例2: function

 static respondToResourceGET<T>(requestBody, res, dao: DAO<T>, whereArray: string[], likeArray: string[]) {
     let whereQuery = _.omit(_.pick(requestBody, whereArray),
         function (value, key, object) {
             return value === "";
         });
     let likeQuery_ = _.chain(requestBody)
         .pick(requestBody, likeArray)
         .omit(function (value, key, object) {
             return value === "";
         }).value();
     let likeQuery = _.mapObject(likeQuery_, function (value, key) {
         return "%" + value + "%";
     });
     dao.find({
         where: whereQuery, like: likeQuery, orderBy: requestBody.orderBy
     }, function (err, results) {
         if (err) {
             APIHelper.sendDatabaseErrorResponse(res, err);
         } else {
             if (results.length === 0) {
                 APIHelper.sendNotFoundResponse(res, "Not found.");
             } else {
                 APIHelper.sendResponse(res, results);
             }
         }
     });
 }
开发者ID:JohanBaskovec,项目名称:libraryBackEnd,代码行数:27,代码来源:apiHelper.ts


示例3: computeNewCerts

 async computeNewCerts(forBlock:number, theNewcomers:any, joinData:any) {
   const newCerts:any = {}, certifiers = [];
   const certsByKey = _.mapObject(joinData, function(val:any){ return val.certs; });
   for (const newcomer of theNewcomers) {
     // New array of certifiers
     newCerts[newcomer] = newCerts[newcomer] || [];
     // Check wether each certification of the block is from valid newcomer/member
     for (const cert of certsByKey[newcomer]) {
       const isAlreadyCertifying = certifiers.indexOf(cert.from) !== -1;
       if (!(isAlreadyCertifying && forBlock > 0)) {
         if (~theNewcomers.indexOf(cert.from)) {
           // Newcomer to newcomer => valid link
           newCerts[newcomer].push(cert);
           certifiers.push(cert.from);
         } else {
           let isMember = await this.dal.isMember(cert.from)
           // Member to newcomer => valid link
           if (isMember) {
             newCerts[newcomer].push(cert);
             certifiers.push(cert.from);
           }
         }
       }
     }
   }
   return newCerts;
 }
开发者ID:Kalmac,项目名称:duniter,代码行数:27,代码来源:blockGenerator.ts


示例4: searchLoadout

export function searchLoadout(storeService: StoreServiceType, store: DimStore): Loadout {
  let items = storeService.getAllItems().filter((i) => {
    return i.visible &&
      !i.location.inPostmaster &&
      !i.notransfer;
  });

  items = addUpStackables(items);

  const itemsByType = _.mapObject(_.groupBy(items, 'type'), (items) => limitToBucketSize(items, store.isVault));

  // Copy the items and mark them equipped and put them in arrays, so they look like a loadout
  const finalItems = {};
  _.each(itemsByType, (items, type) => {
    if (items) {
      finalItems[type.toLowerCase()] = items.map((i) => {
        const copiedItem = copy(i);
        copiedItem.equipped = false;
        return copiedItem;
      });
    }
  });

  return {
    classType: -1,
    name: t('Loadouts.FilteredItems'),
    items: finalItems
  };
}
开发者ID:delphiactual,项目名称:DIM,代码行数:29,代码来源:auto-loadouts.ts


示例5: optimalLoadout

export function optimalLoadout(applicableItems: DimItem[], bestItemFn: (item: DimItem) => number, name: string): Loadout {
  const itemsByType = _.groupBy(applicableItems, 'type');

  // Pick the best item
  let items = _.mapObject(itemsByType, (items) => _.max(items, bestItemFn));

  // Solve for the case where our optimizer decided to equip two exotics
  const getLabel = (i) => i.equippingLabel;
  // All items that share an equipping label, grouped by label
  const overlaps: _.Dictionary<DimItem[]> = _.groupBy(Object.values(items).filter(getLabel), getLabel);
  _.each(overlaps, (overlappingItems) => {
    if (overlappingItems.length <= 1) {
      return;
    }

    const options: _.Dictionary<DimItem>[] = [];
    // For each item, replace all the others overlapping it with the next best thing
    for (const item of overlappingItems) {
      const option = copy(items);
      const otherItems = overlappingItems.filter((i) => i !== item);
      let optionValid = true;

      for (const otherItem of otherItems) {
        // Note: we could look for items that just don't have the *same* equippingLabel but
        // that may fail if there are ever mutual-exclusion items beyond exotics.
        const nonExotics = itemsByType[otherItem.type].filter((i) => !i.equippingLabel);
        if (nonExotics.length) {
          option[otherItem.type] = _.max(nonExotics, bestItemFn);
        } else {
          // this option isn't usable because we couldn't swap this exotic for any non-exotic
          optionValid = false;
        }
      }

      if (optionValid) {
        options.push(option);
      }
    }

    // Pick the option where the optimizer function adds up to the biggest number, again favoring equipped stuff
    if (options.length > 0) {
      const bestOption = _.max(options, (opt) => sum(Object.values(opt), bestItemFn));
      items = bestOption;
    }
  });

  // Copy the items and mark them equipped and put them in arrays, so they look like a loadout
  const finalItems: { [type: string]: DimItem[] } = {};
  _.each(items, (item, type) => {
    const itemCopy = copy(item);
    itemCopy.equipped = true;
    finalItems[type.toLowerCase()] = [itemCopy];
  });

  return {
    classType: -1,
    name,
    items: finalItems
  };
}
开发者ID:delphiactual,项目名称:DIM,代码行数:60,代码来源:loadout-utils.ts


示例6: filterLoadoutToEquipped

 function filterLoadoutToEquipped(loadout: Loadout) {
   const filteredLoadout = copy(loadout);
   filteredLoadout.items = _.mapObject(filteredLoadout.items, (items) => {
     return items.filter((i) => i.equipped);
   });
   return filteredLoadout;
 }
开发者ID:bhollis,项目名称:DIM,代码行数:7,代码来源:loadout-builder.component.ts


示例7: parseExpressionToType

        function parseExpressionToType(expression: AST.ExpressionType) : types.Type {
            if (expression.type === 'expressionarrayLiteral') {
                return types.createArrayType(expression.value.map(val => parseExpressionToType(val)));
            }
            else if (expression.type === 'expressionmapLiteral') {
                return types.createMapType(_.mapObject(expression.value, v => {
                    return parseExpressionToType(v);
                }));
            }
            else if (expression.type === 'expressionidentifier') {
                return types.createReferenceType(expression.value);
            }

            console.error("Couldn't parse dat type boi");
            return types.getAnyType();
        }
开发者ID:shnud94,项目名称:livelang,代码行数:16,代码来源:javascriptStyle.ts


示例8: gatherEngramsLoadout

export function gatherEngramsLoadout(
  storeService: StoreServiceType,
  options: { exotics: boolean } = { exotics: false }
): Loadout {
  const engrams = storeService.getAllItems().filter((i) => {
    return i.isEngram() && !i.location.inPostmaster && (options.exotics ? true : !i.isExotic);
  });

  if (engrams.length === 0) {
    let engramWarning = t('Loadouts.NoEngrams');
    if (options.exotics) {
      engramWarning = t('Loadouts.NoExotics');
    }
    throw new Error(engramWarning);
  }

  const itemsByType = _.mapObject(_.groupBy(engrams, 'type'), (items) => {
    // Sort exotic engrams to the end so they don't crowd out other types
    items = _.sortBy(items, (i) => {
      return i.isExotic ? 1 : 0;
    });
    // No more than 9 engrams of a type
    return _.first(items, 9);
  });

  // Copy the items and mark them equipped and put them in arrays, so they look like a loadout
  const finalItems = {};
  _.each(itemsByType, (items, type) => {
    if (items) {
      finalItems[type.toLowerCase()] = items.map((i) => {
        return copy(i);
      });
    }
  });

  return {
    classType: -1,
    name: t('Loadouts.GatherEngrams'),
    items: finalItems
  };
}
开发者ID:delphiactual,项目名称:DIM,代码行数:41,代码来源:auto-loadouts.ts


示例9: booksGET

function booksGET(req: Request, res: Response) {

    let wrongKeys = _.omit(req.query, ["title", "author",
        "isbn", "pages", "editorid", "year", "orderBy"]);
    if (_.keys(wrongKeys).length > 0) {
        APIHelper.sendInvalidArgumentsResponse(res, _.keys(wrongKeys));
    }
    let constraints = {
        title: {
            presence: false,
        },
        isbn: {
            presence: false
        },
        author: {
            presence: false
        },
        pages: {
            presence: false,
            numericality: {
                onlyInteger: true,
                greaterThan: 0,
            }
        },
        year: {
            presence: false,
            numericality: {
                onlyInteger: true,
            }
        },
        editorid: {
            presence: false,
            numericality: {
                onlyInteger: true,
            }
        }
    };

    let requestValid = APIHelper.validateSearchRequest(res, req.query, constraints);
    console.log("WTF");
    if (requestValid) {
        let whereQuery = _.omit(_.pick(req.query, "pages", "year", "editorid"),
            function (value, key, object) {
                return value === "";
            });
        let likeQuery_ = _.chain(req.query)
            .pick(req.query, "title", "isbn", "author")
            .omit(function (value, key, object) {
                return value === "";
            }).value();
        let likeQuery = _.mapObject(likeQuery_, function (value, key) {
            return "%" + value + "%";
        });

        console.log(req.query.orderBy);
        Book.dao.find({
            where: whereQuery, like: likeQuery, orderBy: req.query.orderBy
        }, function (err, books) {
            if (err) {
                APIHelper.sendDatabaseErrorResponse(res, err);
            } else {
                let asyncToDo = books.length;
                if (asyncToDo === 0) {
                    APIHelper.sendNotFoundResponse(res, "No books found.");
                } else {
                    _.each(books, function (value, index, list) {
                        Editor.dao.find({where: {id: list[index].editorid}}, function (err, editors) {
                            list[index].editor = editors[0];
                            asyncToDo--;
                            if (asyncToDo === 0) {
                                asyncToDo--;
                                APIHelper.sendResponse(res, books);

                            }
                        });
                    });
                }

            }
        });
    }
}
开发者ID:JohanBaskovec,项目名称:libraryBackEnd,代码行数:82,代码来源:bookController.ts


示例10: bookSearchGET

function bookSearchGET(req: Request, res: Response, next: NextFunction) {
    if (Object.keys(req.query).length === 0 && req.baseUrl !== "/api") {
        res.render("book/search", {data: {}});
    }
    else {
        let constraints = {
            title: {
                presence: false,
            },
            isbn: {
                presence: false
            },
            author: {
                presence: false
            },
            pages: {
                presence: false,
                numericality: {
                    onlyInteger: true,
                    greaterThan: 0,
                }
            },
            year: {
                presence: false,
                numericality: {
                    onlyInteger: true,
                }
            },
            editorid: {
                presence: false,
                numericality: {
                    onlyInteger: true,
                }
            }
        };
        let book: Book = new Book();

        let validation = validate(req.query, constraints);
        let data = {
            errors: {global: ""},
            info: {confirmation: ""},
            books: [],
            book: {}
        };
        let wrongInputs = 0;
        for (let prop in validation) {
            if (!validation.hasOwnProperty(prop)) {
                continue;
            }
            data.errors[prop] = validation[prop];
            delete req.query[prop];
            wrongInputs++;
        }
        for (let prop in req.query) {
            if (!req.query.hasOwnProperty(prop)) {
                continue;
            }
            book[prop] = req.query[prop];
        }


        if (wrongInputs === 0) {
            let whereQuery = _.omit(_.pick(req.query, "pages", "year", "editorid"),
                function (value, key, object) {
                    return value === "";
                });
            let likeQuery_ = _.chain(req.query)
                .pick(req.query, "title", "isbn", "author")
                .omit(function (value, key, object) {
                    return value === "";
                }).value();
            let likeQuery = _.mapObject(likeQuery_, function (value, key) {
                return "%" + value + "%";
            });

            console.log("Like query=");
            console.log(likeQuery);
            Book.dao.find({
                where: whereQuery, like: likeQuery
            }, function (err, books) {
                if (err) {
                    data.errors.global = err.code;
                } else {
                    data.books = books;
                    let asyncToDo = data.books.length;

                    _.each(data.books, function (value, index, list) {
                        Editor.dao.find({where: {id: list[index].editorid}}, function (err, editors) {
                            list[index].editor = editors[0];
                            asyncToDo--;
                            if (asyncToDo === 0) {
                                data.info.confirmation = books.length + " books found.";

                                data.book = req.query;

                                if (req.baseUrl === "/api") {
                                    res.json(data);
                                    return;
                                }
                                if (req.xhr) {
//.........这里部分代码省略.........
开发者ID:JohanBaskovec,项目名称:nodejslibrary,代码行数:101,代码来源:bookController.ts



注:本文中的underscore.mapObject函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript underscore.max函数代码示例发布时间:2022-05-25
下一篇:
TypeScript underscore.map函数代码示例发布时间:2022-05-25
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap