Comparing version 1.0.1 to 1.0.2
'use strict' | ||
async function * batch (source, size) { | ||
if (isNaN(size)) { | ||
size = parseInt(size) | ||
if (isNaN(size) || size < 1) { | ||
size = 1 | ||
@@ -6,0 +8,0 @@ } |
{ | ||
"name": "it-batch", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"description": "Takes an async iterator that emits things and emits them as fixed size batches", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
32
test.js
@@ -19,1 +19,33 @@ import batch from './' | ||
}) | ||
test('Should batch up entries with negative batch size', async (t) => { | ||
const values = [0, 1, 2, 3, 4] | ||
const batchSize = -1 | ||
const res = await all(batch(values, batchSize)) | ||
t.deepEqual(res, [[0], [1], [2], [3], [4]]) | ||
}) | ||
test('Should batch up entries with zero batch size', async (t) => { | ||
const values = [0, 1, 2, 3, 4] | ||
const batchSize = 0 | ||
const res = await all(batch(values, batchSize)) | ||
t.deepEqual(res, [[0], [1], [2], [3], [4]]) | ||
}) | ||
test('Should batch up entries with string batch size', async (t) => { | ||
const values = [0, 1, 2, 3, 4] | ||
const batchSize = '2' | ||
const res = await all(batch(values, batchSize)) | ||
t.deepEqual(res, [[0, 1], [2, 3], [4]]) | ||
}) | ||
test('Should batch up entries with non-integer batch size', async (t) => { | ||
const values = [0, 1, 2, 3, 4] | ||
const batchSize = 2.5 | ||
const res = await all(batch(values, batchSize)) | ||
t.deepEqual(res, [[0, 1], [2, 3], [4]]) | ||
}) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
3644
5
58