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

TypeScript lodash类代码示例

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

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



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

示例1: remove

  /**
   * Removes resource from items and all indexes
   */
  public remove(identity?: any): Promise<void> {
    const index: { [key: string]: any[] }
      = JSON.parse(localStorage.getItem(`resource.${this.collectionName}.index`) || '{}');
    const items: T[]
      = JSON.parse(localStorage.getItem(`resource.${this.collectionName}.items`) || '[]');

    // remove from items
    _(items)
      .remove(item => !identity || (item[this.identityAttr] && item[this.identityAttr] === identity) || item.$id === identity)
      .commit();

    // remove from all indexes
    _(index).each((identities: any[]) => {
      _(identities)
        .remove(id => !identity || identity === id)
        .commit();
    });

    // remove all empty indexes
    _(index)
      .keys()
      .forEach(key => {
        if (key === '/' || index[key].length) { return; }
        delete index[key];
      });

    localStorage.setItem(`resource.${this.collectionName}.items`, JSON.stringify(items));
    localStorage.setItem(`resource.${this.collectionName}.index`, JSON.stringify(index));

    return Promise.resolve();
  }
开发者ID:m0n01i7h,项目名称:axios-cached-resource,代码行数:34,代码来源:localStorageProvider.ts


示例2: deleteFilledSubPath

 /**
  * Deletes the filled subpath at the specified index. All adjacent sibling subpaths
  * will be deleted as well (i.e. subpaths that share the same split segment ID).
  */
 deleteFilledSubPath(subIdx: number) {
   LOG('deleteFilledSubPath', subIdx);
   const targetCss = this.findSubPathStateLeaf(subIdx).getCommandStates();
   // Get the list of parent split segment IDs.
   const parentSplitSegIds = _(this.findSubPathStateParent(
     subIdx,
   ).getCommandStates() as CommandState[])
     .map(cs => cs.getSplitSegmentId())
     .compact()
     .uniq()
     .value();
   // Get the list of sibling split segment IDs, not including split segment
   // IDs inherited from the parent.
   const siblingSplitSegIds = _(targetCss as CommandState[])
     .map(cs => cs.getSplitSegmentId())
     .compact()
     .uniq()
     .difference(parentSplitSegIds)
     .value();
   siblingSplitSegIds.forEach(id => {
     const targetCs = _.find(targetCss, cs => cs.getSplitSegmentId() === id);
     const deletedSubIdxs = this.calculateDeletedSubIdxs(subIdx, targetCs);
     this.deleteFilledSubPathSegmentInternal(subIdx, targetCs);
     subIdx -= _.sumBy(deletedSubIdxs, idx => (idx <= subIdx ? 1 : 0));
   });
   return this;
 }
开发者ID:arpitsaan,项目名称:ShapeShifter,代码行数:31,代码来源:Path.ts


示例3: calcProfit

export function calcProfit(orders: OrderImpl[], config: ConfigRoot): { profit: number; commission: number } {
  const commission = _(orders).sumBy(o => {
    const brokerConfig = findBrokerConfig(config, o.broker);
    return calcCommission(o.averageFilledPrice, o.filledSize, brokerConfig.commissionPercent);
  });
  const profit = _(orders).sumBy(o => (o.side === OrderSide.Sell ? 1 : -1) * o.filledNotional) - commission;
  return { profit, commission };
}
开发者ID:tangkaisky,项目名称:r2,代码行数:8,代码来源:pnl.ts


示例4: test

        test("then the products should be there", () => {
            assert.isArray(customer.shoppingCart.items);
            assert.equal(customer.shoppingCart.items.length, 2);

            const item1 = _(customer.shoppingCart.items).find((item: any) => item.id === "redoma-2006-0.75");
            assert.isObject(item1);
            assert.equal(item1.quantity, 3);

            const item2 = _(customer.shoppingCart.items).find((item: any) => item.id === "tiara-2014-1.5");
            assert.isObject(item2);
            assert.equal(item2.quantity, 2);
        });
开发者ID:dfreire,项目名称:orders,代码行数:12,代码来源:index_test.ts


示例5: function

 return function(a: T, b: T) {
     if (!_(a).has(prop) || !_(b).has(prop)) {
         throw new Error("One of the objects in the collection doesn't have the property!")
     }
     if (a[prop] > b[prop]) {
         return how == "asc" ? 1 : (-1)
     }
     else if (a[prop] < b[prop]) {
         return how == "asc" ? (-1) : 1
     }
     else {
         return 0
     }
 }
开发者ID:MahaKoala,项目名称:client,代码行数:14,代码来源:index.ts


示例6: getNetOutRequest

 private async getNetOutRequest(order: Order): Promise<NewOrderRequest> {
   const openPositions = await this.brokerApi.getAllOpenLeveragePositions();
   const targetSide = order.side === OrderSide.Buy ? 'sell' : 'buy';
   const candidates = _(openPositions)
     .filter(p => p.side === targetSide)
     .filter(p => almostEqual(p.amount, order.size, 1))
     .value();
   if (order.symbol !== 'BTCJPY') {
     throw new Error('Not supported');
   }
   const pair = 'btc_jpy';
   const rate = order.type === OrderType.Market ? undefined : order.price;
   const request = { pair, rate };
   if (candidates.length === 0) {
     return {
       ...request,
       order_type: order.side === OrderSide.Buy ? 'leverage_buy' : 'leverage_sell',
       amount: order.size
     };
   }
   const targetPosition = _.last(candidates) as LeveragePosition;
   return {
     ...request,
     order_type: order.side === OrderSide.Buy ? 'close_short' : 'close_long',
     amount: targetPosition.amount,
     position_id: Number(targetPosition.id)
   };
 }
开发者ID:HarryTmetic,项目名称:r2,代码行数:28,代码来源:NetOutStrategy.ts


示例7: Task

        ).then(edges => {
            const minDate = (bs: Beacon[]) => _.min(bs.map(b => b.lastSwept)) || null;
            const edge = _(edges).keys().sortBy([
                k => (edges[k][0].related<BeaconSlot>("slot") as BeaconSlot).building,
                k => (edges[k][0].related<BeaconSlot>("slot") as BeaconSlot).startNode
            ]).value().reduce(
                (a, b, i) => minDate(edges[a]) <= minDate(edges[b]) ? a : b
            );

            const beacons = edges[edge];
            const lastSwept = minDate(beacons);
            if (lastSwept === null || moment(lastSwept).isBefore(moment().subtract(4, "weeks"))) {
                const slot = beacons[0].related<BeaconSlot>("slot") as BeaconSlot;
                console.log("slot debug", beacons[0], slot);
                return new Task({
                    template_type: "sweep_edge",
                    deployment_id: vol.deploymentId,
                    instruction_params: {
                        edge: edge,
                        start: slot.startNode,
                        end: slot.endNode,
                        beacons: beacons.map(b => b.minorId)
                    }
                });
            }
        });
开发者ID:CMUBigLab,项目名称:cmuNodeFbot,代码行数:26,代码来源:sweep_task.ts


示例8:

	it('arrays podem ser projetados com _.reduce e _.map', () => {
		type box = {
			width?: number,
			height?: number,
			url?: string
		}

		let boxarts: Array<box> = [
			{ width: 200, height: 200, url: 'http://cdn-0.nflximg.com/images/2891/Fracture200.jpg' },
			{ width: 150, height: 200, url: 'http://cdn-0.nflximg.com/images/2891/Fracture150.jpg' },
			{ width: 300, height: 200, url: 'http://cdn-0.nflximg.com/images/2891/Fracture300.jpg' },
			{ width: 425, height: 150, url: 'http://cdn-0.nflximg.com/images/2891/Fracture425.jpg' }
		];

		let maior: box =
			_(boxarts)
				.reduce((reduced: box, boxart: box) => {
					if (reduced.width * reduced.height > boxart.width * boxart.height) {
						return reduced;
					}
					else {
						return boxart;
					}
				}, {});

		expect(maior).to.deep.equal({ 
			width: 425, 
			height: 150, 
			url: 'http://cdn-0.nflximg.com/images/2891/Fracture425.jpg'
		});
	});
开发者ID:feliperohdee,项目名称:node-meetup-cheatsheet,代码行数:31,代码来源:arrays.ts


示例9: main

async function main() {
    const writer = createObjectCsvWriter({
        path: "puutteelliset.csv",
        header: [
            { id: "perusteId", title: "Peruste id" },
            { id: "nimi", title: "Nimi" },
            { id: "puuttuvat", title: "Puuttuvat osaamisalakuvaukset" },
        ]
    });

    const iter = lib.iteratePerusteet();
    const brokenOsaamisalat = [];

    for await (const peruste of iter) {
        if (!_.isEmpty(peruste.osaamisalat)) {
            const kuvaukset = await lib.getOsaamisalakuvaukset(peruste.id);
            const puuttuvat = _(peruste.osaamisalat)
                .filter(oa => !kuvaukset[oa.uri])
                .map("arvo")
                .value();

            if (!_.isEmpty(puuttuvat)) {
                brokenOsaamisalat.push({
                    perusteId: peruste.id,
                    nimi: peruste.nimi.fi,
                    puuttuvat: _.join(puuttuvat, " ")
                });
                console.log(_.last(brokenOsaamisalat));
            }
        }
    }

    await writer.writeRecords(brokenOsaamisalat);
}
开发者ID:Opetushallitus,项目名称:eperusteet,代码行数:34,代码来源:puutteellisetosaamisalat.ts


示例10: updateMessagesState

function updateMessagesState(messagesState: IRequestDetailLoggingMessageState[], request): IRequestDetailLoggingMessageState[] {
    if (request && request.messages && request.types) {
        const logWriteMessageIds = request.types['log-write'];

        if (logWriteMessageIds) {

            const allMessages = _(logWriteMessageIds)
                .map(id => request.messages[id])
                .filter(message => message !== undefined)
                .sortBy('ordinal')
                .map(message => {
                    return { 
                        level: message.payload.level, 
                        message: message.payload.message,
                        isObject: isMessageObject(message.payload.message),
                        spans: createSpans(message.payload.message, message.payload.replacedRegions) };
                })
                .value();

            return allMessages;
        }
    }

    return [];
}
开发者ID:Glimpse,项目名称:Glimpse.Client.Prototype,代码行数:25,代码来源:RequestDetailLoggingReducer.ts



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
TypeScript loopback类代码示例发布时间:2022-05-28
下一篇:
TypeScript levelup类代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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