Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Description

## Summary of Changes

## Related Issue

## Type of Change

- [ ] Bug fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)
- [ ] This change requires a documentation update

# Checklist:

- [ ] I have performed a self-review of my code
- [ ] I have made corresponding changes to the documentation
- [ ] My changes generate no new warnings
- [ ] I have added or refactored the necessary tests that prove my fix is effective or that my feature works
- [ ] I have run the `yarn build` script in order to update the `/dist` folder
67 changes: 67 additions & 0 deletions .github/workflows/lint-test-build-pull-request.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
name: Lint, Test, and Build Pull Request
on:
pull_request:
branches: main
jobs:
lint:
runs-on: ubuntu-latest
name: ES Lint
strategy:
matrix:
node-version: ["18.*"]
steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Use node version ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}

- name: Install modules
run: yarn install

- name: Run eslint
run: yarn lint

test:
runs-on: ubuntu-latest
name: Test
strategy:
matrix:
node-version: ["18.*"]
steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Use node version ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}

- name: Install modules
run: yarn install

- name: Run tests
run: yarn test

build:
runs-on: ubuntu-latest
name: Build
strategy:
matrix:
node-version: ["18.*"]
steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Use node version ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}

- name: Install modules
run: yarn install

- name: Build package
run: yarn build
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/node_modules
yarn-error.log
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
# async-iterators
A JavaScript utility library for asynchrous array iteration.

A TypeScript utility library for asynchronous array iteration.
11 changes: 11 additions & 0 deletions dist/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export { default as every } from "./src/every";
export { default as filter } from "./src/filter";
export { default as find } from "./src/find";
export { default as findIndex } from "./src/findIndex";
export { default as findLast } from "./src/findLast";
export { default as findLastIndex } from "./src/findLastIndex";
export { default as map } from "./src/map";
export { default as mapParallel } from "./src/mapParallel";
export { default as reduce } from "./src/reduce";
export { default as reduceRight } from "./src/reduceRight";
export { default as some } from "./src/some";
28 changes: 28 additions & 0 deletions dist/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.some = exports.reduceRight = exports.reduce = exports.mapParallel = exports.map = exports.findLastIndex = exports.findLast = exports.findIndex = exports.find = exports.filter = exports.every = void 0;
var every_1 = require("./src/every");
Object.defineProperty(exports, "every", { enumerable: true, get: function () { return __importDefault(every_1).default; } });
var filter_1 = require("./src/filter");
Object.defineProperty(exports, "filter", { enumerable: true, get: function () { return __importDefault(filter_1).default; } });
var find_1 = require("./src/find");
Object.defineProperty(exports, "find", { enumerable: true, get: function () { return __importDefault(find_1).default; } });
var findIndex_1 = require("./src/findIndex");
Object.defineProperty(exports, "findIndex", { enumerable: true, get: function () { return __importDefault(findIndex_1).default; } });
var findLast_1 = require("./src/findLast");
Object.defineProperty(exports, "findLast", { enumerable: true, get: function () { return __importDefault(findLast_1).default; } });
var findLastIndex_1 = require("./src/findLastIndex");
Object.defineProperty(exports, "findLastIndex", { enumerable: true, get: function () { return __importDefault(findLastIndex_1).default; } });
var map_1 = require("./src/map");
Object.defineProperty(exports, "map", { enumerable: true, get: function () { return __importDefault(map_1).default; } });
var mapParallel_1 = require("./src/mapParallel");
Object.defineProperty(exports, "mapParallel", { enumerable: true, get: function () { return __importDefault(mapParallel_1).default; } });
var reduce_1 = require("./src/reduce");
Object.defineProperty(exports, "reduce", { enumerable: true, get: function () { return __importDefault(reduce_1).default; } });
var reduceRight_1 = require("./src/reduceRight");
Object.defineProperty(exports, "reduceRight", { enumerable: true, get: function () { return __importDefault(reduceRight_1).default; } });
var some_1 = require("./src/some");
Object.defineProperty(exports, "some", { enumerable: true, get: function () { return __importDefault(some_1).default; } });
13 changes: 13 additions & 0 deletions dist/src/every.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/**
* {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/every|MDN Documentation Array.prototype.every}
*
* @static
* @since 1.0.0
* @param {T[]} array
* @param {(value: T, index: number) => Promise<boolean>} iteratee
* @returns {Promise<boolean>}
* @example
* const array = [3, 3, 3];
* const allThree = await every(array, async (value) => value === 3);
*/
export default function every<T>(array: T[], iteratee: (value: T, index: number) => Promise<boolean>): Promise<boolean>;
27 changes: 27 additions & 0 deletions dist/src/every.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = every;
/**
* {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/every|MDN Documentation Array.prototype.every}
*
* @static
* @since 1.0.0
* @param {T[]} array
* @param {(value: T, index: number) => Promise<boolean>} iteratee
* @returns {Promise<boolean>}
* @example
* const array = [3, 3, 3];
* const allThree = await every(array, async (value) => value === 3);
*/
async function every(array, iteratee) {
if (!Array.isArray(array) || !array?.length)
return false;
for (let index = 0; index < array.length; index++) {
const element = array[index];
const result = await iteratee(element, index);
if (!result) {
return false;
}
}
return true;
}
13 changes: 13 additions & 0 deletions dist/src/filter.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/**
* {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter|MDN Documentation Array.prototype.filter}
*
* @static
* @since 1.0.0
* @param {T[]} array
* @param {(value: T, index: number) => Promise<boolean>} iteratee
* @returns {Promise<T[]>}
* @example
* const array = [1, 2, 3];
* const onlyThree = await filter(array, async (value) => value === 3);
*/
export default function filter<T>(array: T[], iteratee: (value: T, index: number) => Promise<boolean>): Promise<T[]>;
28 changes: 28 additions & 0 deletions dist/src/filter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = filter;
/**
* {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter|MDN Documentation Array.prototype.filter}
*
* @static
* @since 1.0.0
* @param {T[]} array
* @param {(value: T, index: number) => Promise<boolean>} iteratee
* @returns {Promise<T[]>}
* @example
* const array = [1, 2, 3];
* const onlyThree = await filter(array, async (value) => value === 3);
*/
async function filter(array, iteratee) {
if (!Array.isArray(array) || !array?.length)
return [];
const results = [];
for (let index = 0; index < array.length; index++) {
const element = array[index];
const result = await iteratee(element, index);
if (result) {
results.push(element);
}
}
return results;
}
13 changes: 13 additions & 0 deletions dist/src/find.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/**
* {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find|MDN Documentation Array.prototype.find}
*
* @static
* @since 1.0.0
* @param {T[]} array
* @param {(value: T, index: number) => Promise<boolean>} iteratee
* @returns {Promise<T | undefined>}
* @example
* const array = [1, 2, 3];
* const foundValue = await find(array, async (value) => value === 3);
*/
export default function find<T>(array: T[], iteratee: (value: T, index: number) => Promise<boolean>): Promise<T | undefined>;
27 changes: 27 additions & 0 deletions dist/src/find.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = find;
/**
* {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find|MDN Documentation Array.prototype.find}
*
* @static
* @since 1.0.0
* @param {T[]} array
* @param {(value: T, index: number) => Promise<boolean>} iteratee
* @returns {Promise<T | undefined>}
* @example
* const array = [1, 2, 3];
* const foundValue = await find(array, async (value) => value === 3);
*/
async function find(array, iteratee) {
if (!Array.isArray(array) || !array?.length)
return undefined;
for (let index = 0; index < array.length; index++) {
const element = array[index];
const result = await iteratee(element, index);
if (result) {
return element;
}
}
return undefined;
}
13 changes: 13 additions & 0 deletions dist/src/findIndex.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/**
* {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/findIndex|MDN Documentation Array.prototype.findIndex}
*
* @static
* @since 1.0.0
* @param {T[]} array
* @param {(value: T, index: number) => Promise<boolean>} iteratee
* @returns {Promise<number>}
* @example
* const array = [1, 2, 3];
* const foundValueIndex = await findIndex(array, async (value) => value === 3);
*/
export default function findIndex<T>(array: T[], iteratee: (value: T, index: number) => Promise<boolean>): Promise<number>;
27 changes: 27 additions & 0 deletions dist/src/findIndex.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = findIndex;
/**
* {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/findIndex|MDN Documentation Array.prototype.findIndex}
*
* @static
* @since 1.0.0
* @param {T[]} array
* @param {(value: T, index: number) => Promise<boolean>} iteratee
* @returns {Promise<number>}
* @example
* const array = [1, 2, 3];
* const foundValueIndex = await findIndex(array, async (value) => value === 3);
*/
async function findIndex(array, iteratee) {
if (!Array.isArray(array) || !array?.length)
return -1;
for (let index = 0; index < array.length; index++) {
const element = array[index];
const result = await iteratee(element, index);
if (result) {
return index;
}
}
return -1;
}
13 changes: 13 additions & 0 deletions dist/src/findLast.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/**
* {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/findLast|MDN Documentation Array.prototype.findLast}
*
* @static
* @since 1.0.0
* @param {T[]} array
* @param {(value: T, index: number) => Promise<boolean>} iteratee
* @returns {Promise<T | undefined>}
* @example
* const array = [1, 2, 3];
* const foundValue = await findLast(array, async (value) => value === 3);
*/
export default function findLast<T>(array: T[], iteratee: (value: T, index: number) => Promise<boolean>): Promise<T | undefined>;
27 changes: 27 additions & 0 deletions dist/src/findLast.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = findLast;
/**
* {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/findLast|MDN Documentation Array.prototype.findLast}
*
* @static
* @since 1.0.0
* @param {T[]} array
* @param {(value: T, index: number) => Promise<boolean>} iteratee
* @returns {Promise<T | undefined>}
* @example
* const array = [1, 2, 3];
* const foundValue = await findLast(array, async (value) => value === 3);
*/
async function findLast(array, iteratee) {
if (!Array.isArray(array) || !array?.length)
return undefined;
for (let index = array.length - 1; index >= 0; index--) {
const element = array[index];
const result = await iteratee(element, index);
if (result) {
return element;
}
}
return undefined;
}
13 changes: 13 additions & 0 deletions dist/src/findLastIndex.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/**
* {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/findLastIndex|MDN Documentation Array.prototype.findLastIndex}
*
* @static
* @since 1.0.0
* @param {T[]} array
* @param {(value: T, index: number) => Promise<boolean>} iteratee
* @returns {Promise<number>}
* @example
* const array = [1, 2, 3];
* const foundValueIndex = await findLastIndex(array, async (value) => value === 3);
*/
export default function findLastIndex<T>(array: T[], iteratee: (value: T, index: number) => Promise<boolean>): Promise<number>;
27 changes: 27 additions & 0 deletions dist/src/findLastIndex.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = findLastIndex;
/**
* {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/findLastIndex|MDN Documentation Array.prototype.findLastIndex}
*
* @static
* @since 1.0.0
* @param {T[]} array
* @param {(value: T, index: number) => Promise<boolean>} iteratee
* @returns {Promise<number>}
* @example
* const array = [1, 2, 3];
* const foundValueIndex = await findLastIndex(array, async (value) => value === 3);
*/
async function findLastIndex(array, iteratee) {
if (!Array.isArray(array) || !array?.length)
return -1;
for (let index = array.length - 1; index >= 0; index--) {
const element = array[index];
const result = await iteratee(element, index);
if (result) {
return index;
}
}
return -1;
}
Loading