test('should return an array iterator when array.entries is called', t => { let count = 0; let callbackCount = 0; const array = [{a: 0}, {a: 1}, {a: 2}]; const proxy = onChange(array, () => { callbackCount++; }); for (const [index, element] of proxy.entries()) { t.is(count++, index); t.is(callbackCount, element.a); element.a++; t.is(callbackCount, element.a); } t.is(callbackCount, 3); });
client.on('message', async message => { if (message.author.id !== owner) return; const match = message.content.match(/^do (.+)$/); if (match && match[1] === 'it') { /* eslint-disable no-await-in-loop */ for (const [i, test] of tests.entries()) { await message.channel.send(`**#${i}**\n\`\`\`js\n${test.toString()}\`\`\``); await test(message).catch(e => message.channel.send(`Error!\n\`\`\`\n${e}\`\`\``)); await wait(1000); } /* eslint-enable no-await-in-loop */ } else if (match) { const n = parseInt(match[1]) || 0; const test = tests.slice(n)[0]; const i = tests.indexOf(test); await message.channel.send(`**#${i}**\n\`\`\`js\n${test.toString()}\`\`\``); await test(message).catch(e => message.channel.send(`Error!\n\`\`\`\n${e}\`\`\``)); } });
client.on('message', async message => { if (message.author.id !== owner) return; const match = message.content.match(/^do (.+)$/); const hooks = [ { type: 'WebhookClient', hook: new Discord.WebhookClient(webhookChannel, webhookToken) }, { type: 'TextChannel#fetchWebhooks', hook: await message.channel.fetchWebhooks().then(x => x.first()) }, { type: 'Guild#fetchWebhooks', hook: await message.guild.fetchWebhooks().then(x => x.first()) }, ]; if (match && match[1] === 'it') { /* eslint-disable no-await-in-loop */ for (const { type, hook } of hooks) { for (const [i, test] of tests.entries()) { await message.channel.send(`**#${i}-Hook: ${type}**\n\`\`\`js\n${test.toString()}\`\`\``); await test(message, hook).catch(e => message.channel.send(`Error!\n\`\`\`\n${e}\`\`\``)); await wait(1000); } } /* eslint-enable no-await-in-loop */ } else if (match) { const n = parseInt(match[1]) || 0; const test = tests.slice(n)[0]; const i = tests.indexOf(test); /* eslint-disable no-await-in-loop */ for (const { type, hook } of hooks) { await message.channel.send(`**#${i}-Hook: ${type}**\n\`\`\`js\n${test.toString()}\`\`\``); await test(message, hook).catch(e => message.channel.send(`Error!\n\`\`\`\n${e}\`\`\``)); } /* eslint-enable no-await-in-loop */ } });
for (const [index, [from, to, status]] of expected.entries()) { expect(redirects[index]).toMatchObject({ from, to, status })
const walkFile = (pathResolve: string, mime: string): object => { const files = fs.readdirSync(pathResolve); const fileList = {}; for (const [i, item] of files.entries()) { const itemArr = item.split('.'); const itemMime = itemArr.length > 1 ? itemArr[itemArr.length - 1] : 'undefined'; if (mime === itemMime) { fileList[item] = pathResolve + item; } } return fileList; }
/** * @see Array#entries * @returns {Iterator.<T>} */ entries(){ return this._items.entries(); }
schedule.scheduleJob(ruleLanguage, async function () { console.log('language定时任务开始执行!', moment().format('YYYY-MM-DD HH:mm:ss')); for(let [idx, item] of languages.entries()) { await starsApi.mostStars(item) // 每个分类间隔两分钟 await helper.sleep(120000) } console.log('language的数据更新完成!', moment().format('YYYY-MM-DD HH:mm:ss')); });
/* eslint-env mocha, browser */ /* global proclaim */ it('is a function', function () { proclaim.isFunction(Array.prototype.entries); });
function truncateCustomKeys (value, max, keywords) { if (typeof value !== 'object' || value === null) { return value } const result = value const keys = Object.keys(result) const truncatedKeys = keys.map(k => keywords.includes(k) ? k : truncate(k, max)) for (const [index, k] of keys.entries()) { const value = result[k] delete result[k] const newKey = truncatedKeys[index] result[newKey] = truncateCustomKeys(value, max, keywords) } return result }
it('returns a next-able object', function () { var array = ['val1', 'val2']; var iterator = array.entries(); proclaim.isInstanceOf(iterator.next, Function); proclaim.deepEqual(iterator.next(), { value: [0, 'val1'], done: false }); });
it('has correct name', function () { proclaim.hasName(Array.prototype.entries, 'entries'); });
it('finally returns a done object', function () { var array = ['val1', 'val2']; var iterator = array.entries(); iterator.next(); iterator.next(); proclaim.deepEqual(iterator.next(), { value: undefined, done: true }); });
it('has correct arity', function () { proclaim.arity(Array.prototype.entries, 0); });
for (const [index, [from, to, status]] of expected.entries()) { expect(redirects[index]).toMatchObject({ from, to, status })
const walkFile = (pathResolve: string, mime: string): object => { const files = fs.readdirSync(pathResolve); const fileList = {}; for (const [i, item] of files.entries()) { const itemArr = item.split('.'); const itemMime = itemArr.length > 1 ? itemArr[itemArr.length - 1] : 'undefined'; if (mime === itemMime) { fileList[item] = pathResolve + item; } } return fileList; }