当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript lodash.default方法代码示例

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


在下文中一共展示了lodash.default方法的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.default方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。