Comparing version 3.0.6 to 3.1.0
(function (root, factory) {(typeof module === 'object' && module.exports) ? module.exports = factory() : root.ItMap = factory()}(typeof self !== 'undefined' ? self : this, function () { | ||
"use strict";var ItMap=(()=>{var i=Object.defineProperty;var s=Object.getOwnPropertyDescriptor;var y=Object.getOwnPropertyNames;var c=Object.prototype.hasOwnProperty;var p=(t,n)=>{for(var e in n)i(t,e,{get:n[e],enumerable:!0})},m=(t,n,e,r)=>{if(n&&typeof n=="object"||typeof n=="function")for(let o of y(n))!c.call(t,o)&&o!==e&&i(t,o,{get:()=>n[o],enumerable:!(r=s(n,o))||r.enumerable});return t};var d=t=>m(i({},"__esModule",{value:!0}),t);var v={};p(v,{default:()=>S});function b(t){let[n,e]=t[Symbol.asyncIterator]!=null?[t[Symbol.asyncIterator](),Symbol.asyncIterator]:[t[Symbol.iterator](),Symbol.iterator],r=[];return{peek:()=>n.next(),push:o=>{r.push(o)},next:()=>r.length>0?{done:!1,value:r.shift()}:n.next(),[e](){return this}}}var u=b;function h(t){return t[Symbol.asyncIterator]!=null}function x(t,n){if(h(t))return async function*(){for await(let a of t)yield n(a)}();let e=u(t),{value:r,done:o}=e.next();if(o===!0)return function*(){}();let l=n(r);if(typeof l.then=="function")return async function*(){yield await l;for await(let a of e)yield n(a)}();let f=n;return function*(){yield l;for(let a of e)yield f(a)}()}var S=x;return d(v);})(); | ||
"use strict";var ItMap=(()=>{var i=Object.defineProperty;var y=Object.getOwnPropertyDescriptor;var c=Object.getOwnPropertyNames;var p=Object.prototype.hasOwnProperty;var d=(t,n)=>{for(var e in n)i(t,e,{get:n[e],enumerable:!0})},m=(t,n,e,o)=>{if(n&&typeof n=="object"||typeof n=="function")for(let r of c(n))!p.call(t,r)&&r!==e&&i(t,r,{get:()=>n[r],enumerable:!(o=y(n,r))||o.enumerable});return t};var b=t=>m(i({},"__esModule",{value:!0}),t);var I={};d(I,{default:()=>v});function x(t){let[n,e]=t[Symbol.asyncIterator]!=null?[t[Symbol.asyncIterator](),Symbol.asyncIterator]:[t[Symbol.iterator](),Symbol.iterator],o=[];return{peek:()=>n.next(),push:r=>{o.push(r)},next:()=>o.length>0?{done:!1,value:o.shift()}:n.next(),[e](){return this}}}var u=x;function h(t){return t[Symbol.asyncIterator]!=null}function S(t,n){let e=0;if(h(t))return async function*(){for await(let a of t)yield n(a,e++)}();let o=u(t),{value:r,done:f}=o.next();if(f===!0)return function*(){}();let l=n(r,e++);if(typeof l.then=="function")return async function*(){yield await l;for await(let a of o)yield n(a,e++)}();let s=n;return function*(){yield l;for(let a of o)yield s(a,e++)}()}var v=S;return b(I);})(); | ||
return ItMap})); |
@@ -14,3 +14,3 @@ /** | ||
* | ||
* const result = map(values, (val) => val++) | ||
* const result = map(values, (val, index) => val++) | ||
* | ||
@@ -29,3 +29,3 @@ * console.info(result) // [1, 2, 3, 4, 5] | ||
* | ||
* const result = await map(values(), async (val) => val++) | ||
* const result = await map(values(), async (val, index) => val++) | ||
* | ||
@@ -39,6 +39,6 @@ * console.info(result) // [1, 2, 3, 4, 5] | ||
*/ | ||
declare function map<I, O>(source: Iterable<I>, func: (val: I) => Promise<O>): AsyncGenerator<O, void, undefined>; | ||
declare function map<I, O>(source: Iterable<I>, func: (val: I) => O): Generator<O, void, undefined>; | ||
declare function map<I, O>(source: AsyncIterable<I> | Iterable<I>, func: (val: I) => O | Promise<O>): AsyncGenerator<O, void, undefined>; | ||
declare function map<I, O>(source: Iterable<I>, func: (val: I, index: number) => Promise<O>): AsyncGenerator<O, void, undefined>; | ||
declare function map<I, O>(source: Iterable<I>, func: (val: I, index: number) => O): Generator<O, void, undefined>; | ||
declare function map<I, O>(source: AsyncIterable<I> | Iterable<I>, func: (val: I, index: number) => O | Promise<O>): AsyncGenerator<O, void, undefined>; | ||
export default map; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -14,3 +14,3 @@ /** | ||
* | ||
* const result = map(values, (val) => val++) | ||
* const result = map(values, (val, index) => val++) | ||
* | ||
@@ -29,3 +29,3 @@ * console.info(result) // [1, 2, 3, 4, 5] | ||
* | ||
* const result = await map(values(), async (val) => val++) | ||
* const result = await map(values(), async (val, index) => val++) | ||
* | ||
@@ -40,6 +40,7 @@ * console.info(result) // [1, 2, 3, 4, 5] | ||
function map(source, func) { | ||
let index = 0; | ||
if (isAsyncIterable(source)) { | ||
return (async function* () { | ||
for await (const val of source) { | ||
yield func(val); | ||
yield func(val, index++); | ||
} | ||
@@ -54,3 +55,3 @@ })(); | ||
} | ||
const res = func(value); | ||
const res = func(value, index++); | ||
// @ts-expect-error .then is not present on O | ||
@@ -61,3 +62,3 @@ if (typeof res.then === 'function') { | ||
for await (const val of peekable) { | ||
yield func(val); | ||
yield func(val, index++); | ||
} | ||
@@ -70,3 +71,3 @@ })(); | ||
for (const val of peekable) { | ||
yield fn(val); | ||
yield fn(val, index++); | ||
} | ||
@@ -73,0 +74,0 @@ })(); |
{ | ||
"name": "it-map", | ||
"version": "3.0.6", | ||
"version": "3.1.0", | ||
"description": "Maps the values yielded by an async iterator", | ||
@@ -5,0 +5,0 @@ "author": "Alex Potsides <alex@achingbrain.net>", |
@@ -35,3 +35,3 @@ # it-map | ||
const result = map(values, (val) => val++) | ||
const result = map(values, (val, index) => val++) | ||
@@ -50,3 +50,3 @@ console.info(result) // [1, 2, 3, 4, 5] | ||
const result = await map(values(), async (val) => val++) | ||
const result = await map(values(), async (val, index) => val++) | ||
@@ -53,0 +53,0 @@ console.info(result) // [1, 2, 3, 4, 5] |
@@ -14,3 +14,3 @@ /** | ||
* | ||
* const result = map(values, (val) => val++) | ||
* const result = map(values, (val, index) => val++) | ||
* | ||
@@ -29,3 +29,3 @@ * console.info(result) // [1, 2, 3, 4, 5] | ||
* | ||
* const result = await map(values(), async (val) => val++) | ||
* const result = await map(values(), async (val, index) => val++) | ||
* | ||
@@ -46,10 +46,12 @@ * console.info(result) // [1, 2, 3, 4, 5] | ||
*/ | ||
function map <I, O> (source: Iterable<I>, func: (val: I) => Promise<O>): AsyncGenerator<O, void, undefined> | ||
function map <I, O> (source: Iterable<I>, func: (val: I) => O): Generator<O, void, undefined> | ||
function map <I, O> (source: AsyncIterable<I> | Iterable<I>, func: (val: I) => O | Promise<O>): AsyncGenerator<O, void, undefined> | ||
function map <I, O> (source: AsyncIterable<I> | Iterable<I>, func: (val: I) => O | Promise<O>): AsyncGenerator<O, void, undefined> | Generator<O, void, undefined> { | ||
function map <I, O> (source: Iterable<I>, func: (val: I, index: number) => Promise<O>): AsyncGenerator<O, void, undefined> | ||
function map <I, O> (source: Iterable<I>, func: (val: I, index: number) => O): Generator<O, void, undefined> | ||
function map <I, O> (source: AsyncIterable<I> | Iterable<I>, func: (val: I, index: number) => O | Promise<O>): AsyncGenerator<O, void, undefined> | ||
function map <I, O> (source: AsyncIterable<I> | Iterable<I>, func: (val: I, index: number) => O | Promise<O>): AsyncGenerator<O, void, undefined> | Generator<O, void, undefined> { | ||
let index = 0 | ||
if (isAsyncIterable(source)) { | ||
return (async function * () { | ||
for await (const val of source) { | ||
yield func(val) | ||
yield func(val, index++) | ||
} | ||
@@ -67,3 +69,3 @@ })() | ||
const res = func(value) | ||
const res = func(value, index++) | ||
@@ -76,3 +78,3 @@ // @ts-expect-error .then is not present on O | ||
for await (const val of peekable) { | ||
yield func(val) | ||
yield func(val, index++) | ||
} | ||
@@ -82,3 +84,3 @@ })() | ||
const fn = func as (val: I) => O | ||
const fn = func as (val: I, index: number) => O | ||
@@ -89,3 +91,3 @@ return (function * () { | ||
for (const val of peekable) { | ||
yield fn(val) | ||
yield fn(val, index++) | ||
} | ||
@@ -92,0 +94,0 @@ })() |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
12824
197