diff --git a/spec.emu b/spec.emu index ef44d42..461eefe 100644 --- a/spec.emu +++ b/spec.emu @@ -49,8 +49,8 @@ copyright: false 1. If _windowSize_ is not an integral Number in the inclusive interval from *1*𝔽 to 𝔽(232 - 1), then 1. Let _error_ be ThrowCompletion(a newly created *RangeError* object). 1. Return ? IteratorClose(_iterated_, _error_). - 1. If _undersized_ is *undefined*, set _undersized_ to *"only full"*. - 1. If _undersized_ is neither *"only full"* nor *"allow partial"*, then + 1. If _undersized_ is *undefined*, set _undersized_ to *"only-full"*. + 1. If _undersized_ is neither *"only-full"* nor *"allow-partial"*, then 1. Let _error_ be ThrowCompletion(a newly created *TypeError* object). 1. Return ? IteratorClose(_iterated_, _error_). 1. Set _iterated_ to ? GetIteratorDirect(_O_). @@ -59,7 +59,7 @@ copyright: false 1. Repeat, 1. Let _value_ be ? IteratorStepValue(_iterated_). 1. If _value_ is ~done~, then - 1. If _undersized_ is *"allow partial"*, _buffer_ is not empty, and the number of elements in _buffer_ < ℝ(_windowSize_), then + 1. If _undersized_ is *"allow-partial"*, _buffer_ is not empty, and the number of elements in _buffer_ < ℝ(_windowSize_), then 1. Perform Completion(Yield(CreateArrayFromList(_buffer_))). 1. Return ReturnCompletion(*undefined*). 1. If the number of elements in _buffer_ is ℝ(_windowSize_), then diff --git a/src/index.ts b/src/index.ts index 79a898e..47ffc77 100644 --- a/src/index.ts +++ b/src/index.ts @@ -31,7 +31,7 @@ function chunks(this: unknown, chunkSize: unknown): Generator { return chunksImpl(this as Iterator, chunkSize) } -function* windowsImpl(iter: Iterator, windowSize: number, undersized: 'only full' | 'allow partial'): Generator> { +function* windowsImpl(iter: Iterator, windowSize: number, undersized: 'only-full' | 'allow-partial'): Generator> { let buffer = []; for (const elem of liftIterator(iter)) { if (buffer.length === windowSize) { @@ -42,12 +42,12 @@ function* windowsImpl(iter: Iterator, windowSize: number, undersized: 'onl yield buffer.slice(); } } - if (undersized === 'allow partial' && 0 < buffer.length && buffer.length < windowSize) { + if (undersized === 'allow-partial' && 0 < buffer.length && buffer.length < windowSize) { yield buffer; } } -function windows(this: Iterator, windowSize: number, undersized?: 'only full' | 'allow partial'): Generator> +function windows(this: Iterator, windowSize: number, undersized?: 'only-full' | 'allow-partial'): Generator> function windows(this: unknown, windowSize: unknown, undersized?: unknown): Generator { if ( typeof windowSize !== 'number' @@ -58,9 +58,9 @@ function windows(this: unknown, windowSize: unknown, undersized?: unknown): Gene throw new RangeError; } if (undersized === undefined) { - undersized = 'only full'; + undersized = 'only-full'; } - if (undersized !== 'only full' && undersized !== 'allow partial') { + if (undersized !== 'only-full' && undersized !== 'allow-partial') { throw new TypeError; } return windowsImpl(this as Iterator, windowSize, undersized); diff --git a/test/index.mjs b/test/index.mjs index 285656a..5688e8b 100644 --- a/test/index.mjs +++ b/test/index.mjs @@ -66,11 +66,11 @@ test('windows', async t => { [[0, 1], [1, 2], [2, 3], [3, 4]], ); assert.deepEqual( - Array.from(nats(5).windows(2, "only full")), + Array.from(nats(5).windows(2, "only-full")), [[0, 1], [1, 2], [2, 3], [3, 4]], ); assert.deepEqual( - Array.from(nats(5).windows(2, "allow partial")), + Array.from(nats(5).windows(2, "allow-partial")), [[0, 1], [1, 2], [2, 3], [3, 4]], ); @@ -83,11 +83,11 @@ test('windows', async t => { [[0], [1], [2], [3], [4]], ); assert.deepEqual( - Array.from(nats(5).windows(1, "only full")), + Array.from(nats(5).windows(1, "only-full")), [[0], [1], [2], [3], [4]], ); assert.deepEqual( - Array.from(nats(5).windows(1, "allow partial")), + Array.from(nats(5).windows(1, "allow-partial")), [[0], [1], [2], [3], [4]], ); @@ -100,11 +100,11 @@ test('windows', async t => { [[0, 1, 2], [1, 2, 3], [2, 3, 4], [3, 4, 5]], ); assert.deepEqual( - Array.from(nats(6).windows(3, "only full")), + Array.from(nats(6).windows(3, "only-full")), [[0, 1, 2], [1, 2, 3], [2, 3, 4], [3, 4, 5]], ); assert.deepEqual( - Array.from(nats(6).windows(3, "allow partial")), + Array.from(nats(6).windows(3, "allow-partial")), [[0, 1, 2], [1, 2, 3], [2, 3, 4], [3, 4, 5]], ); @@ -117,11 +117,11 @@ test('windows', async t => { [], ); assert.deepEqual( - Array.from(nats(6).windows(100, "only full")), + Array.from(nats(6).windows(100, "only-full")), [], ); assert.deepEqual( - Array.from(nats(6).windows(100, "allow partial")), + Array.from(nats(6).windows(100, "allow-partial")), [[0, 1, 2, 3, 4, 5]], ); @@ -134,11 +134,11 @@ test('windows', async t => { [], ); assert.deepEqual( - Array.from(nats(0).windows(2, "only full")), + Array.from(nats(0).windows(2, "only-full")), [], ); assert.deepEqual( - Array.from(nats(0).windows(2, "allow partial")), + Array.from(nats(0).windows(2, "allow-partial")), [], ); @@ -146,20 +146,20 @@ test('windows', async t => { nats(1).windows() }, RangeError); assert.throws(() => { - nats(1).windows(undefined, "only full") + nats(1).windows(undefined, "only-full") }, RangeError); assert.throws(() => { - nats(1).windows(undefined, "allow partial") + nats(1).windows(undefined, "allow-partial") }, RangeError); assert.throws(() => { nats(1).windows([2]); }, RangeError); assert.throws(() => { - nats(1).windows([2], "only full"); + nats(1).windows([2], "only-full"); }, RangeError); assert.throws(() => { - nats(1).windows([2], "allow partial"); + nats(1).windows([2], "allow-partial"); }, RangeError); assert.throws(() => { @@ -169,10 +169,10 @@ test('windows', async t => { nats(1).windows(0, undefined); }, RangeError); assert.throws(() => { - nats(1).windows(0, "only full"); + nats(1).windows(0, "only-full"); }, RangeError); assert.throws(() => { - nats(1).windows(0, "allow partial"); + nats(1).windows(0, "allow-partial"); }, RangeError); assert.throws(() => { @@ -182,10 +182,10 @@ test('windows', async t => { nats(1).windows(-1, undefined); }, RangeError); assert.throws(() => { - nats(1).windows(-1, "only full"); + nats(1).windows(-1, "only-full"); }, RangeError); assert.throws(() => { - nats(1).windows(-1, "allow partial"); + nats(1).windows(-1, "allow-partial"); }, RangeError); assert.throws(() => { @@ -195,10 +195,10 @@ test('windows', async t => { nats(1).windows(1.5, undefined); }, RangeError); assert.throws(() => { - nats(1).windows(1.5, "only full"); + nats(1).windows(1.5, "only-full"); }, RangeError); assert.throws(() => { - nats(1).windows(1.5, "allow partial"); + nats(1).windows(1.5, "allow-partial"); }, RangeError); assert.throws(() => { @@ -208,10 +208,10 @@ test('windows', async t => { nats(1).windows(Math.pow(2, 53), undefined); }, RangeError); assert.throws(() => { - nats(1).windows(Math.pow(2, 53), "only full"); + nats(1).windows(Math.pow(2, 53), "only-full"); }, RangeError); assert.throws(() => { - nats(1).windows(Math.pow(2, 53), "allow partial"); + nats(1).windows(Math.pow(2, 53), "allow-partial"); }, RangeError); assert.throws(() => {