本文整理汇总了TypeScript中lodash.drop函数的典型用法代码示例。如果您正苦于以下问题:TypeScript drop函数的具体用法?TypeScript drop怎么用?TypeScript drop使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了drop函数的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: execute
/**
* Locate and execute a command given an array of positional command
* arguments (argv) and a set of environment variables.
*
* If a command is not found, formatted help is automatically output for the
* right-most namespace found.
*
* @param argv Command arguments sliced to the root for the namespace of this
* executor. Usually, this means `process.argv.slice(2)`.
* @param env Environment variables for this execution.
*/
async execute(argv: readonly string[], env: NodeJS.ProcessEnv): Promise<void> {
if (argv[0] === EXECUTOR_OPS.RPC) {
return this.rpc();
}
const parsedArgs = stripOptions(argv, { includeSeparated: false });
const location = await this.namespace.locate(parsedArgs);
if (argv.find(arg => arg === '--help' || arg === '-?') || isNamespace(location.obj)) {
const cmdoptions = parseArgs([...argv]);
this.stdout.write(await this.formatHelp(location, { format: cmdoptions['json'] ? 'json' : 'terminal' }));
} else {
const cmd = location.obj;
const cmdargs = lodash.drop(argv, location.path.length - 1);
try {
await this.run(cmd, cmdargs, { location, env, executor: this });
} catch (e) {
if (e instanceof BaseError) {
this.stderr.write(`Error: ${e.message}`);
process.exitCode = typeof e.exitCode === 'undefined' ? 1 : e.exitCode;
return;
}
throw e;
}
}
}
示例2:
return _.map(timestampeds, (values, outcome: string) => {
let result: T | undefined;
const beforeBucket = _.takeWhile(values, (pl) => pl.timestamp <= bucket.timestamp);
if (beforeBucket.length > 0) {
_.drop(values, beforeBucket.length);
result = _.last(beforeBucket);
}
if (!result) result = Object.assign({ outcome }, defaultValue);
result.timestamp = bucket.timestamp;
return result;
});
示例3: List
return new List(function* () {
let n = xs0.length;
let xs = xs0;
let prevHd = new Array<A>();
while (n >= k) {
const hd = _.take(xs, k);
const tl = _.drop(xs, k);
yield prevHd.concat(tl);
n = n - k;
xs = tl;
prevHd = prevHd.concat(hd);
}
});
示例4: Set
export const sortTableData = (
data: string[][],
sort: SortOptions
): {sortedData: string[][]; sortedTimeVals: string[]} => {
const headerSet = new Set(data[0])
let sortIndex = 0
if (headerSet.has(sort.field)) {
sortIndex = _.indexOf(data[0], sort.field)
}
const dataValues = _.drop(data, 1)
const sortedData = [
data[0],
..._.orderBy<string[][]>(dataValues, sortIndex, [sort.direction]),
] as string[][]
const sortedTimeVals = fastMap<string[], string>(
sortedData,
(r: string[]): string => r[sortIndex]
)
return {sortedData, sortedTimeVals}
}
示例5:
return _.map(array, (val, i) => _.drop(array, i).concat(_.take(array, i)));
示例6: handleMessage
handleMessage({ content, player, timestamp}: ClientMessage<Player.GamePlayer>): Message[] {
let responses: Message[] = [ Messaging.createEchoMessage(content, player) ];
const component = Actions.getComponentByText(content);
// if we received an action command message
if (component) {
const action = component.parse(content, player.character, timestamp);
const { isValid, error } = component.validate(action, this);
if (isValid) {
player.character.nextAction = action;
responses.push(Messaging.createGameMessage(`Next action: ${content}`, [ player ]));
} else {
responses.push(Messaging.createGameMessage(`Invalid action: ${error}`, [ player ]));
}
} else if (_.startsWith(content, '/')) {
const messageNameSpan = Messaging.spanMessagePlayerNames(content, this.players);
const toPlayers: Player.GamePlayer[] = [];
if (_.startsWith(content, '/s ')) {
this.getNearbyAnimals(player.character).forEach(animal => {
// do we even need to send a message?
if (Character.isPlayerCharacter(animal)) {
// don't send a shout to the shouter!
if (animal.playerId !== player.id) {
const maybePlayer = this.getPlayer(animal.playerId);
if (maybePlayer) {
toPlayers.push(maybePlayer);
} else {
throw new Error(`Got a bad or missing id: ${animal.playerId}`);
}
}
}
});
} else {
messageNameSpan.names.forEach(name => {
const maybePlayer = this.getPlayerByName(name);
if (maybePlayer) {
toPlayers.push(maybePlayer);
} else {
// do nothing
}
});
}
const [ yesComm, noComm ] = _.partition(toPlayers, otherPlayer => Player.canCommunicate(player, otherPlayer));
const noCommMessage = 'something [CANNOT COMMUNICATE]';
const restContent = messageNameSpan.rest;
if (_.startsWith(content, '/t ')) {
responses.push(Messaging.createTalkMessage(player, restContent, yesComm));
responses.push(Messaging.createTalkMessage(player, noCommMessage, noComm));
} else if (_.startsWith(content, '/s ')) {
responses.push(Messaging.createShoutMessage(player, restContent, yesComm));
responses.push(Messaging.createShoutMessage(player, noCommMessage, noComm));
} else if (_.startsWith(content, '/w ')) {
if (toPlayers.length) {
if (yesComm.length) {
const whisperContent = _.drop(content.split(' '), 2).join(' ');
responses.push(Messaging.createWhisperMessage(player, whisperContent, _.head(yesComm)));
}
if (noComm.length) {
responses.push(Messaging.createWhisperMessage(player, noCommMessage, _.head(noComm)));
}
}
} else {
responses.push(Messaging.createGameMessage(`Unknown communication: "${content}`, [ player ]));
}
} else {
responses.push(Messaging.createGameMessage(`Unknown command or communication: "${content}"`, [ player ]));
}
return responses;
}
示例7: parseInt
return rows.map(row => {
const name = _.drop(row.name.split('~')).join('~')
return { ...row, name: _.isEmpty(name) ? 'unknown' : name, count: parseInt(row.count) }
})