本文整理汇总了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();
}
示例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;
}
示例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 };
}
示例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);
});
示例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
}
}
示例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)
};
}
示例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)
}
});
}
});
示例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'
});
});
示例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);
}
示例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 [];
}