Add comprehensive installation and setup documentation

- Add GETTING_STARTED.md with quick start guide and development modes
- Add INSTALL.sh automated installation script
- Add INSTALLATION_CHECKLIST.md, INSTALLATION_SUCCESS.md, and INSTALLATION_SUMMARY.md
- Add QUICK_REFERENCE.md for common commands
- Add SETUP_GUIDE.md with detailed setup instructions
- Update README.md with improved project overview
- Add did-wallet app dependencies and node_modules
This commit is contained in:
Dorian
2026-01-27 17:18:21 +00:00
parent a81f655133
commit 0d073fa89e
22658 changed files with 4494151 additions and 6 deletions

81
apps/web5-dwn/node_modules/it-map/README.md generated vendored Normal file
View File

@@ -0,0 +1,81 @@
# it-map
[![codecov](https://img.shields.io/codecov/c/github/achingbrain/it.svg?style=flat-square)](https://codecov.io/gh/achingbrain/it)
[![CI](https://img.shields.io/github/actions/workflow/status/achingbrain/it/js-test-and-release.yml?branch=main\&style=flat-square)](https://github.com/achingbrain/it/actions/workflows/js-test-and-release.yml?query=branch%3Amain)
> Maps the values yielded by an async iterator
# About
<!--
!IMPORTANT!
Everything in this README between "# About" and "# Install" is automatically
generated and will be overwritten the next time the doc generator is run.
To make changes to this section, please update the @packageDocumentation section
of src/index.js or src/index.ts
To experiment with formatting, please run "npm run docs" from the root of this
repo and examine the changes made.
-->
Convert one value from an (async)iterator into another.
## Example
```javascript
import map from 'it-map'
// This can also be an iterator, generator, etc
const values = [0, 1, 2, 3, 4]
const result = map(values, (val, index) => val++)
console.info(result) // [1, 2, 3, 4, 5]
```
Async sources and transforms must be awaited:
```javascript
import map from 'it-map'
const values = async function * () {
yield * [0, 1, 2, 3, 4]
}
const result = await map(values(), async (val, index) => val++)
console.info(result) // [1, 2, 3, 4, 5]
```
# Install
```console
$ npm i it-map
```
## Browser `<script>` tag
Loading this module through a script tag will make its exports available as `ItMap` in the global namespace.
```html
<script src="https://unpkg.com/it-map/dist/index.min.js"></script>
```
# API Docs
- <https://achingbrain.github.io/it/modules/it_map.html>
# License
Licensed under either of
- Apache 2.0, ([LICENSE-APACHE](https://github.com/achingbrain/it/blob/main/packages/it-map/LICENSE-APACHE) / <http://www.apache.org/licenses/LICENSE-2.0>)
- MIT ([LICENSE-MIT](https://github.com/achingbrain/it/blob/main/packages/it-map/LICENSE-MIT) / <http://opensource.org/licenses/MIT>)
# Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

4
apps/web5-dwn/node_modules/it-map/dist/index.min.js generated vendored Normal file
View File

@@ -0,0 +1,4 @@
(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 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(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}));
//# sourceMappingURL=index.min.js.map

View File

@@ -0,0 +1,7 @@
{
"version": 3,
"sources": ["../src/index.ts", "../../it-peekable/src/index.ts"],
"sourcesContent": ["/**\n * @packageDocumentation\n *\n * Convert one value from an (async)iterator into another.\n *\n * @example\n *\n * ```javascript\n * import map from 'it-map'\n *\n * // This can also be an iterator, generator, etc\n * const values = [0, 1, 2, 3, 4]\n *\n * const result = map(values, (val, index) => val++)\n *\n * console.info(result) // [1, 2, 3, 4, 5]\n * ```\n *\n * Async sources and transforms must be awaited:\n *\n * ```javascript\n * import map from 'it-map'\n *\n * const values = async function * () {\n * yield * [0, 1, 2, 3, 4]\n * }\n *\n * const result = await map(values(), async (val, index) => val++)\n *\n * console.info(result) // [1, 2, 3, 4, 5]\n * ```\n */\n\nimport peek from 'it-peekable'\n\nfunction isAsyncIterable <T> (thing: any): thing is AsyncIterable<T> {\n return thing[Symbol.asyncIterator] != null\n}\n\n/**\n * Takes an (async) iterable and returns one with each item mapped by the passed\n * function\n */\nfunction map <I, O> (source: Iterable<I>, func: (val: I, index: number) => Promise<O>): AsyncGenerator<O, void, undefined>\nfunction map <I, O> (source: Iterable<I>, func: (val: I, index: number) => O): Generator<O, void, undefined>\nfunction map <I, O> (source: AsyncIterable<I> | Iterable<I>, func: (val: I, index: number) => O | Promise<O>): AsyncGenerator<O, void, undefined>\nfunction map <I, O> (source: AsyncIterable<I> | Iterable<I>, func: (val: I, index: number) => O | Promise<O>): AsyncGenerator<O, void, undefined> | Generator<O, void, undefined> {\n let index = 0\n\n if (isAsyncIterable(source)) {\n return (async function * () {\n for await (const val of source) {\n yield func(val, index++)\n }\n })()\n }\n\n // if mapping function returns a promise we have to return an async generator\n const peekable = peek(source)\n const { value, done } = peekable.next()\n\n if (done === true) {\n return (function * () {}())\n }\n\n const res = func(value, index++)\n\n // @ts-expect-error .then is not present on O\n if (typeof res.then === 'function') {\n return (async function * () {\n yield await res\n\n for (const val of peekable) {\n yield func(val, index++)\n }\n })()\n }\n\n const fn = func as (val: I, index: number) => O\n\n return (function * () {\n yield res as O\n\n for (const val of peekable) {\n yield fn(val, index++)\n }\n })()\n}\n\nexport default map\n", "/**\n * @packageDocumentation\n *\n * Lets you look at the contents of an async iterator and decide what to do\n *\n * @example\n *\n * ```javascript\n * import peekable from 'it-peekable'\n *\n * // This can also be an iterator, generator, etc\n * const values = [0, 1, 2, 3, 4]\n *\n * const it = peekable(value)\n *\n * const first = it.peek()\n *\n * console.info(first) // 0\n *\n * it.push(first)\n *\n * console.info([...it])\n * // [ 0, 1, 2, 3, 4 ]\n * ```\n *\n * Async sources must be awaited:\n *\n * ```javascript\n * import peekable from 'it-peekable'\n *\n * const values = async function * () {\n * yield * [0, 1, 2, 3, 4]\n * }\n *\n * const it = peekable(values())\n *\n * const first = await it.peek()\n *\n * console.info(first) // 0\n *\n * it.push(first)\n *\n * console.info(await all(it))\n * // [ 0, 1, 2, 3, 4 ]\n * ```\n */\n\nexport interface Peek <T> {\n peek(): IteratorResult<T, undefined>\n}\n\nexport interface AsyncPeek <T> {\n peek(): Promise<IteratorResult<T, undefined>>\n}\n\nexport interface Push <T> {\n push(value: T): void\n}\n\nexport type Peekable <T> = Iterable<T> & Peek<T> & Push<T> & Iterator<T>\n\nexport type AsyncPeekable <T> = AsyncIterable<T> & AsyncPeek<T> & Push<T> & AsyncIterator<T>\n\nfunction peekable <T> (iterable: Iterable<T>): Peekable<T>\nfunction peekable <T> (iterable: AsyncIterable<T>): AsyncPeekable<T>\nfunction peekable <T> (iterable: Iterable<T> | AsyncIterable<T>): Peekable<T> | AsyncPeekable<T> {\n // @ts-expect-error can't use Symbol.asyncIterator to index iterable since it might be Iterable\n const [iterator, symbol] = iterable[Symbol.asyncIterator] != null\n // @ts-expect-error can't use Symbol.asyncIterator to index iterable since it might be Iterable\n ? [iterable[Symbol.asyncIterator](), Symbol.asyncIterator]\n // @ts-expect-error can't use Symbol.iterator to index iterable since it might be AsyncIterable\n : [iterable[Symbol.iterator](), Symbol.iterator]\n\n const queue: any[] = []\n\n // @ts-expect-error can't use symbol to index peekable\n return {\n peek: () => {\n return iterator.next()\n },\n push: (value: any) => {\n queue.push(value)\n },\n next: () => {\n if (queue.length > 0) {\n return {\n done: false,\n value: queue.shift()\n }\n }\n\n return iterator.next()\n },\n [symbol] () {\n return this\n }\n }\n}\n\nexport default peekable\n"],
"mappings": ";ybAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,aAAAE,ICiEA,SAASC,EAAcC,EAAwC,CAE7D,GAAM,CAACC,EAAUC,CAAM,EAAIF,EAAS,OAAO,aAAa,GAAK,KAEzD,CAACA,EAAS,OAAO,aAAa,EAAC,EAAI,OAAO,aAAa,EAEvD,CAACA,EAAS,OAAO,QAAQ,EAAC,EAAI,OAAO,QAAQ,EAE3CG,EAAe,CAAA,EAGrB,MAAO,CACL,KAAM,IACGF,EAAS,KAAI,EAEtB,KAAOG,GAAc,CACnBD,EAAM,KAAKC,CAAK,CAClB,EACA,KAAM,IACAD,EAAM,OAAS,EACV,CACL,KAAM,GACN,MAAOA,EAAM,MAAK,GAIfF,EAAS,KAAI,EAEtB,CAACC,CAAM,GAAC,CACN,OAAO,IACT,EAEJ,CAEA,IAAAG,EAAeN,EDhEf,SAASO,EAAqBC,EAAU,CACtC,OAAOA,EAAM,OAAO,aAAa,GAAK,IACxC,CASA,SAASC,EAAYC,EAAwCC,EAA+C,CAC1G,IAAIC,EAAQ,EAEZ,GAAIL,EAAgBG,CAAM,EACxB,OAAQ,iBAAgB,CACtB,cAAiBG,KAAOH,EACtB,MAAMC,EAAKE,EAAKD,GAAO,CAE3B,EAAE,EAIJ,IAAME,EAAWC,EAAKL,CAAM,EACtB,CAAE,MAAAM,EAAO,KAAAC,CAAI,EAAKH,EAAS,KAAI,EAErC,GAAIG,IAAS,GACX,OAAQ,WAAU,CAAK,EAAC,EAG1B,IAAMC,EAAMP,EAAKK,EAAOJ,GAAO,EAG/B,GAAI,OAAOM,EAAI,MAAS,WACtB,OAAQ,iBAAgB,CACtB,MAAM,MAAMA,EAEZ,QAAWL,KAAOC,EAChB,MAAMH,EAAKE,EAAKD,GAAO,CAE3B,EAAE,EAGJ,IAAMO,EAAKR,EAEX,OAAQ,WAAU,CAChB,MAAMO,EAEN,QAAWL,KAAOC,EAChB,MAAMK,EAAGN,EAAKD,GAAO,CAEzB,EAAE,CACJ,CAEA,IAAAQ,EAAeX",
"names": ["index_exports", "__export", "index_default", "peekable", "iterable", "iterator", "symbol", "queue", "value", "src_default", "isAsyncIterable", "thing", "map", "source", "func", "index", "val", "peekable", "src_default", "value", "done", "res", "fn", "index_default"]
}

41
apps/web5-dwn/node_modules/it-map/dist/src/index.d.ts generated vendored Normal file
View File

@@ -0,0 +1,41 @@
/**
* @packageDocumentation
*
* Convert one value from an (async)iterator into another.
*
* @example
*
* ```javascript
* import map from 'it-map'
*
* // This can also be an iterator, generator, etc
* const values = [0, 1, 2, 3, 4]
*
* const result = map(values, (val, index) => val++)
*
* console.info(result) // [1, 2, 3, 4, 5]
* ```
*
* Async sources and transforms must be awaited:
*
* ```javascript
* import map from 'it-map'
*
* const values = async function * () {
* yield * [0, 1, 2, 3, 4]
* }
*
* const result = await map(values(), async (val, index) => val++)
*
* console.info(result) // [1, 2, 3, 4, 5]
* ```
*/
/**
* Takes an (async) iterable and returns one with each item mapped by the passed
* function
*/
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

View File

@@ -0,0 +1 @@
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AAQH;;;GAGG;AACH,iBAAS,GAAG,CAAE,CAAC,EAAE,CAAC,EAAG,MAAM,EAAE,QAAQ,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,GAAG,EAAE,CAAC,EAAE,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC,CAAC,CAAC,GAAG,cAAc,CAAC,CAAC,EAAE,IAAI,EAAE,SAAS,CAAC,CAAA;AAC1H,iBAAS,GAAG,CAAE,CAAC,EAAE,CAAC,EAAG,MAAM,EAAE,QAAQ,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,GAAG,EAAE,CAAC,EAAE,KAAK,EAAE,MAAM,KAAK,CAAC,GAAG,SAAS,CAAC,CAAC,EAAE,IAAI,EAAE,SAAS,CAAC,CAAA;AAC5G,iBAAS,GAAG,CAAE,CAAC,EAAE,CAAC,EAAG,MAAM,EAAE,aAAa,CAAC,CAAC,CAAC,GAAG,QAAQ,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,GAAG,EAAE,CAAC,EAAE,KAAK,EAAE,MAAM,KAAK,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,GAAG,cAAc,CAAC,CAAC,EAAE,IAAI,EAAE,SAAS,CAAC,CAAA;AA4CjJ,eAAe,GAAG,CAAA"}

71
apps/web5-dwn/node_modules/it-map/dist/src/index.js generated vendored Normal file
View File

@@ -0,0 +1,71 @@
/**
* @packageDocumentation
*
* Convert one value from an (async)iterator into another.
*
* @example
*
* ```javascript
* import map from 'it-map'
*
* // This can also be an iterator, generator, etc
* const values = [0, 1, 2, 3, 4]
*
* const result = map(values, (val, index) => val++)
*
* console.info(result) // [1, 2, 3, 4, 5]
* ```
*
* Async sources and transforms must be awaited:
*
* ```javascript
* import map from 'it-map'
*
* const values = async function * () {
* yield * [0, 1, 2, 3, 4]
* }
*
* const result = await map(values(), async (val, index) => val++)
*
* console.info(result) // [1, 2, 3, 4, 5]
* ```
*/
import peek from 'it-peekable';
function isAsyncIterable(thing) {
return thing[Symbol.asyncIterator] != null;
}
function map(source, func) {
let index = 0;
if (isAsyncIterable(source)) {
return (async function* () {
for await (const val of source) {
yield func(val, index++);
}
})();
}
// if mapping function returns a promise we have to return an async generator
const peekable = peek(source);
const { value, done } = peekable.next();
if (done === true) {
return (function* () { }());
}
const res = func(value, index++);
// @ts-expect-error .then is not present on O
if (typeof res.then === 'function') {
return (async function* () {
yield await res;
for (const val of peekable) {
yield func(val, index++);
}
})();
}
const fn = func;
return (function* () {
yield res;
for (const val of peekable) {
yield fn(val, index++);
}
})();
}
export default map;
//# sourceMappingURL=index.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AAEH,OAAO,IAAI,MAAM,aAAa,CAAA;AAE9B,SAAS,eAAe,CAAM,KAAU;IACtC,OAAO,KAAK,CAAC,MAAM,CAAC,aAAa,CAAC,IAAI,IAAI,CAAA;AAC5C,CAAC;AASD,SAAS,GAAG,CAAS,MAAsC,EAAE,IAA+C;IAC1G,IAAI,KAAK,GAAG,CAAC,CAAA;IAEb,IAAI,eAAe,CAAC,MAAM,CAAC,EAAE,CAAC;QAC5B,OAAO,CAAC,KAAK,SAAU,CAAC;YACtB,IAAI,KAAK,EAAE,MAAM,GAAG,IAAI,MAAM,EAAE,CAAC;gBAC/B,MAAM,IAAI,CAAC,GAAG,EAAE,KAAK,EAAE,CAAC,CAAA;YAC1B,CAAC;QACH,CAAC,CAAC,EAAE,CAAA;IACN,CAAC;IAED,6EAA6E;IAC7E,MAAM,QAAQ,GAAG,IAAI,CAAC,MAAM,CAAC,CAAA;IAC7B,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,GAAG,QAAQ,CAAC,IAAI,EAAE,CAAA;IAEvC,IAAI,IAAI,KAAK,IAAI,EAAE,CAAC;QAClB,OAAO,CAAC,QAAS,CAAC,MAAK,CAAC,EAAE,CAAC,CAAA;IAC7B,CAAC;IAED,MAAM,GAAG,GAAG,IAAI,CAAC,KAAK,EAAE,KAAK,EAAE,CAAC,CAAA;IAEhC,6CAA6C;IAC7C,IAAI,OAAO,GAAG,CAAC,IAAI,KAAK,UAAU,EAAE,CAAC;QACnC,OAAO,CAAC,KAAK,SAAU,CAAC;YACtB,MAAM,MAAM,GAAG,CAAA;YAEf,KAAK,MAAM,GAAG,IAAI,QAAQ,EAAE,CAAC;gBAC3B,MAAM,IAAI,CAAC,GAAG,EAAE,KAAK,EAAE,CAAC,CAAA;YAC1B,CAAC;QACH,CAAC,CAAC,EAAE,CAAA;IACN,CAAC;IAED,MAAM,EAAE,GAAG,IAAoC,CAAA;IAE/C,OAAO,CAAC,QAAS,CAAC;QAChB,MAAM,GAAQ,CAAA;QAEd,KAAK,MAAM,GAAG,IAAI,QAAQ,EAAE,CAAC;YAC3B,MAAM,EAAE,CAAC,GAAG,EAAE,KAAK,EAAE,CAAC,CAAA;QACxB,CAAC;IACH,CAAC,CAAC,EAAE,CAAA;AACN,CAAC;AAED,eAAe,GAAG,CAAA"}

146
apps/web5-dwn/node_modules/it-map/package.json generated vendored Normal file
View File

@@ -0,0 +1,146 @@
{
"name": "it-map",
"version": "3.1.4",
"description": "Maps the values yielded by an async iterator",
"author": "Alex Potsides <alex@achingbrain.net>",
"license": "Apache-2.0 OR MIT",
"homepage": "https://github.com/achingbrain/it/tree/main/packages/it-map#readme",
"repository": {
"type": "git",
"url": "git+https://github.com/achingbrain/it.git"
},
"bugs": {
"url": "https://github.com/achingbrain/it/issues"
},
"publishConfig": {
"access": "public",
"provenance": true
},
"type": "module",
"types": "./dist/src/index.d.ts",
"files": [
"src",
"dist",
"!dist/test",
"!**/*.tsbuildinfo"
],
"exports": {
".": {
"types": "./dist/src/index.d.ts",
"import": "./dist/src/index.js"
}
},
"release": {
"branches": [
"main"
],
"plugins": [
[
"@semantic-release/commit-analyzer",
{
"preset": "conventionalcommits",
"releaseRules": [
{
"breaking": true,
"release": "major"
},
{
"revert": true,
"release": "patch"
},
{
"type": "feat",
"release": "minor"
},
{
"type": "fix",
"release": "patch"
},
{
"type": "docs",
"release": "patch"
},
{
"type": "test",
"release": "patch"
},
{
"type": "deps",
"release": "patch"
},
{
"scope": "no-release",
"release": false
}
]
}
],
[
"@semantic-release/release-notes-generator",
{
"preset": "conventionalcommits",
"presetConfig": {
"types": [
{
"type": "feat",
"section": "Features"
},
{
"type": "fix",
"section": "Bug Fixes"
},
{
"type": "chore",
"section": "Trivial Changes"
},
{
"type": "docs",
"section": "Documentation"
},
{
"type": "deps",
"section": "Dependencies"
},
{
"type": "test",
"section": "Tests"
}
]
}
}
],
"@semantic-release/changelog",
"@semantic-release/npm",
"@semantic-release/github",
[
"@semantic-release/git",
{
"assets": [
"CHANGELOG.md",
"package.json"
]
}
]
]
},
"scripts": {
"build": "aegir build",
"lint": "aegir lint",
"dep-check": "aegir dep-check",
"clean": "aegir clean",
"test": "aegir test",
"test:node": "aegir test -t node --cov",
"test:chrome": "aegir test -t browser --cov",
"test:chrome-webworker": "aegir test -t webworker",
"test:firefox": "aegir test -t browser -- --browser firefox",
"test:firefox-webworker": "aegir test -t webworker -- --browser firefox",
"release": "aegir release"
},
"dependencies": {
"it-peekable": "^3.0.0"
},
"devDependencies": {
"aegir": "^47.0.16",
"it-all": "^3.0.0"
}
}

90
apps/web5-dwn/node_modules/it-map/src/index.ts generated vendored Normal file
View File

@@ -0,0 +1,90 @@
/**
* @packageDocumentation
*
* Convert one value from an (async)iterator into another.
*
* @example
*
* ```javascript
* import map from 'it-map'
*
* // This can also be an iterator, generator, etc
* const values = [0, 1, 2, 3, 4]
*
* const result = map(values, (val, index) => val++)
*
* console.info(result) // [1, 2, 3, 4, 5]
* ```
*
* Async sources and transforms must be awaited:
*
* ```javascript
* import map from 'it-map'
*
* const values = async function * () {
* yield * [0, 1, 2, 3, 4]
* }
*
* const result = await map(values(), async (val, index) => val++)
*
* console.info(result) // [1, 2, 3, 4, 5]
* ```
*/
import peek from 'it-peekable'
function isAsyncIterable <T> (thing: any): thing is AsyncIterable<T> {
return thing[Symbol.asyncIterator] != null
}
/**
* Takes an (async) iterable and returns one with each item mapped by the passed
* function
*/
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, index++)
}
})()
}
// if mapping function returns a promise we have to return an async generator
const peekable = peek(source)
const { value, done } = peekable.next()
if (done === true) {
return (function * () {}())
}
const res = func(value, index++)
// @ts-expect-error .then is not present on O
if (typeof res.then === 'function') {
return (async function * () {
yield await res
for (const val of peekable) {
yield func(val, index++)
}
})()
}
const fn = func as (val: I, index: number) => O
return (function * () {
yield res as O
for (const val of peekable) {
yield fn(val, index++)
}
})()
}
export default map