From e3d7111442f34dfaa3ae996a680b1be6cf39a3d3 Mon Sep 17 00:00:00 2001 From: Charles Opute Odili Date: Sun, 18 Feb 2024 06:49:19 -0700 Subject: [PATCH 01/37] ready to publish --- README.md | 15 +++++++++++---- package.json | 2 +- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index f0dcb33..391b1f5 100644 --- a/README.md +++ b/README.md @@ -45,7 +45,7 @@ JS challenge by @thdxr on X.com


`n-tuple-array` solution code
-[](./assets/demo-classic.svg) +[](https://github.com/chalu/n-tuple-array/blob/main/src/demo/demo-classic.ts#L6-L40)

`n-tuple-array` n-tuple-array solution demo
@@ -56,12 +56,13 @@ JS challenge by @thdxr on X.com
## Setup & Usage ```bash -npm install n-tuple-array +npm install @chalu/n-tuple-array ``` ```javascript import { tuplesFromArray } from 'n-tuple-array'; +// some setup const numbers = Array.from({length: 100}, (_, i) => i + 1); const isEven = (item) => { if ( @@ -73,8 +74,14 @@ const isEven = (item) => { return true; }; -for (const triplets of tuplesFromArray({list: numbers, maxItems: 3, match: isEven})) { - console.log(triplets); +// use the lib +const quintetIterator = tuplesFromArray({ + list: numbers, maxItems: 5, match: isEven +}); + +for (const quintet of quintetIterator) { + // prints [ 2, 4, 6, 8, 10 ] ... [ 92, 94, 96, 98, 100 ] + console.log(quintet); } ``` diff --git a/package.json b/package.json index d98121b..897eb01 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "name": "n-tuple-array", + "name": "@chalu/n-tuple-array", "version": "0.1", "description": "Get a specified amount of items when iterating over a JavaScript array, instead of just a single item that native arrays provide!", "main": "dist/index.js", From 51add333de5845b97eacb0b26a00b1579e90bbca Mon Sep 17 00:00:00 2001 From: Charles Opute Odili Date: Sun, 18 Feb 2024 07:57:16 -0700 Subject: [PATCH 02/37] add CD workflow --- .github/workflows/CD.yaml | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 .github/workflows/CD.yaml diff --git a/.github/workflows/CD.yaml b/.github/workflows/CD.yaml new file mode 100644 index 0000000..8ce8733 --- /dev/null +++ b/.github/workflows/CD.yaml @@ -0,0 +1,24 @@ +name: CD +on: + pull_request: + types: [ closed ] + +jobs: + build-and-test: + if: github.event.pull_request.base.ref == 'main' && github.event.pull_request.merged == true + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Print ENV + run: | + echo ${ github.event.pull_request.base.ref } + echo ${ github.event.pull_request } + + # - name: Publish to Registry + # uses: JS-DevTools/npm-publish@v3 + # with: + # token: ${{ secrets.NPM_TOKEN }} + \ No newline at end of file From 16d3398acf08593eb0e561490632e0bff52eae05 Mon Sep 17 00:00:00 2001 From: Charles Opute Odili Date: Sun, 18 Feb 2024 07:58:50 -0700 Subject: [PATCH 03/37] lint only changed TS or JS files --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 897eb01..aa2d186 100644 --- a/package.json +++ b/package.json @@ -11,8 +11,8 @@ "build": "tsc", "prebuild": "rm -rf dist/*", "postbuild": "rm -rf dist/demo/*.d.*", - "lint": "xo", - "lint:fix": "xo --fix", + "lint": "xo $(git diff --name-only --diff-filter=d HEAD | grep -E '\\.(ts|js)$' | xargs)", + "lint:fix": "xo --fix $(git diff --name-only --diff-filter=d HEAD | grep -E '\\.(ts|js)$' | xargs)", "test": "jest --runInBand", "pretest": "pnpm lint && pnpm build", "test:ci": "jest --ci --config='./jest.config.ci.ts'", From d0de98d58e799a93706bee0176614f6388607658 Mon Sep 17 00:00:00 2001 From: Charles Opute Odili Date: Sun, 18 Feb 2024 08:03:40 -0700 Subject: [PATCH 04/37] fix CD job name --- .github/workflows/CD.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/CD.yaml b/.github/workflows/CD.yaml index 8ce8733..87083f6 100644 --- a/.github/workflows/CD.yaml +++ b/.github/workflows/CD.yaml @@ -4,7 +4,7 @@ on: types: [ closed ] jobs: - build-and-test: + publish-to-registry: if: github.event.pull_request.base.ref == 'main' && github.event.pull_request.merged == true runs-on: ubuntu-latest From 83348c4aadee82d7b34f12283c3329a135ef8a2c Mon Sep 17 00:00:00 2001 From: Charles Opute Odili Date: Sun, 18 Feb 2024 08:09:34 -0700 Subject: [PATCH 05/37] run CI only on PR to dev or main --- .github/workflows/CI.yaml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/.github/workflows/CI.yaml b/.github/workflows/CI.yaml index 7a5502b..d355aee 100644 --- a/.github/workflows/CI.yaml +++ b/.github/workflows/CI.yaml @@ -1,9 +1,5 @@ name: CI on: - push: - branches: - - "!main" - - "*" pull_request: branches: - "dev" From d8979e9c8dfdbed2591ee53ad4092cd486544b9f Mon Sep 17 00:00:00 2001 From: Charles Opute Odili Date: Sun, 18 Feb 2024 08:26:19 -0700 Subject: [PATCH 06/37] dry run package publishing --- .github/workflows/CD.yaml | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/.github/workflows/CD.yaml b/.github/workflows/CD.yaml index 87083f6..324e1ff 100644 --- a/.github/workflows/CD.yaml +++ b/.github/workflows/CD.yaml @@ -12,13 +12,9 @@ jobs: - name: Checkout uses: actions/checkout@v4 - - name: Print ENV - run: | - echo ${ github.event.pull_request.base.ref } - echo ${ github.event.pull_request } - - # - name: Publish to Registry - # uses: JS-DevTools/npm-publish@v3 - # with: - # token: ${{ secrets.NPM_TOKEN }} + - name: Publish to Registry + uses: JS-DevTools/npm-publish@v3 + with: + token: ${{ secrets.NPM_TOKEN }} + dry-run: true \ No newline at end of file From 2b39e3e8075486c0f8fe4e1443626d3f8c171d32 Mon Sep 17 00:00:00 2001 From: Charles Opute Odili Date: Sun, 18 Feb 2024 08:40:31 -0700 Subject: [PATCH 07/37] dry run publish on dev branch --- .github/workflows/CD.yaml | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/CD.yaml b/.github/workflows/CD.yaml index 324e1ff..d7adac2 100644 --- a/.github/workflows/CD.yaml +++ b/.github/workflows/CD.yaml @@ -5,7 +5,7 @@ on: jobs: publish-to-registry: - if: github.event.pull_request.base.ref == 'main' && github.event.pull_request.merged == true + if: github.event.pull_request.base.ref == 'dev' && github.event.pull_request.merged == true runs-on: ubuntu-latest steps: diff --git a/package.json b/package.json index aa2d186..7224684 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@chalu/n-tuple-array", - "version": "0.1", + "version": "0.0.1", "description": "Get a specified amount of items when iterating over a JavaScript array, instead of just a single item that native arrays provide!", "main": "dist/index.js", "types": "dist/index.d.ts", From 0cfbc0326f87e4318d24c442b9d0eee635c1e1e2 Mon Sep 17 00:00:00 2001 From: Charles Opute Odili Date: Sun, 18 Feb 2024 10:53:02 -0700 Subject: [PATCH 08/37] get production ready --- .github/workflows/CI.yaml | 3 ++ .github/workflows/snyk.yml | 14 ++++++++ README.md | 2 +- __tests__/smoke.test.js | 2 +- dist/{ => cjs}/index.js | 0 dist/{ => cjs/types}/index.d.ts | 1 + dist/cjs/types/index.d.ts.map | 1 + dist/demo/demo-basics.js | 34 ------------------ dist/demo/demo-classic.js | 32 ----------------- dist/demo/demo-utils.js | 36 ------------------- dist/esm/index.mjs | 62 +++++++++++++++++++++++++++++++++ dist/esm/types/index.d.ts | 13 +++++++ dist/esm/types/index.d.ts.map | 1 + package.json | 38 +++++++++++++++----- tsconfig.base.json | 20 +++++++++++ tsconfig.cjs.json | 14 ++++++++ tsconfig.esm.json | 14 ++++++++ tsconfig.json | 24 ------------- 18 files changed, 174 insertions(+), 137 deletions(-) create mode 100644 .github/workflows/snyk.yml rename dist/{ => cjs}/index.js (100%) rename dist/{ => cjs/types}/index.d.ts (92%) create mode 100644 dist/cjs/types/index.d.ts.map delete mode 100644 dist/demo/demo-basics.js delete mode 100644 dist/demo/demo-classic.js delete mode 100644 dist/demo/demo-utils.js create mode 100644 dist/esm/index.mjs create mode 100644 dist/esm/types/index.d.ts create mode 100644 dist/esm/types/index.d.ts.map create mode 100644 tsconfig.base.json create mode 100644 tsconfig.cjs.json create mode 100644 tsconfig.esm.json delete mode 100644 tsconfig.json diff --git a/.github/workflows/CI.yaml b/.github/workflows/CI.yaml index d355aee..30a9629 100644 --- a/.github/workflows/CI.yaml +++ b/.github/workflows/CI.yaml @@ -1,5 +1,8 @@ name: CI on: + push: + branches-ignore: + - "main" pull_request: branches: - "dev" diff --git a/.github/workflows/snyk.yml b/.github/workflows/snyk.yml new file mode 100644 index 0000000..199ccdd --- /dev/null +++ b/.github/workflows/snyk.yml @@ -0,0 +1,14 @@ +name: Security Check + +on: [push, pull_request] + +jobs: + security-audit: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Check for Security Vulnerabilities + uses: snyk/actions/node@master + env: + SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }} \ No newline at end of file diff --git a/README.md b/README.md index 391b1f5..9fcee3b 100644 --- a/README.md +++ b/README.md @@ -60,7 +60,7 @@ npm install @chalu/n-tuple-array ``` ```javascript -import { tuplesFromArray } from 'n-tuple-array'; +const { tuplesFromArray } = require('@chalu/n-tuple-array'); // some setup const numbers = Array.from({length: 100}, (_, i) => i + 1); diff --git a/__tests__/smoke.test.js b/__tests__/smoke.test.js index 5a81cb3..acd34ce 100644 --- a/__tests__/smoke.test.js +++ b/__tests__/smoke.test.js @@ -1,4 +1,4 @@ -const {tuplesFromArray, InvalidInvocationParameterError} = require('../dist/index.js'); +const {tuplesFromArray, InvalidInvocationParameterError} = require('../dist/cjs/index.js'); describe('Smoke Tests', () => { it('should throw if input array is not specified', () => { diff --git a/dist/index.js b/dist/cjs/index.js similarity index 100% rename from dist/index.js rename to dist/cjs/index.js diff --git a/dist/index.d.ts b/dist/cjs/types/index.d.ts similarity index 92% rename from dist/index.d.ts rename to dist/cjs/types/index.d.ts index aea6b25..cb5aa72 100644 --- a/dist/index.d.ts +++ b/dist/cjs/types/index.d.ts @@ -10,3 +10,4 @@ export declare class InvalidInvocationParameterError extends Error { } export declare const tuplesFromArray: (config: TupleConfig) => Iterable>; export default tuplesFromArray; +//# sourceMappingURL=index.d.ts.map \ No newline at end of file diff --git a/dist/cjs/types/index.d.ts.map b/dist/cjs/types/index.d.ts.map new file mode 100644 index 0000000..8d87987 --- /dev/null +++ b/dist/cjs/types/index.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAAA,KAAK,IAAI,CAAC,CAAC,IAAI,CAAC,GAAG,SAAS,CAAC;AAC7B,KAAK,KAAK,CAAC,CAAC,IAAI,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;AAG/B,MAAM,MAAM,OAAO,CAAC,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,GAAG,OAAO,KAAK,OAAO,CAAC;AACxD,MAAM,MAAM,WAAW,CAAC,CAAC,IAAI;IAC5B,IAAI,EAAE,CAAC,EAAE,CAAC;IACV,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,KAAK,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC;CACnB,CAAC;AAEF,qBAAa,+BAAgC,SAAQ,KAAK;CAAG;AAqB7D,eAAO,MAAM,eAAe,mDAmD3B,CAAC;AAEF,eAAe,eAAe,CAAC"} \ No newline at end of file diff --git a/dist/demo/demo-basics.js b/dist/demo/demo-basics.js deleted file mode 100644 index 6f01236..0000000 --- a/dist/demo/demo-basics.js +++ /dev/null @@ -1,34 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -const index_1 = require("../index"); -const demo_utils_1 = require("./demo-utils"); -console.log('----- Example 1 [10 Hex in twos. Used default param values] ------'); -for (const hexPair of (0, index_1.tuplesFromArray)({ list: (0, demo_utils_1.hexadecimals)(10) })) { - console.log(hexPair); -} -console.log('\n----- Example 2 [30 Hex in fives. Specified maxItems] ------'); -for (const hexQuintet of (0, index_1.tuplesFromArray)({ list: (0, demo_utils_1.hexadecimals)(30), maxItems: 5 })) { - console.log(hexQuintet); -} -console.log('\n----- Example 3 [Dates in twos. Filtered in by a match function] ------'); -// Create an array of 50 elements which include some dates -const data = [...(0, demo_utils_1.hexadecimals)(20), ...(0, demo_utils_1.dates)(10), ...(0, demo_utils_1.uuids)(20)]; -// Use a basic/weak shuffle algo to shuffle the array items -data.sort(() => Math.random() - 0.5); -for (const dateTriplet of (0, index_1.tuplesFromArray)({ list: data, match: demo_utils_1.isDate })) { - console.log(dateTriplet); -} -console.log('\n----- Example 4 [Tuples can be "remainders", see the last array/tuple] ------'); -for (const idTriplets of (0, index_1.tuplesFromArray)({ list: (0, demo_utils_1.uuids)(8), maxItems: 3 })) { - console.log(idTriplets); -} -const dozenHexValues = (0, demo_utils_1.hexadecimals)(12); -const hexIterable = (0, index_1.tuplesFromArray)({ list: dozenHexValues, maxItems: 2 }); -const hexPairs = Array.from(hexIterable); -console.log('Array.from( tuplesFromArray(...) ) is an Array:', Array.isArray(hexPairs)); -// Use native Array methods -hexPairs - .map(pair => pair.toString().toUpperCase().split(',')) - .forEach(pair => { - console.log(pair); -}); diff --git a/dist/demo/demo-classic.js b/dist/demo/demo-classic.js deleted file mode 100644 index cbcab33..0000000 --- a/dist/demo/demo-classic.js +++ /dev/null @@ -1,32 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -const index_1 = require("../index"); -const demo_utils_1 = require("./demo-utils"); -const processItem = async (item) => { - await (0, demo_utils_1.delay)(Math.random() * 500); // Simulate some async workload - const processed = (item instanceof Date && (0, demo_utils_1.isDate)(item)) ? demo_utils_1.canadaDateFormat.format(item) : item; - return processed; -}; -const parallelPool = async (tasks, prarallelSize) => { - const processed = []; - const parallelSizeAwareIterable = (0, index_1.tuplesFromArray)({ - list: tasks, - maxItems: prarallelSize, - }); - let count = 1; - for await (const cohort of parallelSizeAwareIterable) { - const results = await Promise.allSettled(cohort.map(async (itm) => processItem(itm))); - processed.push(...results); - console.log(`processed ${(0, demo_utils_1.formatCount)(count)} batch of <= ${prarallelSize} items`); - if ((count * prarallelSize) >= tasks.length) { - console.log('DONE!'); - } - count += 1; - } - return processed; -}; -(async () => { - const canadianDates = await parallelPool((0, demo_utils_1.dates)(12), 3); - console.log('-------------------'); - console.log(canadianDates); -})(); diff --git a/dist/demo/demo-utils.js b/dist/demo/demo-utils.js deleted file mode 100644 index ef25db0..0000000 --- a/dist/demo/demo-utils.js +++ /dev/null @@ -1,36 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.delay = exports.formatCount = exports.canadaDateFormat = exports.isDate = exports.hexadecimals = exports.dates = exports.uuids = void 0; -const faker_1 = require("@faker-js/faker"); -/** - * Some Helper Functions - */ -const factory = (generator, howMany = 20) => faker_1.simpleFaker.helpers.multiple(generator, { count: howMany }); -const uuids = (howMany) => factory(faker_1.simpleFaker.string.uuid, howMany); -exports.uuids = uuids; -const dates = (howMany) => factory(faker_1.simpleFaker.date.birthdate, howMany); -exports.dates = dates; -const hexadecimals = (howMany) => factory(faker_1.simpleFaker.string.hexadecimal, howMany); -exports.hexadecimals = hexadecimals; -const isDate = (date) => (date instanceof Date) && !Number.isNaN(date.getTime()); -exports.isDate = isDate; -exports.canadaDateFormat = new Intl.DateTimeFormat('en-CA', { - dateStyle: 'medium', -}); -const plural = new Intl.PluralRules('en-US', { type: 'ordinal' }); -const suffixes = new Map([ - ['one', 'st'], - ['two', 'nd'], - ['few', 'rd'], - ['other', 'th'], -]); -const formatCount = (n) => { - const rule = plural.select(n); - const suffix = suffixes.get(rule); - return `${n}${suffix}`; -}; -exports.formatCount = formatCount; -const delay = async (ms) => new Promise(resolve => { - setTimeout(resolve, ms); -}); -exports.delay = delay; diff --git a/dist/esm/index.mjs b/dist/esm/index.mjs new file mode 100644 index 0000000..927cbf0 --- /dev/null +++ b/dist/esm/index.mjs @@ -0,0 +1,62 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.tuplesFromArray = exports.InvalidInvocationParameterError = void 0; +class InvalidInvocationParameterError extends Error { +} +exports.InvalidInvocationParameterError = InvalidInvocationParameterError; +const validateParametersOrThrow = (list, maxItems, match) => { + if (!list || !Array.isArray(list)) { + throw new InvalidInvocationParameterError('expected list to be an array'); + } + if (typeof maxItems !== 'number' + || (typeof maxItems === 'number' && maxItems <= 0)) { + const message = 'expected maxItems (when provided) to be a positive integer (1 and above)'; + throw new InvalidInvocationParameterError(message); + } + if (match !== undefined && typeof match !== 'function') { + const message = 'expected match (when provided) to be a function'; + throw new InvalidInvocationParameterError(message); + } +}; +const tuplesFromArray = (config) => { + const { list, match, maxItems = 2 } = config; + validateParametersOrThrow(list, maxItems, match); + let cursor = 0; + const maxItemSize = Number.parseInt(`${maxItems}`, 10); + const proceedNext = () => { + const items = []; + if (cursor >= list.length) { + return { done: true, value: [] }; + } + const endIndex = match === undefined + // A match funtion was provided. Okay to run to array end + // or until we've matched maxItemSize elements + ? Math.min(cursor + maxItemSize, list.length) + // No match function was provided. We should run till we are + // out of items (list.length) or till we gotten the next set + // of maxItemSize items + : list.length; + while (cursor < endIndex) { + const item = list[cursor]; + cursor += 1; + if (match && !match(item)) { + continue; + } + items.push(item); + if (match && items.length === maxItemSize) { + break; + } + } + return { value: items, done: items.length === 0 }; + }; + const iterable = { + [Symbol.iterator]() { + return { + next: proceedNext, + }; + }, + }; + return iterable; +}; +exports.tuplesFromArray = tuplesFromArray; +exports.default = exports.tuplesFromArray; diff --git a/dist/esm/types/index.d.ts b/dist/esm/types/index.d.ts new file mode 100644 index 0000000..cb5aa72 --- /dev/null +++ b/dist/esm/types/index.d.ts @@ -0,0 +1,13 @@ +type Item = T | undefined; +type Value = Array>; +export type Matcher = (item: T | unknown) => boolean; +export type TupleConfig = { + list: T[]; + maxItems?: number; + match?: Matcher; +}; +export declare class InvalidInvocationParameterError extends Error { +} +export declare const tuplesFromArray: (config: TupleConfig) => Iterable>; +export default tuplesFromArray; +//# sourceMappingURL=index.d.ts.map \ No newline at end of file diff --git a/dist/esm/types/index.d.ts.map b/dist/esm/types/index.d.ts.map new file mode 100644 index 0000000..8d87987 --- /dev/null +++ b/dist/esm/types/index.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAAA,KAAK,IAAI,CAAC,CAAC,IAAI,CAAC,GAAG,SAAS,CAAC;AAC7B,KAAK,KAAK,CAAC,CAAC,IAAI,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;AAG/B,MAAM,MAAM,OAAO,CAAC,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,GAAG,OAAO,KAAK,OAAO,CAAC;AACxD,MAAM,MAAM,WAAW,CAAC,CAAC,IAAI;IAC5B,IAAI,EAAE,CAAC,EAAE,CAAC;IACV,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,KAAK,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC;CACnB,CAAC;AAEF,qBAAa,+BAAgC,SAAQ,KAAK;CAAG;AAqB7D,eAAO,MAAM,eAAe,mDAmD3B,CAAC;AAEF,eAAe,eAAe,CAAC"} \ No newline at end of file diff --git a/package.json b/package.json index 7224684..2d79c9b 100644 --- a/package.json +++ b/package.json @@ -1,22 +1,36 @@ { "name": "@chalu/n-tuple-array", "version": "0.0.1", - "description": "Get a specified amount of items when iterating over a JavaScript array, instead of just a single item that native arrays provide!", - "main": "dist/index.js", - "types": "dist/index.d.ts", + "description": "Get a specified amount of items when iterating over a JavaScript array, instead of just a single item that arrays provide!", + "main": "./dist/cjs/index.js", + "types": "./dist/cjs/types/index.d.ts", "files": [ - "/dist" + "dist/**/*" ], + "exports": { + ".": { + "import": { + "types": "./dist/esm/types/index.d.ts", + "default": "./dist/esm/index.mjs" + }, + "require": { + "types": "./dist/cjs/types/index.d.ts", + "default": "./dist/cjs/index.js" + } + } + }, "scripts": { - "build": "tsc", - "prebuild": "rm -rf dist/*", - "postbuild": "rm -rf dist/demo/*.d.*", + "build": "pnpm build:esm && pnpm build:cjs", + "prebuild": "rm -rf dist", + "build:esm": "tsc -p tsconfig.esm.json && mv dist/esm/index.js dist/esm/index.mjs", + "build:cjs": "tsc -p tsconfig.cjs.json", "lint": "xo $(git diff --name-only --diff-filter=d HEAD | grep -E '\\.(ts|js)$' | xargs)", "lint:fix": "xo --fix $(git diff --name-only --diff-filter=d HEAD | grep -E '\\.(ts|js)$' | xargs)", - "test": "jest --runInBand", + "test": "jest", "pretest": "pnpm lint && pnpm build", "test:ci": "jest --ci --config='./jest.config.ci.ts'", - "prepare": "husky" + "prepare": "husky", + "prepack": "pnpm build" }, "keywords": ["array", "tuple", "arrays", "tuples", "iterables", "iterators", "symbol.iterator", "javascript", "typescript"], "author": "Charles Odili ", @@ -32,5 +46,11 @@ "ts-node": "^10.9.2", "typescript": "^5.3.3", "xo": "^0.57.0" + }, + "release": { + "branches": ["main"] + }, + "publishConfig": { + "access": "public" } } diff --git a/tsconfig.base.json b/tsconfig.base.json new file mode 100644 index 0000000..aa3027b --- /dev/null +++ b/tsconfig.base.json @@ -0,0 +1,20 @@ +{ + "compilerOptions": { + "strict": true, + "rootDir": "./src", + "esModuleInterop": true, + "forceConsistentCasingInFileNames": true, + "skipLibCheck": true, + "checkJs": true, + "allowJs": true, + "declaration": true, + "declarationMap": true, + "allowSyntheticDefaultImports": true + }, + "include": [ + "src/**/*" + ], + "exclude": [ + "src/demo/**" + ] +} \ No newline at end of file diff --git a/tsconfig.cjs.json b/tsconfig.cjs.json new file mode 100644 index 0000000..5d35037 --- /dev/null +++ b/tsconfig.cjs.json @@ -0,0 +1,14 @@ +{ + "extends": "./tsconfig.base.json", + "compilerOptions": { + "lib": [ + "ES2022", + "DOM" + ], + "target": "ES2022", + "module": "CommonJS", + "moduleResolution": "Node", + "outDir": "dist/cjs", + "declarationDir": "dist/cjs/types" + } +} \ No newline at end of file diff --git a/tsconfig.esm.json b/tsconfig.esm.json new file mode 100644 index 0000000..8beeb6a --- /dev/null +++ b/tsconfig.esm.json @@ -0,0 +1,14 @@ +{ + "extends": "./tsconfig.base.json", + "compilerOptions": { + "lib": [ + "ES2022", + "DOM" + ], + "target": "ES2022", + "module": "NodeNext", + "moduleResolution": "NodeNext", + "outDir": "dist/esm", + "declarationDir": "dist/esm/types" + } +} \ No newline at end of file diff --git a/tsconfig.json b/tsconfig.json deleted file mode 100644 index f86599f..0000000 --- a/tsconfig.json +++ /dev/null @@ -1,24 +0,0 @@ -{ - "compilerOptions": { - /* Visit https://aka.ms/tsconfig to read more about this file */ - /* Language and Environment */ - "lib": ["ES2022", "dom"], - "target": "ESNext", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */ /* Control what method is used to detect module-format JS files. */ - /* Modules */ - "module": "commonjs", /* Specify what module code is generated. */ - "rootDir": "./src", /* Specify the root folder within your source files. */ - /* Emit */ - "declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */ - "outDir": "./dist", /* Specify an output folder for all emitted files. */ - "esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */ /* Ensure that casing is correct in imports. */ - "moduleResolution": "node", - "resolveJsonModule": true, - /* Type Checking */ - "strict": true, /* Skip type checking all .d.ts files. */ - "noUncheckedIndexedAccess": true, - "skipLibCheck": true - }, - "include": [ - "src/**/*" - ] -} \ No newline at end of file From bbf5f0b2d16115c856b7f4215d3b85256a7e6312 Mon Sep 17 00:00:00 2001 From: Charles Opute Odili Date: Sun, 18 Feb 2024 10:53:40 -0700 Subject: [PATCH 09/37] make a default tsconfig from the ESM config --- tsconfig.base.json | 1 + tsconfig.json | 3 +++ 2 files changed, 4 insertions(+) create mode 100644 tsconfig.json diff --git a/tsconfig.base.json b/tsconfig.base.json index aa3027b..211db10 100644 --- a/tsconfig.base.json +++ b/tsconfig.base.json @@ -9,6 +9,7 @@ "allowJs": true, "declaration": true, "declarationMap": true, + "noUncheckedIndexedAccess": true, "allowSyntheticDefaultImports": true }, "include": [ diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..166936b --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,3 @@ +{ + "extends": "./tsconfig.esm.json" +} \ No newline at end of file From 41ba737f2dc804c64daaa54b0729b74a6be29f02 Mon Sep 17 00:00:00 2001 From: Charles Opute Odili Date: Sun, 18 Feb 2024 12:08:43 -0700 Subject: [PATCH 10/37] dry run release from GHA --- .github/workflows/CD.yaml | 9 +++++++-- package.json | 20 ++++++++++++++++++-- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/.github/workflows/CD.yaml b/.github/workflows/CD.yaml index d7adac2..3966c02 100644 --- a/.github/workflows/CD.yaml +++ b/.github/workflows/CD.yaml @@ -1,10 +1,11 @@ -name: CD +name: Release + on: pull_request: types: [ closed ] jobs: - publish-to-registry: + release: if: github.event.pull_request.base.ref == 'dev' && github.event.pull_request.merged == true runs-on: ubuntu-latest @@ -12,6 +13,10 @@ jobs: - name: Checkout uses: actions/checkout@v4 + - uses: jaywcjlove/github-action-package@main + with: + unset: scripts.prepare + - name: Publish to Registry uses: JS-DevTools/npm-publish@v3 with: diff --git a/package.json b/package.json index 2d79c9b..7b2c5cc 100644 --- a/package.json +++ b/package.json @@ -32,7 +32,17 @@ "prepare": "husky", "prepack": "pnpm build" }, - "keywords": ["array", "tuple", "arrays", "tuples", "iterables", "iterators", "symbol.iterator", "javascript", "typescript"], + "keywords": [ + "array", + "tuple", + "arrays", + "tuples", + "iterables", + "iterators", + "symbol.iterator", + "javascript", + "typescript" + ], "author": "Charles Odili ", "license": "MIT", "devDependencies": { @@ -48,9 +58,15 @@ "xo": "^0.57.0" }, "release": { - "branches": ["main"] + "branches": [ + "main" + ] }, "publishConfig": { "access": "public" + }, + "repository": { + "type": "git", + "url": "https://github.com/chalu/n-tuple-array.git" } } From d706086e39f24bb01df1439cc8ebf9e2f3b466d7 Mon Sep 17 00:00:00 2001 From: Charles Opute Odili Date: Sun, 18 Feb 2024 12:16:44 -0700 Subject: [PATCH 11/37] prune GHA runs --- .github/workflows/CI.yaml | 1 + .github/workflows/snyk.yml | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/CI.yaml b/.github/workflows/CI.yaml index 30a9629..369eac9 100644 --- a/.github/workflows/CI.yaml +++ b/.github/workflows/CI.yaml @@ -3,6 +3,7 @@ on: push: branches-ignore: - "main" + - "dev" pull_request: branches: - "dev" diff --git a/.github/workflows/snyk.yml b/.github/workflows/snyk.yml index 199ccdd..fb3f98f 100644 --- a/.github/workflows/snyk.yml +++ b/.github/workflows/snyk.yml @@ -1,6 +1,6 @@ name: Security Check -on: [push, pull_request] +on: [pull_request] jobs: security-audit: From 0d3d8b1552d9176942640afa2538006bb3be275f Mon Sep 17 00:00:00 2001 From: Charles Opute Odili Date: Sun, 18 Feb 2024 12:24:18 -0700 Subject: [PATCH 12/37] attempt release from GHA --- .github/workflows/CD.yaml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/CD.yaml b/.github/workflows/CD.yaml index 3966c02..8e04669 100644 --- a/.github/workflows/CD.yaml +++ b/.github/workflows/CD.yaml @@ -21,5 +21,4 @@ jobs: uses: JS-DevTools/npm-publish@v3 with: token: ${{ secrets.NPM_TOKEN }} - dry-run: true \ No newline at end of file From 670b7c1fa8e01d9e8a347acbfb14e3439332434e Mon Sep 17 00:00:00 2001 From: Charles Opute Odili Date: Sun, 18 Feb 2024 12:52:41 -0700 Subject: [PATCH 13/37] attempt release from GHA --- .github/workflows/CD.yaml | 10 +++++++++- package.json | 4 ++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/.github/workflows/CD.yaml b/.github/workflows/CD.yaml index 8e04669..4ad91a8 100644 --- a/.github/workflows/CD.yaml +++ b/.github/workflows/CD.yaml @@ -13,12 +13,20 @@ jobs: - name: Checkout uses: actions/checkout@v4 - - uses: jaywcjlove/github-action-package@main + - name: PKG Info + id: pkg + uses: jaywcjlove/github-action-package@main with: unset: scripts.prepare - name: Publish to Registry + id: publish uses: JS-DevTools/npm-publish@v3 with: token: ${{ secrets.NPM_TOKEN }} + tag: ${{ steps.pkg.outputs.version }} + + - name: Release Status + if: ${{ steps.publish.outputs.type }} + run: echo "Published v${{ steps.pkg.outputs.version }}" \ No newline at end of file diff --git a/package.json b/package.json index 7b2c5cc..fddd638 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@chalu/n-tuple-array", - "version": "0.0.1", + "version": "0.0.2", "description": "Get a specified amount of items when iterating over a JavaScript array, instead of just a single item that arrays provide!", "main": "./dist/cjs/index.js", "types": "./dist/cjs/types/index.d.ts", @@ -67,6 +67,6 @@ }, "repository": { "type": "git", - "url": "https://github.com/chalu/n-tuple-array.git" + "url": "git+https://github.com/chalu/n-tuple-array.git" } } From b528f0c489b3df26d802df9b157725cd7c7f32a5 Mon Sep 17 00:00:00 2001 From: Charles Opute Odili Date: Sun, 18 Feb 2024 13:00:23 -0700 Subject: [PATCH 14/37] fix package json file --- package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/package.json b/package.json index 9178e5a..fddd638 100644 --- a/package.json +++ b/package.json @@ -68,4 +68,5 @@ "repository": { "type": "git", "url": "git+https://github.com/chalu/n-tuple-array.git" + } } From f0a3f5ff6f2e8ca8393ae417bb71b0a1a6ed07f7 Mon Sep 17 00:00:00 2001 From: Charles Opute Odili Date: Sun, 18 Feb 2024 13:11:02 -0700 Subject: [PATCH 15/37] fix version --- .github/workflows/CD.yaml | 5 ++++- package.json | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/.github/workflows/CD.yaml b/.github/workflows/CD.yaml index 4ad91a8..42ae78c 100644 --- a/.github/workflows/CD.yaml +++ b/.github/workflows/CD.yaml @@ -2,7 +2,9 @@ name: Release on: pull_request: - types: [ closed ] + branches: + - "dev" + # types: [ closed ] jobs: release: @@ -25,6 +27,7 @@ jobs: with: token: ${{ secrets.NPM_TOKEN }} tag: ${{ steps.pkg.outputs.version }} + dry-run: true - name: Release Status if: ${{ steps.publish.outputs.type }} diff --git a/package.json b/package.json index fddd638..1c18dbd 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@chalu/n-tuple-array", - "version": "0.0.2", + "version": "1.0.1", "description": "Get a specified amount of items when iterating over a JavaScript array, instead of just a single item that arrays provide!", "main": "./dist/cjs/index.js", "types": "./dist/cjs/types/index.d.ts", From 2a291043ed7c6bf556f097a2d8e1fcea70c2ee33 Mon Sep 17 00:00:00 2001 From: Charles Opute Odili Date: Sun, 18 Feb 2024 13:19:12 -0700 Subject: [PATCH 16/37] remove merged condition --- .github/workflows/CD.yaml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/CD.yaml b/.github/workflows/CD.yaml index ad5cbe0..0fbaacf 100644 --- a/.github/workflows/CD.yaml +++ b/.github/workflows/CD.yaml @@ -8,7 +8,6 @@ on: jobs: release: - if: github.event.pull_request.base.ref == 'dev' && github.event.pull_request.merged == true runs-on: ubuntu-latest steps: From db425450eed5873b243e8d49f76fba4b3bbadadd Mon Sep 17 00:00:00 2001 From: Charles Opute Odili Date: Sun, 18 Feb 2024 13:21:28 -0700 Subject: [PATCH 17/37] fix version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 1c18dbd..7488627 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@chalu/n-tuple-array", - "version": "1.0.1", + "version": "1.0.0", "description": "Get a specified amount of items when iterating over a JavaScript array, instead of just a single item that arrays provide!", "main": "./dist/cjs/index.js", "types": "./dist/cjs/types/index.d.ts", From f176ab09937cae6e98b877c4befd5729b142312d Mon Sep 17 00:00:00 2001 From: Charles Opute Odili Date: Sun, 18 Feb 2024 13:27:41 -0700 Subject: [PATCH 18/37] fix version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 7488627..468cce4 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@chalu/n-tuple-array", - "version": "1.0.0", + "version": "0.1.3", "description": "Get a specified amount of items when iterating over a JavaScript array, instead of just a single item that arrays provide!", "main": "./dist/cjs/index.js", "types": "./dist/cjs/types/index.d.ts", From 1d5adb1cf0e0b832fa8d219527a42052df5402a0 Mon Sep 17 00:00:00 2001 From: Charles Opute Odili Date: Sun, 18 Feb 2024 13:30:20 -0700 Subject: [PATCH 19/37] use latest tag --- .github/workflows/CD.yaml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/CD.yaml b/.github/workflows/CD.yaml index 0fbaacf..362505f 100644 --- a/.github/workflows/CD.yaml +++ b/.github/workflows/CD.yaml @@ -25,8 +25,6 @@ jobs: uses: JS-DevTools/npm-publish@v3 with: token: ${{ secrets.NPM_TOKEN }} - tag: ${{ steps.pkg.outputs.version }} - dry-run: true - name: Release Status if: ${{ steps.publish.outputs.type }} From 387b3e2c99e5d1e8a1032c4a5d7078cff546305b Mon Sep 17 00:00:00 2001 From: Charles Opute Odili Date: Sun, 18 Feb 2024 13:37:04 -0700 Subject: [PATCH 20/37] fix release workflow --- .github/workflows/CD.yaml | 13 +++++-------- package.json | 2 +- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/.github/workflows/CD.yaml b/.github/workflows/CD.yaml index 362505f..884c28e 100644 --- a/.github/workflows/CD.yaml +++ b/.github/workflows/CD.yaml @@ -2,12 +2,13 @@ name: Release on: pull_request: - branches: - - "dev" - # types: [ closed ] + branches: + - "dev" + types: [ closed ] jobs: release: + if: github.event.pull_request.merged == true runs-on: ubuntu-latest steps: @@ -25,8 +26,4 @@ jobs: uses: JS-DevTools/npm-publish@v3 with: token: ${{ secrets.NPM_TOKEN }} - - - name: Release Status - if: ${{ steps.publish.outputs.type }} - run: echo "Published v${{ steps.pkg.outputs.version }}" - \ No newline at end of file + \ No newline at end of file diff --git a/package.json b/package.json index 468cce4..c30e1b0 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@chalu/n-tuple-array", - "version": "0.1.3", + "version": "0.1.4", "description": "Get a specified amount of items when iterating over a JavaScript array, instead of just a single item that arrays provide!", "main": "./dist/cjs/index.js", "types": "./dist/cjs/types/index.d.ts", From dd323c07618009541e6e9f3308651c58b530b32a Mon Sep 17 00:00:00 2001 From: Charles Opute Odili Date: Sun, 18 Feb 2024 14:01:12 -0700 Subject: [PATCH 21/37] prepare first public release --- .github/workflows/CD.yaml | 2 +- README.md | 25 ++++++++++++++++--------- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/.github/workflows/CD.yaml b/.github/workflows/CD.yaml index 884c28e..35588d9 100644 --- a/.github/workflows/CD.yaml +++ b/.github/workflows/CD.yaml @@ -3,7 +3,7 @@ name: Release on: pull_request: branches: - - "dev" + - "main" types: [ closed ] jobs: diff --git a/README.md b/README.md index 9fcee3b..f385ae2 100644 --- a/README.md +++ b/README.md @@ -29,26 +29,33 @@ const coordPairs = Array.from(coordIterable); console.log(Array.isArray(coordPairs)); // true // prints ["5.7225", "-9.6273"] ... coordPairs - .map(pair => myTransform(pair)) - .forEach((pair) => placeOnMap(pair)); + .map(pair => { + return myTransform(pair); + }) + .forEach((pair) => { + placeOnMap(pair); + }); ``` ### Some Real World Examples -> I first had this idea and tried my hands on it when [building wole-joko](https://github.com/chalu/wole-joko/blob/dev/src/js/utils.js#L57-L92), a live coding task I was asked to do in an engineering manager interview. It was a simulation of people entering an event hall to get seated, but only two could get it/be attended to at a time. I later took some time to [bring the project to live](https://wole-joko.netlify.app/) -> The below example was adapted for more concise terminal output +#### Wole Joko -
+I first tried my hands on this concept when [building wole-joko](https://github.com/chalu/wole-joko/blob/dev/src/js/utils.js#L57-L92), a _live coding task_ I was asked to do in an engineering manager interview :man_shrugging. It was a simulation of people entering an event hall to get seated, but only two could get in at a time. I later took some time to [give the project more life](https://wole-joko.netlify.app/) -JS challenge by @thdxr on X.com
+#### Execute max of X tasks in parallel + +JS challenge by [@thdxr on X.com](https://twitter.com/thdxr)
![](./assets/the-dax-js-challenge.png "JS challenge by @thdxr")

-`n-tuple-array` solution code
-[](https://github.com/chalu/n-tuple-array/blob/main/src/demo/demo-classic.ts#L6-L40) +> The below was adapted for more concise terminal output + +`n-tuple-array` solution. View [code here](https://github.com/chalu/n-tuple-array/blob/main/src/demo/demo-classic.ts#L6-L40)
+![](./assets/demo-classic.png "n-tuple-array solution")

-`n-tuple-array` n-tuple-array solution demo
+`n-tuple-array` solution demo
![](./assets/ntuple-array-demo-optimized.gif "n-tuple-array solution demo") From 33b91833eaf0a5198b3ad1ad8f1d97d967ba3955 Mon Sep 17 00:00:00 2001 From: Charles Opute Odili Date: Sun, 18 Feb 2024 14:02:01 -0700 Subject: [PATCH 22/37] set first public release --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index c30e1b0..882e94a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@chalu/n-tuple-array", - "version": "0.1.4", + "version": "0.1.5", "description": "Get a specified amount of items when iterating over a JavaScript array, instead of just a single item that arrays provide!", "main": "./dist/cjs/index.js", "types": "./dist/cjs/types/index.d.ts", From dba7f3ec2c763222bcee20ec161edae8d1b1ae25 Mon Sep 17 00:00:00 2001 From: Charles Opute Odili Date: Wed, 28 Feb 2024 11:12:25 -0700 Subject: [PATCH 23/37] remove files filter from lint script --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 882e94a..26aa3c1 100644 --- a/package.json +++ b/package.json @@ -24,8 +24,8 @@ "prebuild": "rm -rf dist", "build:esm": "tsc -p tsconfig.esm.json && mv dist/esm/index.js dist/esm/index.mjs", "build:cjs": "tsc -p tsconfig.cjs.json", - "lint": "xo $(git diff --name-only --diff-filter=d HEAD | grep -E '\\.(ts|js)$' | xargs)", - "lint:fix": "xo --fix $(git diff --name-only --diff-filter=d HEAD | grep -E '\\.(ts|js)$' | xargs)", + "lint": "xo", + "lint:fix": "xo --fix", "test": "jest", "pretest": "pnpm lint && pnpm build", "test:ci": "jest --ci --config='./jest.config.ci.ts'", From 95e196ee5314b16d8a561f523d60ee28a62d7f2b Mon Sep 17 00:00:00 2001 From: Charles Opute Odili Date: Wed, 28 Feb 2024 11:14:24 -0700 Subject: [PATCH 24/37] simplify types used --- src/index.ts | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/index.ts b/src/index.ts index 6adea2f..3bebe49 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,6 +1,4 @@ -type Item = T | undefined; -type Value = Array>; -type Result = IteratorResult, Value>; +type Result = IteratorResult, Array>; export type Matcher = (item: T | unknown) => boolean; export type TupleConfig = { @@ -38,7 +36,7 @@ export const tuplesFromArray = (config: TupleConfig) => { const maxItemSize = Number.parseInt(`${maxItems}`, 10); const proceedNext = (): Result => { - const items: Value = []; + const items: Array = []; if (cursor >= list.length) { return {done: true, value: []}; @@ -72,11 +70,11 @@ export const tuplesFromArray = (config: TupleConfig) => { return {value: items, done: items.length === 0}; }; - const iterable: Iterable> = { - [Symbol.iterator](): Iterator> { - return { - next: proceedNext, - }; + const iterable: IterableIterator> = { + next: proceedNext, + + [Symbol.iterator](): IterableIterator> { + return this; }, }; From 6f6a4ade1e6d12b969756d9a77d8be1fb4c6260a Mon Sep 17 00:00:00 2001 From: Charles Opute Odili Date: Tue, 5 Mar 2024 11:06:59 -0700 Subject: [PATCH 25/37] refine lint script for pre-commit hook --- .husky/pre-commit | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.husky/pre-commit b/.husky/pre-commit index 009b3f8..859bd52 100644 --- a/.husky/pre-commit +++ b/.husky/pre-commit @@ -1 +1 @@ -pnpm lint +pnpm lint:MA diff --git a/package.json b/package.json index 26aa3c1..c46e2fb 100644 --- a/package.json +++ b/package.json @@ -25,7 +25,7 @@ "build:esm": "tsc -p tsconfig.esm.json && mv dist/esm/index.js dist/esm/index.mjs", "build:cjs": "tsc -p tsconfig.cjs.json", "lint": "xo", - "lint:fix": "xo --fix", + "lint:MA": "xo $(git diff --name-only --diff-filter=MA HEAD | grep -E 'src/.+\\.(ts|js)$' | xargs)", "test": "jest", "pretest": "pnpm lint && pnpm build", "test:ci": "jest --ci --config='./jest.config.ci.ts'", From b41eb1416ce1f44043586326777fe90e3c6e1ae4 Mon Sep 17 00:00:00 2001 From: Charles Opute Odili Date: Tue, 5 Mar 2024 13:42:14 -0700 Subject: [PATCH 26/37] fix cjs and esm modules --- README.md | 43 ++++++++++--------- fix-pkgs | 11 +++++ package.json | 3 +- src/examples/js/basic.js | 25 +++++++++++ src/examples/js/basic.mjs | 23 ++++++++++ .../demo-basics.ts => examples/ts/basic.ts} | 4 +- .../ts/classic.ts} | 4 +- .../demo-utils.ts => examples/ts/utils.ts} | 0 tsconfig.base.json | 26 ++++++++--- tsconfig.cjs.json | 5 --- tsconfig.esm.json | 9 +--- 11 files changed, 110 insertions(+), 43 deletions(-) create mode 100755 fix-pkgs create mode 100644 src/examples/js/basic.js create mode 100644 src/examples/js/basic.mjs rename src/{demo/demo-basics.ts => examples/ts/basic.ts} (95%) rename src/{demo/demo-classic.ts => examples/ts/classic.ts} (94%) rename src/{demo/demo-utils.ts => examples/ts/utils.ts} (100%) diff --git a/README.md b/README.md index f385ae2..926aeb9 100644 --- a/README.md +++ b/README.md @@ -1,57 +1,60 @@ # n-tuple-array -Get a specified amount of items when iterating over a JavaScript array, instead of the single item that arrays provide per iteration, by default. +Get a **`configurable`** amount of items when iterating over a JavaScript array, instead of a single item that arrays provide per iteration, by default. ## Motivation -Imagine that you received a collection of coordinates (latitude and longitude), but they were sent -as a flat array of values to speed up the data transfers. +Imagine that you received a large collection of coordinates (latitude and longitude), but they were sent +as a flat array of values to speed up the data transfer. -`n-tuple-array` can help you get out the coordinates in pairs (their logical representation), such that you'd go **from** +`n-tuple-array` can help you get out the coordinates in pairs (i.e their logical representation), such that you'd go + +**from** ```json -// flatCoords +// flat coordinates ["5.7225", "-9.6273", "2.68452", "-30.9501", ...] ``` **to** ```javascript -// generate pairs by default -const coordIterable = tuplesFromArray({ list: flatCoords }); +// the iterable will generate pairs by default +const coordsIterable = tuplesFromArray({ list: flatCoords }); // using for..of, get pairs as ["5.7225", "-9.6273"] ... -for (const pair of coordIterable) { +for (const pair of coordsIterable) { console.log(pair); } -// OR manipulate pairs with regular array functions -const coordPairs = Array.from(coordIterable); -console.log(Array.isArray(coordPairs)); // true -// prints ["5.7225", "-9.6273"] ... -coordPairs +// OR manipulate pairs with regular array +// functions like map, filter, forEach ... +const coordsInPairs = Array.from(coordsIterable); +console.log(Array.isArray(coordsInPairs)); // true +coordsInPairs .map(pair => { + // pair is ["5.7225", "-9.6273"] ... return myTransform(pair); }) .forEach((pair) => { + // pair is ["5.7225", "-9.6273"] ... placeOnMap(pair); }); ``` ### Some Real World Examples -#### Wole Joko +#### 1. Wole Joko -I first tried my hands on this concept when [building wole-joko](https://github.com/chalu/wole-joko/blob/dev/src/js/utils.js#L57-L92), a _live coding task_ I was asked to do in an engineering manager interview :man_shrugging. It was a simulation of people entering an event hall to get seated, but only two could get in at a time. I later took some time to [give the project more life](https://wole-joko.netlify.app/) +I first tried my hands on this concept when [fleshing out wole-joko](https://github.com/chalu/wole-joko/blob/dev/src/js/utils.js#L57-L92), which strated as a _live coding task_ I was asked to do in an engineering manager interview :man_shrugging +It was a simulation of people entering an event hall to get seated, but **only two** could get in at a time - https://wole-joko.netlify.app/ -#### Execute max of X tasks in parallel +#### 2. Execute max of `N` async tasks -JS challenge by [@thdxr on X.com](https://twitter.com/thdxr)
![](./assets/the-dax-js-challenge.png "JS challenge by @thdxr") -

> The below was adapted for more concise terminal output -`n-tuple-array` solution. View [code here](https://github.com/chalu/n-tuple-array/blob/main/src/demo/demo-classic.ts#L6-L40)
+`n-tuple-array` solution. View [code here](https://github.com/chalu/n-tuple-array/blob/main/src/examples/classic.ts#L6-L40)
![](./assets/demo-classic.png "n-tuple-array solution")

@@ -92,5 +95,5 @@ for (const quintet of quintetIterator) { } ``` -See more examples in [src/demo](./src/demo/) +See more examples in [src/examples](./src/examples/) diff --git a/fix-pkgs b/fix-pkgs new file mode 100755 index 0000000..e1f4413 --- /dev/null +++ b/fix-pkgs @@ -0,0 +1,11 @@ +cat >dist/cjs/package.json <dist/esm/package.json < i + 1); +const isEven = item => { + if ( + !item + || typeof item !== 'number' + || item % 2 !== 0 + ) { + return false; + } + + return true; +}; + +// Use the lib +const quintetIterator = tuplesFromArray({ + list: numbers, maxItems: 5, match: isEven, +}); + +for (const quintet of quintetIterator) { + // Prints [ 2, 4, 6, 8, 10 ] ... [ 92, 94, 96, 98, 100 ] + console.log(quintet); +} diff --git a/src/examples/js/basic.mjs b/src/examples/js/basic.mjs new file mode 100644 index 0000000..6374be8 --- /dev/null +++ b/src/examples/js/basic.mjs @@ -0,0 +1,23 @@ +import tuplesFromArray from '../../../dist/esm/index.mjs'; + +// some setup +const numbers = Array.from({length: 100}, (_, i) => i + 1); +const isEven = (item) => { + if ( + !item + || typeof item !== 'number' + || item % 2 !== 0 + ) return false; + + return true; +}; + +// use the lib +const quintetIterator = tuplesFromArray({ + list: numbers, maxItems: 5, match: isEven +}); + +for (const quintet of quintetIterator) { + // prints [ 2, 4, 6, 8, 10 ] ... [ 92, 94, 96, 98, 100 ] + console.log(quintet); +} \ No newline at end of file diff --git a/src/demo/demo-basics.ts b/src/examples/ts/basic.ts similarity index 95% rename from src/demo/demo-basics.ts rename to src/examples/ts/basic.ts index e0c13df..68fb5e9 100644 --- a/src/demo/demo-basics.ts +++ b/src/examples/ts/basic.ts @@ -1,7 +1,7 @@ -import {tuplesFromArray} from '../index'; +import {tuplesFromArray} from '../../index'; import { hexadecimals, isDate, dates, uuids, -} from './demo-utils'; +} from './utils'; console.log('----- Example 1 [10 Hex in twos. Used default param values] ------'); for (const hexPair of tuplesFromArray({list: hexadecimals(10)})) { diff --git a/src/demo/demo-classic.ts b/src/examples/ts/classic.ts similarity index 94% rename from src/demo/demo-classic.ts rename to src/examples/ts/classic.ts index e191584..922f8f2 100644 --- a/src/demo/demo-classic.ts +++ b/src/examples/ts/classic.ts @@ -1,7 +1,7 @@ -import {tuplesFromArray} from '../index'; +import {tuplesFromArray} from '../../index'; import { isDate, dates, canadaDateFormat, delay, formatCount, -} from './demo-utils'; +} from './utils'; const processItem = async (item: T | undefined) => { await delay(Math.random() * 500); // Simulate some async workload diff --git a/src/demo/demo-utils.ts b/src/examples/ts/utils.ts similarity index 100% rename from src/demo/demo-utils.ts rename to src/examples/ts/utils.ts diff --git a/tsconfig.base.json b/tsconfig.base.json index 211db10..18ddf57 100644 --- a/tsconfig.base.json +++ b/tsconfig.base.json @@ -1,21 +1,35 @@ { "compilerOptions": { "strict": true, - "rootDir": "./src", - "esModuleInterop": true, - "forceConsistentCasingInFileNames": true, - "skipLibCheck": true, + "pretty": true, "checkJs": true, "allowJs": true, + "rootDir": "./src", + "skipLibCheck": true, "declaration": true, + "esModuleInterop": true, "declarationMap": true, + "sourceMap": true, + "inlineSourceMap": false, + "resolveJsonModule": true, + "moduleResolution": "Node", + "moduleDetection": "force", "noUncheckedIndexedAccess": true, - "allowSyntheticDefaultImports": true + "allowSyntheticDefaultImports": true, + "forceConsistentCasingInFileNames": true, + "noFallthroughCasesInSwitch": true, + "lib": [ + "ES2022", + "DOM", + "DOM.Iterable" + ] }, "include": [ "src/**/*" ], "exclude": [ - "src/demo/**" + "src/examples/**", + "node_modules", + "dist" ] } \ No newline at end of file diff --git a/tsconfig.cjs.json b/tsconfig.cjs.json index 5d35037..5801811 100644 --- a/tsconfig.cjs.json +++ b/tsconfig.cjs.json @@ -1,13 +1,8 @@ { "extends": "./tsconfig.base.json", "compilerOptions": { - "lib": [ - "ES2022", - "DOM" - ], "target": "ES2022", "module": "CommonJS", - "moduleResolution": "Node", "outDir": "dist/cjs", "declarationDir": "dist/cjs/types" } diff --git a/tsconfig.esm.json b/tsconfig.esm.json index 8beeb6a..bed57b6 100644 --- a/tsconfig.esm.json +++ b/tsconfig.esm.json @@ -1,13 +1,8 @@ { "extends": "./tsconfig.base.json", "compilerOptions": { - "lib": [ - "ES2022", - "DOM" - ], - "target": "ES2022", - "module": "NodeNext", - "moduleResolution": "NodeNext", + "target": "ESNext", + "module": "ESNext", "outDir": "dist/esm", "declarationDir": "dist/esm/types" } From ba0f9006027583fd503f9923cebf2b38688d6b2a Mon Sep 17 00:00:00 2001 From: Charles Opute Odili Date: Tue, 5 Mar 2024 13:47:11 -0700 Subject: [PATCH 27/37] add updated build --- dist/cjs/index.js | 6 +++--- dist/cjs/index.js.map | 1 + dist/cjs/package.json | 3 +++ dist/cjs/types/index.d.ts | 4 +--- dist/cjs/types/index.d.ts.map | 2 +- dist/esm/index.js.map | 1 + dist/esm/index.mjs | 17 ++++++----------- dist/esm/package.json | 3 +++ dist/esm/types/index.d.ts | 4 +--- dist/esm/types/index.d.ts.map | 2 +- 10 files changed, 21 insertions(+), 22 deletions(-) create mode 100644 dist/cjs/index.js.map create mode 100644 dist/cjs/package.json create mode 100644 dist/esm/index.js.map create mode 100644 dist/esm/package.json diff --git a/dist/cjs/index.js b/dist/cjs/index.js index 927cbf0..0f9c2e9 100644 --- a/dist/cjs/index.js +++ b/dist/cjs/index.js @@ -50,13 +50,13 @@ const tuplesFromArray = (config) => { return { value: items, done: items.length === 0 }; }; const iterable = { + next: proceedNext, [Symbol.iterator]() { - return { - next: proceedNext, - }; + return this; }, }; return iterable; }; exports.tuplesFromArray = tuplesFromArray; exports.default = exports.tuplesFromArray; +//# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/dist/cjs/index.js.map b/dist/cjs/index.js.map new file mode 100644 index 0000000..201cde8 --- /dev/null +++ b/dist/cjs/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;AASA,MAAa,+BAAgC,SAAQ,KAAK;CAAG;AAA7D,0EAA6D;AAE7D,MAAM,yBAAyB,GAAG,CAAI,IAAS,EAAE,QAAgB,EAAE,KAA6B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AAM,GAAG,WAAW,EAAE,IAAI,CAAC,MAAM,CAAC;YAE7C,4DAA4D;YAC5D,4DAA4D;YAC5D,uBAAuB;YACvB,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC;QAEf,OAAO,MAAM,GAAG,QAAQ,EAAE,CAAC;YAC1B,MAAM,IAAI,GAAG,IAAI,CAAC,MAAM,CAAC,CAAC;YAC1B,MAAM,IAAI,CAAC,CAAC;YAEZ,IAAI,KAAK,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC;gBAC3B,SAAS;YACV,CAAC;YAED,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YAEjB,IAAI,KAAK,IAAI,KAAK,CAAC,MAAM,KAAK,WAAW,EAAE,CAAC;gBAC3C,MAAM;YACP,CAAC;QACF,CAAC;QAED,OAAO,EAAC,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,CAAC,MAAM,KAAK,CAAC,EAAC,CAAC;IACjD,CAAC,CAAC;IAEF,MAAM,QAAQ,GAA2C;QACxD,IAAI,EAAE,WAAW;QAEjB,CAAC,MAAM,CAAC,QAAQ,CAAC;YAChB,OAAO,IAAI,CAAC;QACb,CAAC;KACD,CAAC;IAEF,OAAO,QAAQ,CAAC;AACjB,CAAC,CAAC;AAnDW,QAAA,eAAe,mBAmD1B;AAEF,kBAAe,uBAAe,CAAC"} \ No newline at end of file diff --git a/dist/cjs/package.json b/dist/cjs/package.json new file mode 100644 index 0000000..1cd945a --- /dev/null +++ b/dist/cjs/package.json @@ -0,0 +1,3 @@ +{ + "type": "commonjs" +} diff --git a/dist/cjs/types/index.d.ts b/dist/cjs/types/index.d.ts index cb5aa72..05345e4 100644 --- a/dist/cjs/types/index.d.ts +++ b/dist/cjs/types/index.d.ts @@ -1,5 +1,3 @@ -type Item = T | undefined; -type Value = Array>; export type Matcher = (item: T | unknown) => boolean; export type TupleConfig = { list: T[]; @@ -8,6 +6,6 @@ export type TupleConfig = { }; export declare class InvalidInvocationParameterError extends Error { } -export declare const tuplesFromArray: (config: TupleConfig) => Iterable>; +export declare const tuplesFromArray: (config: TupleConfig) => IterableIterator<(T | undefined)[]>; export default tuplesFromArray; //# sourceMappingURL=index.d.ts.map \ No newline at end of file diff --git a/dist/cjs/types/index.d.ts.map b/dist/cjs/types/index.d.ts.map index 8d87987..d9ec426 100644 --- a/dist/cjs/types/index.d.ts.map +++ b/dist/cjs/types/index.d.ts.map @@ -1 +1 @@ -{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAAA,KAAK,IAAI,CAAC,CAAC,IAAI,CAAC,GAAG,SAAS,CAAC;AAC7B,KAAK,KAAK,CAAC,CAAC,IAAI,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;AAG/B,MAAM,MAAM,OAAO,CAAC,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,GAAG,OAAO,KAAK,OAAO,CAAC;AACxD,MAAM,MAAM,WAAW,CAAC,CAAC,IAAI;IAC5B,IAAI,EAAE,CAAC,EAAE,CAAC;IACV,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,KAAK,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC;CACnB,CAAC;AAEF,qBAAa,+BAAgC,SAAQ,KAAK;CAAG;AAqB7D,eAAO,MAAM,eAAe,mDAmD3B,CAAC;AAEF,eAAe,eAAe,CAAC"} \ No newline at end of file +{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,OAAO,CAAC,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,GAAG,OAAO,KAAK,OAAO,CAAC;AACxD,MAAM,MAAM,WAAW,CAAC,CAAC,IAAI;IAC5B,IAAI,EAAE,CAAC,EAAE,CAAC;IACV,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,KAAK,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC;CACnB,CAAC;AAEF,qBAAa,+BAAgC,SAAQ,KAAK;CAAG;AAqB7D,eAAO,MAAM,eAAe,oEAmD3B,CAAC;AAEF,eAAe,eAAe,CAAC"} \ No newline at end of file diff --git a/dist/esm/index.js.map b/dist/esm/index.js.map new file mode 100644 index 0000000..6ca0fe6 --- /dev/null +++ b/dist/esm/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AASA,MAAM,OAAO,+BAAgC,SAAQ,KAAK;CAAG;AAE7D,MAAM,yBAAyB,GAAG,CAAI,IAAS,EAAE,QAAgB,EAAE,KAA6B,EAAE,EAAE;IACnG,IAAI,CAAC,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC;QACnC,MAAM,IAAI,+BAA+B,CAAC,8BAA8B,CAAC,CAAC;IAC3E,CAAC;IAED,IACC,OAAO,QAAQ,KAAK,QAAQ;WACnB,CAAC,OAAO,QAAQ,KAAK,QAAQ,IAAI,QAAQ,IAAI,CAAC,CAAC,EACvD,CAAC;QACF,MAAM,OAAO,GAAG,0EAA0E,CAAC;QAC3F,MAAM,IAAI,+BAA+B,CAAC,OAAO,CAAC,CAAC;IACpD,CAAC;IAED,IAAI,KAAK,KAAK,SAAS,IAAI,OAAO,KAAK,KAAK,UAAU,EAAE,CAAC;QACxD,MAAM,OAAO,GAAG,iDAAiD,CAAC;QAClE,MAAM,IAAI,+BAA+B,CAAC,OAAO,CAAC,CAAC;IACpD,CAAC;AACF,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,eAAe,GAAG,CAAI,MAAsB,EAAE,EAAE;IAC5D,MAAM,EAAC,IAAI,EAAE,KAAK,EAAE,QAAQ,GAAG,CAAC,EAAC,GAAG,MAAM,CAAC;IAC3C,yBAAyB,CAAC,IAAI,EAAE,QAAQ,EAAE,KAAK,CAAC,CAAC;IAEjD,IAAI,MAAM,GAAG,CAAC,CAAC;IACf,MAAM,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AC"} \ No newline at end of file diff --git a/dist/esm/index.mjs b/dist/esm/index.mjs index 927cbf0..08c7f8e 100644 --- a/dist/esm/index.mjs +++ b/dist/esm/index.mjs @@ -1,9 +1,5 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.tuplesFromArray = exports.InvalidInvocationParameterError = void 0; -class InvalidInvocationParameterError extends Error { +export class InvalidInvocationParameterError extends Error { } -exports.InvalidInvocationParameterError = InvalidInvocationParameterError; const validateParametersOrThrow = (list, maxItems, match) => { if (!list || !Array.isArray(list)) { throw new InvalidInvocationParameterError('expected list to be an array'); @@ -18,7 +14,7 @@ const validateParametersOrThrow = (list, maxItems, match) => { throw new InvalidInvocationParameterError(message); } }; -const tuplesFromArray = (config) => { +export const tuplesFromArray = (config) => { const { list, match, maxItems = 2 } = config; validateParametersOrThrow(list, maxItems, match); let cursor = 0; @@ -50,13 +46,12 @@ const tuplesFromArray = (config) => { return { value: items, done: items.length === 0 }; }; const iterable = { + next: proceedNext, [Symbol.iterator]() { - return { - next: proceedNext, - }; + return this; }, }; return iterable; }; -exports.tuplesFromArray = tuplesFromArray; -exports.default = exports.tuplesFromArray; +export default tuplesFromArray; +//# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/dist/esm/package.json b/dist/esm/package.json new file mode 100644 index 0000000..4720025 --- /dev/null +++ b/dist/esm/package.json @@ -0,0 +1,3 @@ +{ + "type": "module" +} diff --git a/dist/esm/types/index.d.ts b/dist/esm/types/index.d.ts index cb5aa72..05345e4 100644 --- a/dist/esm/types/index.d.ts +++ b/dist/esm/types/index.d.ts @@ -1,5 +1,3 @@ -type Item = T | undefined; -type Value = Array>; export type Matcher = (item: T | unknown) => boolean; export type TupleConfig = { list: T[]; @@ -8,6 +6,6 @@ export type TupleConfig = { }; export declare class InvalidInvocationParameterError extends Error { } -export declare const tuplesFromArray: (config: TupleConfig) => Iterable>; +export declare const tuplesFromArray: (config: TupleConfig) => IterableIterator<(T | undefined)[]>; export default tuplesFromArray; //# sourceMappingURL=index.d.ts.map \ No newline at end of file diff --git a/dist/esm/types/index.d.ts.map b/dist/esm/types/index.d.ts.map index 8d87987..d9ec426 100644 --- a/dist/esm/types/index.d.ts.map +++ b/dist/esm/types/index.d.ts.map @@ -1 +1 @@ -{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAAA,KAAK,IAAI,CAAC,CAAC,IAAI,CAAC,GAAG,SAAS,CAAC;AAC7B,KAAK,KAAK,CAAC,CAAC,IAAI,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;AAG/B,MAAM,MAAM,OAAO,CAAC,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,GAAG,OAAO,KAAK,OAAO,CAAC;AACxD,MAAM,MAAM,WAAW,CAAC,CAAC,IAAI;IAC5B,IAAI,EAAE,CAAC,EAAE,CAAC;IACV,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,KAAK,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC;CACnB,CAAC;AAEF,qBAAa,+BAAgC,SAAQ,KAAK;CAAG;AAqB7D,eAAO,MAAM,eAAe,mDAmD3B,CAAC;AAEF,eAAe,eAAe,CAAC"} \ No newline at end of file +{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,OAAO,CAAC,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,GAAG,OAAO,KAAK,OAAO,CAAC;AACxD,MAAM,MAAM,WAAW,CAAC,CAAC,IAAI;IAC5B,IAAI,EAAE,CAAC,EAAE,CAAC;IACV,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,KAAK,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC;CACnB,CAAC;AAEF,qBAAa,+BAAgC,SAAQ,KAAK;CAAG;AAqB7D,eAAO,MAAM,eAAe,oEAmD3B,CAAC;AAEF,eAAe,eAAe,CAAC"} \ No newline at end of file From 994f562735fd8da8924ca2692cdd67f8a002ed1d Mon Sep 17 00:00:00 2001 From: Charles Opute Odili Date: Tue, 5 Mar 2024 13:49:51 -0700 Subject: [PATCH 28/37] fix lint errors in esm example code --- src/examples/js/basic.mjs | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/examples/js/basic.mjs b/src/examples/js/basic.mjs index 6374be8..72d27df 100644 --- a/src/examples/js/basic.mjs +++ b/src/examples/js/basic.mjs @@ -1,23 +1,25 @@ import tuplesFromArray from '../../../dist/esm/index.mjs'; -// some setup +// Some setup const numbers = Array.from({length: 100}, (_, i) => i + 1); -const isEven = (item) => { - if ( - !item +const isEven = item => { + if ( + !item || typeof item !== 'number' || item % 2 !== 0 - ) return false; + ) { + return false; + } - return true; + return true; }; -// use the lib +// Use the lib const quintetIterator = tuplesFromArray({ - list: numbers, maxItems: 5, match: isEven + list: numbers, maxItems: 5, match: isEven, }); for (const quintet of quintetIterator) { - // prints [ 2, 4, 6, 8, 10 ] ... [ 92, 94, 96, 98, 100 ] + // Prints [ 2, 4, 6, 8, 10 ] ... [ 92, 94, 96, 98, 100 ] console.log(quintet); -} \ No newline at end of file +} From 854d60467b6f8d7483ee360f70ea48aedc0539ec Mon Sep 17 00:00:00 2001 From: Charles Opute Odili Date: Tue, 5 Mar 2024 20:07:27 -0700 Subject: [PATCH 29/37] add more JS examples --- .xo-config.json | 1 + src/examples/js/concurrent.js | 39 +++++++++++++++++++++++++ src/examples/js/with-lib.mjs | 43 ++++++++++++++++++++++++++++ src/examples/js/without-lib.js | 52 ++++++++++++++++++++++++++++++++++ 4 files changed, 135 insertions(+) create mode 100644 src/examples/js/concurrent.js create mode 100644 src/examples/js/with-lib.mjs create mode 100644 src/examples/js/without-lib.js diff --git a/.xo-config.json b/.xo-config.json index 1a87094..bfe3926 100644 --- a/.xo-config.json +++ b/.xo-config.json @@ -1,6 +1,7 @@ { "env": ["jest", "node"], "rules": { + "no-await-in-loop": "off", "import/extensions": "off", "unicorn/prefer-module": "off", "unicorn/no-array-for-each": "off", diff --git a/src/examples/js/concurrent.js b/src/examples/js/concurrent.js new file mode 100644 index 0000000..0ad348e --- /dev/null +++ b/src/examples/js/concurrent.js @@ -0,0 +1,39 @@ +const indexToDate = (index = 0) => batchId => new Promise(resolve => { + console.log(`[Batch ${batchId}] task ${index + 1} starting`); + const delay = Math.random() * 3000; + const dt = new Date(`2024-07-${(index + 1) % 30}`); + setTimeout(() => { + console.log(`[Batch ${batchId}] task ${index + 1} completed in ${delay.toFixed(2)} ms`); + resolve(dt); + }, delay); +}); + +const processTask = async (todo, batchId) => { + const out = await todo(batchId); + return out; +}; + +const executeConcurrent = async (todos, maxBatchSize) => { + const done = []; + const todosCopy = todos.slice(); + const worker = async (_, batchIndex) => { + let todo = todosCopy.shift(); + while (todo) { + const [result] = await Promise.allSettled([processTask(todo, batchIndex + 1)]); + done.push(result); + todo = todosCopy.shift(); + } + }; + + const batchStarters = Array.from({length: maxBatchSize}, worker); + await Promise.all(batchStarters); + return done; +}; + +(async () => { + const tasks = Array.from({length: 5}, (_, i) => indexToDate(i)); + const maxTasksPerTime = 2; + + const allDone = await executeConcurrent(tasks, maxTasksPerTime); + console.log(allDone); +})(); diff --git a/src/examples/js/with-lib.mjs b/src/examples/js/with-lib.mjs new file mode 100644 index 0000000..02a5c6f --- /dev/null +++ b/src/examples/js/with-lib.mjs @@ -0,0 +1,43 @@ +import tuplesFromArray from '../../../dist/esm/index.mjs'; + +const indexToDate = (index = 0) => batchId => new Promise(resolve => { + console.log(`[Batch ${batchId}] task ${index + 1} starting`); + const delay = Math.random() * 3000; + const dt = new Date(`2024-07-${(index + 1) % 30}`); + setTimeout(() => { + console.log(`[Batch ${batchId}] task ${index + 1} completed in ${delay.toFixed(2)} ms`); + resolve(dt); + }, delay); +}); + +const processTask = async (todo, batchId) => { + const out = await todo(batchId); + return out; +}; + +const executeWitLibrary = async (todos, maxBatchSize) => { + console.log(`do <= ${maxBatchSize} of ${todos.length} tasks, at any given time`); + const done = []; + + let batchIndex = 1; + const todosBatchIterable = tuplesFromArray({list: todos, maxItems: maxBatchSize}); + for (const batch of todosBatchIterable) { + console.log(`----- starting batch [${batchIndex}], ${batch.length} todos`); + const results = await Promise.allSettled( + batch.map(todo => processTask(todo, batchIndex)), + ); + done.push(...results); + + batchIndex += 1; + } + + return done; +}; + +(async () => { + const tasks = Array.from({length: 5}, (_, i) => indexToDate(i)); + const maxTasksPerTime = 2; + + const allDone = await executeWitLibrary(tasks, maxTasksPerTime); + console.log(allDone); +})(); diff --git a/src/examples/js/without-lib.js b/src/examples/js/without-lib.js new file mode 100644 index 0000000..e9803b7 --- /dev/null +++ b/src/examples/js/without-lib.js @@ -0,0 +1,52 @@ +const indexToDate = (index = 0) => batchId => new Promise(resolve => { + console.log(`[Batch ${batchId}] task ${index + 1} starting`); + const delay = Math.random() * 3000; + const dt = new Date(`2024-07-${(index + 1) % 30}`); + setTimeout(() => { + console.log(`[Batch ${batchId}] task ${index + 1} completed in ${delay.toFixed(2)} ms`); + resolve(dt); + }, delay); +}); + +const processTask = async (todo, batchId) => { + const out = await todo(batchId); + return out; +}; + +// Everywhere start/end is used is repititive and error prone +const executeWithoutLibrary = async (todos, maxBatchSize) => { + console.log(`do <= ${maxBatchSize} of ${todos.length} tasks, at any given time`); + const done = []; + + let start = 0; + let end = start + maxBatchSize; + let batchIndex = 1; + let batch = todos.slice(start, end); + while (batch.length > 0) { + console.log(`----- starting batch [${batchIndex}], ${batch.length} todos`); + const results = await Promise.allSettled( + batch.map(todo => processTask(todo, batchIndex)), + ); + done.push(...results); + + start = end; + if (start >= todos.length) { + break; + } + + end = Math.min(start + maxBatchSize, todos.length); + batch = todos.slice(start, end); + + batchIndex += 1; + } + + return done; +}; + +(async () => { + const tasks = Array.from({length: 5}, (_, i) => indexToDate(i)); + const maxTasksPerTime = 2; + + const allDone = await executeWithoutLibrary(tasks, maxTasksPerTime); + console.log(allDone); +})(); From b0f35e3fac1587589b41b4125be1e123f23ec9c7 Mon Sep 17 00:00:00 2001 From: Charles Opute Odili Date: Tue, 5 Mar 2024 21:41:34 -0700 Subject: [PATCH 30/37] document what is exported --- dist/cjs/index.js | 32 +++++++++++++++++++++ dist/cjs/index.js.map | 2 +- dist/cjs/types/index.d.ts | 51 ++++++++++++++++++++++++++++++++-- dist/cjs/types/index.d.ts.map | 2 +- dist/esm/index.js.map | 2 +- dist/esm/index.mjs | 32 +++++++++++++++++++++ dist/esm/types/index.d.ts | 51 ++++++++++++++++++++++++++++++++-- dist/esm/types/index.d.ts.map | 2 +- src/index.ts | 52 ++++++++++++++++++++++++++++++++++- 9 files changed, 217 insertions(+), 9 deletions(-) diff --git a/dist/cjs/index.js b/dist/cjs/index.js index 0f9c2e9..f442bee 100644 --- a/dist/cjs/index.js +++ b/dist/cjs/index.js @@ -1,6 +1,11 @@ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.tuplesFromArray = exports.InvalidInvocationParameterError = void 0; +; +/** + * An exception than can be thrown if there is no input array, `maxItems` is <= 0 or is not + * a number, or `match` is not a function + */ class InvalidInvocationParameterError extends Error { } exports.InvalidInvocationParameterError = InvalidInvocationParameterError; @@ -18,6 +23,33 @@ const validateParametersOrThrow = (list, maxItems, match) => { throw new InvalidInvocationParameterError(message); } }; +/** + * Returns an iterable iterator that ouputs a configured + * list of items when iterating over a given array + * + * @typeParam T - Type of items the input list contains + * + * @param config - An object to indicate the input array `config.list`, and set the + * max size of items per interation `config.maxItems`. You can also optionally specify `config.match` + * as a function that should return true to filter in items from the input array + * (or false to filter them out) when deciding what items is to be included per iteration + * + * @function + * @throws InvalidInvocationParameterError + * This exception is thrown if there is no input array, `maxItems` is <= 0 or is not + * a number, or `match` is not a function + * + * @returns an IterableIterator + * + * @example + * Here is an example that will get max of 3 items from + * each iteration on the returned iterable + * ```javascript + * const iterable = tuplesFromArray({ + * list:[], maxSize: 3, match: (itm) => !!itm + * }); + * ``` + */ const tuplesFromArray = (config) => { const { list, match, maxItems = 2 } = config; validateParametersOrThrow(list, maxItems, match); diff --git a/dist/cjs/index.js.map b/dist/cjs/index.js.map index 201cde8..7e53e9e 100644 --- a/dist/cjs/index.js.map +++ b/dist/cjs/index.js.map @@ -1 +1 @@ -{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;AASA,MAAa,+BAAgC,SAAQ,KAAK;CAAG;AAA7D,0EAA6D;AAE7D,MAAM,yBAAyB,GAAG,CAAI,IAAS,EAAE,QAAgB,EAAE,KAA6B,EAAE,EAAE;IACnG,IAAI,CAAC,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC;QACnC,MAAM,IAAI,+BAA+B,CAAC,8BAA8B,CAAC,CAAC;IAC3E,CAAC;IAED,IACC,OAAO,QAAQ,KAAK,QAAQ;WACnB,CAAC,OAAO,QAAQ,KAAK,QAAQ,IAAI,QAAQ,IAAI,CAAC,CAAC,EACvD,CAAC;QACF,MAAM,OAAO,GAAG,0EAA0E,CAAC;QAC3F,MAAM,IAAI,+BAA+B,CAAC,OAAO,CAAC,CAAC;IACpD,CAAC;IAED,IAAI,KAAK,KAAK,SAAS,IAAI,OAAO,KAAK,KAAK,UAAU,EAAE,CAAC;QACxD,MAAM,OAAO,GAAG,iDAAiD,CAAC;QAClE,MAAM,IAAI,+BAA+B,CAAC,OAAO,CAAC,CAAC;IACpD,CAAC;AACF,CAAC,CAAC;AAEK,MAAM,eAAe,GAAG,CAAI,MAAsB,EAAE,EAAE;IAC5D,MAAM,EAAC,IAAI,EAAE,KAAK,EAAE,QAAQ,GAAG,CAAC,EAAC,GAAG,MAAM,CAAC;IAC3C,yBAAyB,CAAC,IAAI,EAAE,QAAQ,EAAE,KAAK,CAAC,CAAC;IAEjD,IAAI,MAAM,GAAG,CAAC,CAAC;IACf,MAAM,WAAW,GAAG,MAAM,CAAC,QAAQ,CAAC,GAAG,QAAQ,EAAE,EAAE,EAAE,CAAC,CAAC;IAEvD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AE,CAAC;YAC3B,OAAO,EAAC,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,EAAE,EAAC,CAAC;QAChC,CAAC;QAED,MAAM,QAAQ,GAAG,KAAK,KAAK,SAAS;YACnC,yDAAyD;YACzD,8CAA8C;YAC9C,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,MAAM,GAAG,WAAW,EAAE,IAAI,CAAC,MAAM,CAAC;YAE7C,4DAA4D;YAC5D,4DAA4D;YAC5D,uBAAuB;YACvB,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC;QAEf,OAAO,MAAM,GAAG,QAAQ,EAAE,CAAC;YAC1B,MAAM,IAAI,GAAG,IAAI,CAAC,MAAM,CAAC,CAAC;YAC1B,MAAM,IAAI,CAAC,CAAC;YAEZ,IAAI,KAAK,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC;gBAC3B,SAAS;YACV,CAAC;YAED,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YAEjB,IAAI,KAAK,IAAI,KAAK,CAAC,MAAM,KAAK,WAAW,EAAE,CAAC;gBAC3C,MAAM;YACP,CAAC;QACF,CAAC;QAED,OAAO,EAAC,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,CAAC,MAAM,KAAK,CAAC,EAAC,CAAC;IACjD,CAAC,CAAC;IAEF,MAAM,QAAQ,GAA2C;QACxD,IAAI,EAAE,WAAW;QAEjB,CAAC,MAAM,CAAC,QAAQ,CAAC;YAChB,OAAO,IAAI,CAAC;QACb,CAAC;KACD,CAAC;IAEF,OAAO,QAAQ,CAAC;AACjB,CAAC,CAAC;AAnDW,QAAA,eAAe,mBAmD1B;AAEF,kBAAe,uBAAe,CAAC"} \ No newline at end of file diff --git a/dist/cjs/types/index.d.ts b/dist/cjs/types/index.d.ts index 05345e4..a2ca17f 100644 --- a/dist/cjs/types/index.d.ts +++ b/dist/cjs/types/index.d.ts @@ -1,11 +1,58 @@ export type Matcher = (item: T | unknown) => boolean; -export type TupleConfig = { +/** + * The invocation argument type + * + * @typeParam T - Type of items the input list contains + */ +export interface TupleConfig { + /** + * The input array to use + */ list: T[]; + /** + * The max number of items to return from the input array, per iteration + * @defaultValue 2 + */ maxItems?: number; + /** + * When provided, a function used to determine which items in the input array + * are eligible to be included, per iteration + */ match?: Matcher; -}; +} +/** + * An exception than can be thrown if there is no input array, `maxItems` is <= 0 or is not + * a number, or `match` is not a function + */ export declare class InvalidInvocationParameterError extends Error { } +/** + * Returns an iterable iterator that ouputs a configured + * list of items when iterating over a given array + * + * @typeParam T - Type of items the input list contains + * + * @param config - An object to indicate the input array `config.list`, and set the + * max size of items per interation `config.maxItems`. You can also optionally specify `config.match` + * as a function that should return true to filter in items from the input array + * (or false to filter them out) when deciding what items is to be included per iteration + * + * @function + * @throws InvalidInvocationParameterError + * This exception is thrown if there is no input array, `maxItems` is <= 0 or is not + * a number, or `match` is not a function + * + * @returns an IterableIterator + * + * @example + * Here is an example that will get max of 3 items from + * each iteration on the returned iterable + * ```javascript + * const iterable = tuplesFromArray({ + * list:[], maxSize: 3, match: (itm) => !!itm + * }); + * ``` + */ export declare const tuplesFromArray: (config: TupleConfig) => IterableIterator<(T | undefined)[]>; export default tuplesFromArray; //# sourceMappingURL=index.d.ts.map \ No newline at end of file diff --git a/dist/cjs/types/index.d.ts.map b/dist/cjs/types/index.d.ts.map index d9ec426..14ead46 100644 --- a/dist/cjs/types/index.d.ts.map +++ b/dist/cjs/types/index.d.ts.map @@ -1 +1 @@ -{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,OAAO,CAAC,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,GAAG,OAAO,KAAK,OAAO,CAAC;AACxD,MAAM,MAAM,WAAW,CAAC,CAAC,IAAI;IAC5B,IAAI,EAAE,CAAC,EAAE,CAAC;IACV,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,KAAK,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC;CACnB,CAAC;AAEF,qBAAa,+BAAgC,SAAQ,KAAK;CAAG;AAqB7D,eAAO,MAAM,eAAe,oEAmD3B,CAAC;AAEF,eAAe,eAAe,CAAC"} \ No newline at end of file +{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,OAAO,CAAC,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,GAAG,OAAO,KAAK,OAAO,CAAC;AAExD;;;;GAIG;AACH,MAAM,WAAW,WAAW,CAAC,CAAC;IAC7B;;OAEG;IACH,IAAI,EAAE,CAAC,EAAE,CAAC;IAEV;;;OAGG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAElB;;;OAGG;IACH,KAAK,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC;CACnB;AAED;;;GAGG;AACH,qBAAa,+BAAgC,SAAQ,KAAK;CAAG;AAqB7D;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,eAAO,MAAM,eAAe,oEAmD3B,CAAC;AAEF,eAAe,eAAe,CAAC"} \ No newline at end of file diff --git a/dist/esm/index.js.map b/dist/esm/index.js.map index 6ca0fe6..a32d11c 100644 --- a/dist/esm/index.js.map +++ b/dist/esm/index.js.map @@ -1 +1 @@ -{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AASA,MAAM,OAAO,+BAAgC,SAAQ,KAAK;CAAG;AAE7D,MAAM,yBAAyB,GAAG,CAAI,IAAS,EAAE,QAAgB,EAAE,KAA6B,EAAE,EAAE;IACnG,IAAI,CAAC,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC;QACnC,MAAM,IAAI,+BAA+B,CAAC,8BAA8B,CAAC,CAAC;IAC3E,CAAC;IAED,IACC,OAAO,QAAQ,KAAK,QAAQ;WACnB,CAAC,OAAO,QAAQ,KAAK,QAAQ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CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YAEjB,IAAI,KAAK,IAAI,KAAK,CAAC,MAAM,KAAK,WAAW,EAAE,CAAC;gBAC3C,MAAM;YACP,CAAC;QACF,CAAC;QAED,OAAO,EAAC,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,CAAC,MAAM,KAAK,CAAC,EAAC,CAAC;IACjD,CAAC,CAAC;IAEF,MAAM,QAAQ,GAA2C;QACxD,IAAI,EAAE,WAAW;QAEjB,CAAC,MAAM,CAAC,QAAQ,CAAC;YAChB,OAAO,IAAI,CAAC;QACb,CAAC;KACD,CAAC;IAEF,OAAO,QAAQ,CAAC;AACjB,CAAC,CAAC;AAEF,eAAe,eAAe,CAAC"} \ No newline at end of file diff --git a/dist/esm/index.mjs b/dist/esm/index.mjs index 08c7f8e..91c1b69 100644 --- a/dist/esm/index.mjs +++ b/dist/esm/index.mjs @@ -1,3 +1,8 @@ +; +/** + * An exception than can be thrown if there is no input array, `maxItems` is <= 0 or is not + * a number, or `match` is not a function + */ export class InvalidInvocationParameterError extends Error { } const validateParametersOrThrow = (list, maxItems, match) => { @@ -14,6 +19,33 @@ const validateParametersOrThrow = (list, maxItems, match) => { throw new InvalidInvocationParameterError(message); } }; +/** + * Returns an iterable iterator that ouputs a configured + * list of items when iterating over a given array + * + * @typeParam T - Type of items the input list contains + * + * @param config - An object to indicate the input array `config.list`, and set the + * max size of items per interation `config.maxItems`. You can also optionally specify `config.match` + * as a function that should return true to filter in items from the input array + * (or false to filter them out) when deciding what items is to be included per iteration + * + * @function + * @throws InvalidInvocationParameterError + * This exception is thrown if there is no input array, `maxItems` is <= 0 or is not + * a number, or `match` is not a function + * + * @returns an IterableIterator + * + * @example + * Here is an example that will get max of 3 items from + * each iteration on the returned iterable + * ```javascript + * const iterable = tuplesFromArray({ + * list:[], maxSize: 3, match: (itm) => !!itm + * }); + * ``` + */ export const tuplesFromArray = (config) => { const { list, match, maxItems = 2 } = config; validateParametersOrThrow(list, maxItems, match); diff --git a/dist/esm/types/index.d.ts b/dist/esm/types/index.d.ts index 05345e4..a2ca17f 100644 --- a/dist/esm/types/index.d.ts +++ b/dist/esm/types/index.d.ts @@ -1,11 +1,58 @@ export type Matcher = (item: T | unknown) => boolean; -export type TupleConfig = { +/** + * The invocation argument type + * + * @typeParam T - Type of items the input list contains + */ +export interface TupleConfig { + /** + * The input array to use + */ list: T[]; + /** + * The max number of items to return from the input array, per iteration + * @defaultValue 2 + */ maxItems?: number; + /** + * When provided, a function used to determine which items in the input array + * are eligible to be included, per iteration + */ match?: Matcher; -}; +} +/** + * An exception than can be thrown if there is no input array, `maxItems` is <= 0 or is not + * a number, or `match` is not a function + */ export declare class InvalidInvocationParameterError extends Error { } +/** + * Returns an iterable iterator that ouputs a configured + * list of items when iterating over a given array + * + * @typeParam T - Type of items the input list contains + * + * @param config - An object to indicate the input array `config.list`, and set the + * max size of items per interation `config.maxItems`. You can also optionally specify `config.match` + * as a function that should return true to filter in items from the input array + * (or false to filter them out) when deciding what items is to be included per iteration + * + * @function + * @throws InvalidInvocationParameterError + * This exception is thrown if there is no input array, `maxItems` is <= 0 or is not + * a number, or `match` is not a function + * + * @returns an IterableIterator + * + * @example + * Here is an example that will get max of 3 items from + * each iteration on the returned iterable + * ```javascript + * const iterable = tuplesFromArray({ + * list:[], maxSize: 3, match: (itm) => !!itm + * }); + * ``` + */ export declare const tuplesFromArray: (config: TupleConfig) => IterableIterator<(T | undefined)[]>; export default tuplesFromArray; //# sourceMappingURL=index.d.ts.map \ No newline at end of file diff --git a/dist/esm/types/index.d.ts.map b/dist/esm/types/index.d.ts.map index d9ec426..14ead46 100644 --- a/dist/esm/types/index.d.ts.map +++ b/dist/esm/types/index.d.ts.map @@ -1 +1 @@ -{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,OAAO,CAAC,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,GAAG,OAAO,KAAK,OAAO,CAAC;AACxD,MAAM,MAAM,WAAW,CAAC,CAAC,IAAI;IAC5B,IAAI,EAAE,CAAC,EAAE,CAAC;IACV,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,KAAK,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC;CACnB,CAAC;AAEF,qBAAa,+BAAgC,SAAQ,KAAK;CAAG;AAqB7D,eAAO,MAAM,eAAe,oEAmD3B,CAAC;AAEF,eAAe,eAAe,CAAC"} \ No newline at end of file +{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,OAAO,CAAC,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,GAAG,OAAO,KAAK,OAAO,CAAC;AAExD;;;;GAIG;AACH,MAAM,WAAW,WAAW,CAAC,CAAC;IAC7B;;OAEG;IACH,IAAI,EAAE,CAAC,EAAE,CAAC;IAEV;;;OAGG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAElB;;;OAGG;IACH,KAAK,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC;CACnB;AAED;;;GAGG;AACH,qBAAa,+BAAgC,SAAQ,KAAK;CAAG;AAqB7D;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,eAAO,MAAM,eAAe,oEAmD3B,CAAC;AAEF,eAAe,eAAe,CAAC"} \ No newline at end of file diff --git a/src/index.ts b/src/index.ts index 3bebe49..aff3840 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,12 +1,35 @@ type Result = IteratorResult, Array>; export type Matcher = (item: T | unknown) => boolean; -export type TupleConfig = { + +/** + * The invocation argument type + * + * @typeParam T - Type of items the input list contains + */ +export interface TupleConfig { + /** + * The input array to use + */ list: T[]; + + /** + * The max number of items to return from the input array, per iteration + * @defaultValue 2 + */ maxItems?: number; + + /** + * When provided, a function used to determine which items in the input array + * are eligible to be included, per iteration + */ match?: Matcher; }; +/** + * An exception than can be thrown if there is no input array, `maxItems` is <= 0 or is not + * a number, or `match` is not a function + */ export class InvalidInvocationParameterError extends Error {} const validateParametersOrThrow = (list: T[], maxItems: number, match: Matcher | undefined) => { @@ -28,6 +51,33 @@ const validateParametersOrThrow = (list: T[], maxItems: number, match: Matche } }; +/** + * Returns an iterable iterator that ouputs a configured + * list of items when iterating over a given array + * + * @typeParam T - Type of items the input list contains + * + * @param config - An object to indicate the input array `config.list`, and set the + * max size of items per interation `config.maxItems`. You can also optionally specify `config.match` + * as a function that should return true to filter in items from the input array + * (or false to filter them out) when deciding what items is to be included per iteration + * + * @function + * @throws InvalidInvocationParameterError + * This exception is thrown if there is no input array, `maxItems` is <= 0 or is not + * a number, or `match` is not a function + * + * @returns an IterableIterator + * + * @example + * Here is an example that will get max of 3 items from + * each iteration on the returned iterable + * ```javascript + * const iterable = tuplesFromArray({ + * list:[], maxSize: 3, match: (itm) => !!itm + * }); + * ``` + */ export const tuplesFromArray = (config: TupleConfig) => { const {list, match, maxItems = 2} = config; validateParametersOrThrow(list, maxItems, match); From d076ec381ee0129d2b8f331031dc32d383562234 Mon Sep 17 00:00:00 2001 From: Charles Opute Odili Date: Tue, 5 Mar 2024 21:42:06 -0700 Subject: [PATCH 31/37] document what is exported --- src/index.ts | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/src/index.ts b/src/index.ts index aff3840..ea90e85 100644 --- a/src/index.ts +++ b/src/index.ts @@ -2,12 +2,7 @@ type Result = IteratorResult, Array>; export type Matcher = (item: T | unknown) => boolean; -/** - * The invocation argument type - * - * @typeParam T - Type of items the input list contains - */ -export interface TupleConfig { +export type TupleConfig = { /** * The input array to use */ @@ -52,25 +47,25 @@ const validateParametersOrThrow = (list: T[], maxItems: number, match: Matche }; /** - * Returns an iterable iterator that ouputs a configured + * Returns an iterable iterator that ouputs a configured * list of items when iterating over a given array - * + * * @typeParam T - Type of items the input list contains - * + * * @param config - An object to indicate the input array `config.list`, and set the * max size of items per interation `config.maxItems`. You can also optionally specify `config.match` - * as a function that should return true to filter in items from the input array + * as a function that should return true to filter in items from the input array * (or false to filter them out) when deciding what items is to be included per iteration - * + * * @function * @throws InvalidInvocationParameterError * This exception is thrown if there is no input array, `maxItems` is <= 0 or is not * a number, or `match` is not a function - * + * * @returns an IterableIterator - * + * * @example - * Here is an example that will get max of 3 items from + * Here is an example that will get max of 3 items from * each iteration on the returned iterable * ```javascript * const iterable = tuplesFromArray({ From 1e8584a13a0d5d49be2ee0ff7a554494daf58668 Mon Sep 17 00:00:00 2001 From: Charles Opute Odili Date: Tue, 5 Mar 2024 21:53:18 -0700 Subject: [PATCH 32/37] update build --- dist/cjs/index.js | 1 - dist/cjs/index.js.map | 2 +- dist/cjs/types/index.d.ts | 9 ++------- dist/cjs/types/index.d.ts.map | 2 +- dist/esm/index.js.map | 2 +- dist/esm/index.mjs | 1 - dist/esm/types/index.d.ts | 9 ++------- dist/esm/types/index.d.ts.map | 2 +- 8 files changed, 8 insertions(+), 20 deletions(-) diff --git a/dist/cjs/index.js b/dist/cjs/index.js index f442bee..8d4c23e 100644 --- a/dist/cjs/index.js +++ b/dist/cjs/index.js @@ -1,7 +1,6 @@ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.tuplesFromArray = exports.InvalidInvocationParameterError = void 0; -; /** * An exception than can be thrown if there is no input array, `maxItems` is <= 0 or is not * a number, or `match` is not a function diff --git a/dist/cjs/index.js.map b/dist/cjs/index.js.map index 7e53e9e..402b09c 100644 --- a/dist/cjs/index.js.map +++ b/dist/cjs/index.js.map @@ -1 +1 @@ -{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;AA0BC,CAAC;AAEF;;;GAGG;AACH,MAAa,+BAAgC,SAAQ,KAAK;CAAG;AAA7D,0EAA6D;AAE7D,MAAM,yBAAyB,GAAG,CAAI,IAAS,EAAE,QAAgB,EAAE,KAA6B,EAAE,EAAE;IACnG,IAAI,CAAC,IAAI,IAAI,CAAC,KAAK,CAAC,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O,MAAM,GAAG,QAAQ,EAAE,CAAC;YAC1B,MAAM,IAAI,GAAG,IAAI,CAAC,MAAM,CAAC,CAAC;YAC1B,MAAM,IAAI,CAAC,CAAC;YAEZ,IAAI,KAAK,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC;gBAC3B,SAAS;YACV,CAAC;YAED,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YAEjB,IAAI,KAAK,IAAI,KAAK,CAAC,MAAM,KAAK,WAAW,EAAE,CAAC;gBAC3C,MAAM;YACP,CAAC;QACF,CAAC;QAED,OAAO,EAAC,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,CAAC,MAAM,KAAK,CAAC,EAAC,CAAC;IACjD,CAAC,CAAC;IAEF,MAAM,QAAQ,GAA2C;QACxD,IAAI,EAAE,WAAW;QAEjB,CAAC,MAAM,CAAC,QAAQ,CAAC;YAChB,OAAO,IAAI,CAAC;QACb,CAAC;KACD,CAAC;IAEF,OAAO,QAAQ,CAAC;AACjB,CAAC,CAAC;AAnDW,QAAA,eAAe,mBAmD1B;AAEF,kBAAe,uBAAe,CAAC"} \ No newline at end of file diff --git a/dist/cjs/types/index.d.ts b/dist/cjs/types/index.d.ts index a2ca17f..cbe5290 100644 --- a/dist/cjs/types/index.d.ts +++ b/dist/cjs/types/index.d.ts @@ -1,10 +1,5 @@ export type Matcher = (item: T | unknown) => boolean; -/** - * The invocation argument type - * - * @typeParam T - Type of items the input list contains - */ -export interface TupleConfig { +export type TupleConfig = { /** * The input array to use */ @@ -19,7 +14,7 @@ export interface TupleConfig { * are eligible to be included, per iteration */ match?: Matcher; -} +}; /** * An exception than can be thrown if there is no input array, `maxItems` is <= 0 or is not * a number, or `match` is not a function diff --git a/dist/cjs/types/index.d.ts.map b/dist/cjs/types/index.d.ts.map index 14ead46..cb8e02a 100644 --- a/dist/cjs/types/index.d.ts.map +++ b/dist/cjs/types/index.d.ts.map @@ -1 +1 @@ -{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,OAAO,CAAC,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,GAAG,OAAO,KAAK,OAAO,CAAC;AAExD;;;;GAIG;AACH,MAAM,WAAW,WAAW,CAAC,CAAC;IAC7B;;OAEG;IACH,IAAI,EAAE,CAAC,EAAE,CAAC;IAEV;;;OAGG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAElB;;;OAGG;IACH,KAAK,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC;CACnB;AAED;;;GAGG;AACH,qBAAa,+BAAgC,SAAQ,KAAK;CAAG;AAqB7D;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,eAAO,MAAM,eAAe,oEAmD3B,CAAC;AAEF,eAAe,eAAe,CAAC"} \ No newline at end of file +{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,OAAO,CAAC,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,GAAG,OAAO,KAAK,OAAO,CAAC;AAExD,MAAM,MAAM,WAAW,CAAC,CAAC,IAAI;IAC5B;;OAEG;IACH,IAAI,EAAE,CAAC,EAAE,CAAC;IAEV;;;OAGG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAElB;;;OAGG;IACH,KAAK,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC;CACnB,CAAC;AAEF;;;GAGG;AACH,qBAAa,+BAAgC,SAAQ,KAAK;CAAG;AAqB7D;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,eAAO,MAAM,eAAe,oEAmD3B,CAAC;AAEF,eAAe,eAAe,CAAC"} \ No newline at end of file diff --git a/dist/esm/index.js.map b/dist/esm/index.js.map index a32d11c..c284d3b 100644 --- a/dist/esm/index.js.map +++ b/dist/esm/index.js.map @@ -1 +1 @@ -{"version":3,"file":"index.js","sourceRoot":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DAAyD;YACzD,8CAA8C;YAC9C,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,MAAM,GAAG,WAAW,EAAE,IAAI,CAAC,MAAM,CAAC;YAE7C,4DAA4D;YAC5D,4DAA4D;YAC5D,uBAAuB;YACvB,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC;QAEf,OAAO,MAAM,GAAG,QAAQ,EAAE,CAAC;YAC1B,MAAM,IAAI,GAAG,IAAI,CAAC,MAAM,CAAC,CAAC;YAC1B,MAAM,IAAI,CAAC,CAAC;YAEZ,IAAI,KAAK,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC;gBAC3B,SAAS;YACV,CAAC;YAED,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YAEjB,IAAI,KAAK,IAAI,KAAK,CAAC,MAAM,KAAK,WAAW,EAAE,CAAC;gBAC3C,MAAM;YACP,CAAC;QACF,CAAC;QAED,OAAO,EAAC,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,CAAC,MAAM,KAAK,CAAC,EAAC,CAAC;IACjD,CAAC,CAAC;IAEF,MAAM,QAAQ,GAA2C;QACxD,IAAI,EAAE,WAAW;QAEjB,CAAC,MAAM,CAAC,QAAQ,CAAC;YAChB,OAAO,IAAI,CAAC;QACb,CAAC;KACD,CAAC;IAEF,OAAO,QAAQ,CAAC;AACjB,CAAC,CAAC;AAEF,eAAe,eAAe,CAAC"} \ No newline at end of file diff --git a/dist/esm/index.mjs b/dist/esm/index.mjs index 91c1b69..5bd2ab4 100644 --- a/dist/esm/index.mjs +++ b/dist/esm/index.mjs @@ -1,4 +1,3 @@ -; /** * An exception than can be thrown if there is no input array, `maxItems` is <= 0 or is not * a number, or `match` is not a function diff --git a/dist/esm/types/index.d.ts b/dist/esm/types/index.d.ts index a2ca17f..cbe5290 100644 --- a/dist/esm/types/index.d.ts +++ b/dist/esm/types/index.d.ts @@ -1,10 +1,5 @@ export type Matcher = (item: T | unknown) => boolean; -/** - * The invocation argument type - * - * @typeParam T - Type of items the input list contains - */ -export interface TupleConfig { +export type TupleConfig = { /** * The input array to use */ @@ -19,7 +14,7 @@ export interface TupleConfig { * are eligible to be included, per iteration */ match?: Matcher; -} +}; /** * An exception than can be thrown if there is no input array, `maxItems` is <= 0 or is not * a number, or `match` is not a function diff --git a/dist/esm/types/index.d.ts.map b/dist/esm/types/index.d.ts.map index 14ead46..cb8e02a 100644 --- a/dist/esm/types/index.d.ts.map +++ b/dist/esm/types/index.d.ts.map @@ -1 +1 @@ -{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,OAAO,CAAC,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,GAAG,OAAO,KAAK,OAAO,CAAC;AAExD;;;;GAIG;AACH,MAAM,WAAW,WAAW,CAAC,CAAC;IAC7B;;OAEG;IACH,IAAI,EAAE,CAAC,EAAE,CAAC;IAEV;;;OAGG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAElB;;;OAGG;IACH,KAAK,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC;CACnB;AAED;;;GAGG;AACH,qBAAa,+BAAgC,SAAQ,KAAK;CAAG;AAqB7D;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,eAAO,MAAM,eAAe,oEAmD3B,CAAC;AAEF,eAAe,eAAe,CAAC"} \ No newline at end of file +{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,OAAO,CAAC,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,GAAG,OAAO,KAAK,OAAO,CAAC;AAExD,MAAM,MAAM,WAAW,CAAC,CAAC,IAAI;IAC5B;;OAEG;IACH,IAAI,EAAE,CAAC,EAAE,CAAC;IAEV;;;OAGG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAElB;;;OAGG;IACH,KAAK,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC;CACnB,CAAC;AAEF;;;GAGG;AACH,qBAAa,+BAAgC,SAAQ,KAAK;CAAG;AAqB7D;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,eAAO,MAAM,eAAe,oEAmD3B,CAAC;AAEF,eAAe,eAAe,CAAC"} \ No newline at end of file From 6f347fb96819576b858e0cda3429c8550576d324 Mon Sep 17 00:00:00 2001 From: Charles Opute Odili Date: Tue, 5 Mar 2024 21:59:02 -0700 Subject: [PATCH 33/37] bump patch version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 246dd6f..bebbbcf 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@chalu/n-tuple-array", - "version": "0.1.5", + "version": "0.1.6", "description": "Get a specified amount of items when iterating over a JavaScript array, instead of just a single item that arrays provide!", "main": "./dist/cjs/index.js", "module": "dist/esm/index.mjs", From 99e91efe3d7c3bd02ff9057dfbd0f2e25fc353af Mon Sep 17 00:00:00 2001 From: Charles Opute Odili Date: Sun, 10 Mar 2024 14:03:05 -0600 Subject: [PATCH 34/37] cleanup project README --- README.md | 66 ++++++++++++++++++-------------- assets/the-dax-js-challenge.png | Bin 81467 -> 72755 bytes 2 files changed, 38 insertions(+), 28 deletions(-) diff --git a/README.md b/README.md index 926aeb9..020ecb6 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,8 @@ # n-tuple-array -Get a **`configurable`** amount of items when iterating over a JavaScript array, instead of a single item that arrays provide per iteration, by default. +Get a **`configurable`** amount of items when iterating over a JavaScript array, instead of a single item that arrays provide per iteration, by default. + +Put differently, easily and safely retrieve a configurable number of items from an array, without having to manipulate array bounds or indices. ## Motivation @@ -8,7 +10,7 @@ Get a **`configurable`** amount of items when iterating over a JavaScript array, Imagine that you received a large collection of coordinates (latitude and longitude), but they were sent as a flat array of values to speed up the data transfer. -`n-tuple-array` can help you get out the coordinates in pairs (i.e their logical representation), such that you'd go +`n-tuple-array` can help you get out the coordinates in pairs (i.e their logical representation), such that you'd __easily__ go **from** ```json @@ -16,17 +18,24 @@ as a flat array of values to speed up the data transfer. ["5.7225", "-9.6273", "2.68452", "-30.9501", ...] ``` -**to** +**to** +```json +// coordinates in pairs +[["5.7225", "-9.6273"], ["2.68452", "-30.9501"], ...] +``` + +**using** ```javascript // the iterable will generate pairs by default const coordsIterable = tuplesFromArray({ list: flatCoords }); -// using for..of, get pairs as ["5.7225", "-9.6273"] ... +// with for..of, get pairs as ["5.7225", "-9.6273"] ... for (const pair of coordsIterable) { console.log(pair); } -// OR manipulate pairs with regular array +// OR +// manipulate pairs with regular array // functions like map, filter, forEach ... const coordsInPairs = Array.from(coordsIterable); console.log(Array.isArray(coordsInPairs)); // true @@ -41,28 +50,6 @@ coordsInPairs }); ``` -### Some Real World Examples - -#### 1. Wole Joko - -I first tried my hands on this concept when [fleshing out wole-joko](https://github.com/chalu/wole-joko/blob/dev/src/js/utils.js#L57-L92), which strated as a _live coding task_ I was asked to do in an engineering manager interview :man_shrugging -It was a simulation of people entering an event hall to get seated, but **only two** could get in at a time - https://wole-joko.netlify.app/ - -#### 2. Execute max of `N` async tasks - -![](./assets/the-dax-js-challenge.png "JS challenge by @thdxr") - -> The below was adapted for more concise terminal output - -`n-tuple-array` solution. View [code here](https://github.com/chalu/n-tuple-array/blob/main/src/examples/classic.ts#L6-L40)
-![](./assets/demo-classic.png "n-tuple-array solution") -

- -`n-tuple-array` solution demo
-![](./assets/ntuple-array-demo-optimized.gif "n-tuple-array solution demo") - - - ## Setup & Usage ```bash @@ -84,16 +71,39 @@ const isEven = (item) => { return true; }; -// use the lib +// use the lib, get batches of <= 5 nums +// from the collection in numbers above const quintetIterator = tuplesFromArray({ list: numbers, maxItems: 5, match: isEven }); +// since quintetIterator uses the isEven match +// function, give us only even numbers in fives for (const quintet of quintetIterator) { // prints [ 2, 4, 6, 8, 10 ] ... [ 92, 94, 96, 98, 100 ] console.log(quintet); } ``` +### Some Real World Examples + +#### 1. Wole Joko + +I first tried my hands on this concept when [fleshing out wole-joko](https://github.com/chalu/wole-joko/blob/dev/src/js/utils.js#L57-L92), which strated as a _live coding task_ I was asked to do in an engineering manager interview :man_shrugging +It was a simulation of people entering an event hall to get seated, but **only two** could get in at a time - https://wole-joko.netlify.app/ + +#### 2. Execute max of `N` async tasks at the same time + +![](./assets/the-dax-js-challenge.png "JS challenge by @thdxr") + +> The below was adapted for more concise terminal output + +`n-tuple-array` solution. View [code here](https://github.com/chalu/n-tuple-array/blob/main/src/examples/classic.ts#L6-L40)
+![](./assets/demo-classic.png "n-tuple-array solution") +

+ +`n-tuple-array` solution demo
+![](./assets/ntuple-array-demo-optimized.gif) + See more examples in [src/examples](./src/examples/) diff --git a/assets/the-dax-js-challenge.png b/assets/the-dax-js-challenge.png index 41b9041dc579a2c99d558c65fe82171a30f9652b..0e19c02cb6d720953dac9ec3652094a9054adc63 100644 GIT binary patch delta 3592 zcmb7GWn9$T78L~P8c{~+92yCwQ^Emd7(x(`7*bS9LI&^;NC*NdNIS$J-Q6G^Qo_(N z@L)uTj-lgS?|avG--q|%ov-_M_TFc$eb(9yrz91%B=4Chv&gSpx^xN2L$MOb8OKTF zLd+ah6+<*m1MH^f7xP2{cKMimDBrc%ABMIc9Q8V`(OS{~f}f!x^qeh;&QLElC)n1?Opk6p;Y ztnbDV>T5yCiN^uFJKLM@o3p)B1iPq(n)9Hwi5bDD1YjRjiU_w*ay^=)5C|U<UpW(3c0iy~nQo?T#O7UbwGfkAt~@YQQEtD-2Vnyd8xk^3v#ctWBQFNt80V|3^vtn4c6v{!-o9M2+9lh z=f&^bl1fp6!&0#uP0w8qHXgGme(Y_7S3DMMh-{4>T;px_!l4E0$)@Gejc8(@?(!+e z;b%P0dcP{Xngx%6zttR16gYEObqQBK8NHI%3s5-DWJf)e?mSGoy`&Q?VsY4po}Y2J zDM81EP;HX)s~arvyRA%8w%s5@?J)B_$`3`IeEvE#J;%=blcJ|uQ%>z6aVU*GKb?zj0L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jQ@B!zrP&8i}ShmNkZNpAdi%f14 zYB0rID>;jB zM7zjQb4{mwtrZzL3BD{S!NhGOll%QT@ZeX6S7op>;RA#|iZHlr&M$n_7+P|n@O~&P z+xk^hKYQJfY*nj>%sY7D5&12wcAmAOJrEwn7^jl;g> z1}FRBk3ZZQcE_!#77MiOi+T^o=p>8AiRfL;PZcYj+KeMVoy|WNG0LPBDr=1}<(s6$ z;fIPh&;jqoYE3=@w{)-z)}LxA!nO{07D*-7>}*NIaMH2TH8RGE=VUEo25PPm) zD@`<=OZ0*{YY;?&-awZm1`6hIDM23izyPRCahlc1&P^BfzKuZ}j1? z=`@By=@Zm>GSMAZFc;6aK_d8M{Gm@WAuICK8)m!J@p6Ly58X~PSdN`5|~oIGiQ`$ZXxX}z%thvjUP32lq-J=#y7L<7-bsVX4q zlL?;&E=JP{zaK-?c0Ukafc7aa!~dHKg(BB6vt{qN3ki<}WivNQtjV^5pCMbe#@qvV zQJh{s@9#7f>dLrK;AAhv~!2aB55jyEa= zwUjEIc1YC;pH-kNdl)M36%gE`*7DympCIg)8p^|dV%B#bmo}Z<;+;3?y?wp5`~F|n)j!M%BiPx+K=j4un@6-w zC@iP*JFV){C$l|T{6iwPo__oUY@E7{EVBLWTJWclh8irw<=?f*{lj1(1pD?yxMwHw zKg|&o7z0R(vl8b>CfEOTT|oUAnWz6SMnGQy5OsjQy^=TVlF#2i^QZceUA)ixw^!${ zCo82x4Hs{+gj}=!VYu*vS~G6Z{wo#GhYP)-hGt`cI%e(PzSBQ_&CnQM{@*bI|4ESl si!lQKNs#}GF|z%;9{yj6JOj`T8u$A?WL81{JOCplCNEm~$spkW0PZGeYXATM From 6128432b90a8f53ce7d6ff100bae8fde81076ea8 Mon Sep 17 00:00:00 2001 From: Charles Opute Odili Date: Sun, 10 Mar 2024 15:36:14 -0600 Subject: [PATCH 35/37] update js examples for cleaner output --- src/examples/js/concurrent.js | 5 +++-- src/examples/js/with-lib.mjs | 6 +++--- src/examples/js/without-lib.js | 6 +++--- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/examples/js/concurrent.js b/src/examples/js/concurrent.js index 0ad348e..ee5b52f 100644 --- a/src/examples/js/concurrent.js +++ b/src/examples/js/concurrent.js @@ -14,6 +14,7 @@ const processTask = async (todo, batchId) => { }; const executeConcurrent = async (todos, maxBatchSize) => { + console.log(`\ndo <= ${maxBatchSize} of ${todos.length} tasks (concurrently), at any given time\n`); const done = []; const todosCopy = todos.slice(); const worker = async (_, batchIndex) => { @@ -23,7 +24,7 @@ const executeConcurrent = async (todos, maxBatchSize) => { done.push(result); todo = todosCopy.shift(); } - }; + }; const batchStarters = Array.from({length: maxBatchSize}, worker); await Promise.all(batchStarters); @@ -35,5 +36,5 @@ const executeConcurrent = async (todos, maxBatchSize) => { const maxTasksPerTime = 2; const allDone = await executeConcurrent(tasks, maxTasksPerTime); - console.log(allDone); + console.log('\n', allDone); })(); diff --git a/src/examples/js/with-lib.mjs b/src/examples/js/with-lib.mjs index 02a5c6f..8bb31e6 100644 --- a/src/examples/js/with-lib.mjs +++ b/src/examples/js/with-lib.mjs @@ -16,13 +16,13 @@ const processTask = async (todo, batchId) => { }; const executeWitLibrary = async (todos, maxBatchSize) => { - console.log(`do <= ${maxBatchSize} of ${todos.length} tasks, at any given time`); + console.log(`\ndo <= ${maxBatchSize} of ${todos.length} tasks, at any given time (with library)`); const done = []; let batchIndex = 1; const todosBatchIterable = tuplesFromArray({list: todos, maxItems: maxBatchSize}); for (const batch of todosBatchIterable) { - console.log(`----- starting batch [${batchIndex}], ${batch.length} todos`); + console.log(`\n----- starting batch [${batchIndex}], ${batch.length} todos`); const results = await Promise.allSettled( batch.map(todo => processTask(todo, batchIndex)), ); @@ -39,5 +39,5 @@ const executeWitLibrary = async (todos, maxBatchSize) => { const maxTasksPerTime = 2; const allDone = await executeWitLibrary(tasks, maxTasksPerTime); - console.log(allDone); + console.log('\n', allDone); })(); diff --git a/src/examples/js/without-lib.js b/src/examples/js/without-lib.js index e9803b7..5f7de65 100644 --- a/src/examples/js/without-lib.js +++ b/src/examples/js/without-lib.js @@ -15,7 +15,7 @@ const processTask = async (todo, batchId) => { // Everywhere start/end is used is repititive and error prone const executeWithoutLibrary = async (todos, maxBatchSize) => { - console.log(`do <= ${maxBatchSize} of ${todos.length} tasks, at any given time`); + console.log(`\ndo <= ${maxBatchSize} of ${todos.length} tasks, at any given time (no library)`); const done = []; let start = 0; @@ -23,7 +23,7 @@ const executeWithoutLibrary = async (todos, maxBatchSize) => { let batchIndex = 1; let batch = todos.slice(start, end); while (batch.length > 0) { - console.log(`----- starting batch [${batchIndex}], ${batch.length} todos`); + console.log(`\n----- starting batch [${batchIndex}], ${batch.length} todos`); const results = await Promise.allSettled( batch.map(todo => processTask(todo, batchIndex)), ); @@ -48,5 +48,5 @@ const executeWithoutLibrary = async (todos, maxBatchSize) => { const maxTasksPerTime = 2; const allDone = await executeWithoutLibrary(tasks, maxTasksPerTime); - console.log(allDone); + console.log('\n', allDone); })(); From 655a4201c0a9e8b9ccf4a979b3c073b42ebb5659 Mon Sep 17 00:00:00 2001 From: Charles Opute Odili Date: Sun, 10 Mar 2024 15:38:59 -0600 Subject: [PATCH 36/37] update concurrent example for cleaner output --- src/examples/js/concurrent.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/examples/js/concurrent.js b/src/examples/js/concurrent.js index ee5b52f..3eed0d2 100644 --- a/src/examples/js/concurrent.js +++ b/src/examples/js/concurrent.js @@ -24,7 +24,7 @@ const executeConcurrent = async (todos, maxBatchSize) => { done.push(result); todo = todosCopy.shift(); } - }; + }; const batchStarters = Array.from({length: maxBatchSize}, worker); await Promise.all(batchStarters); From 6eeeea05ccd0497b5b868e553e9519bf770838ae Mon Sep 17 00:00:00 2001 From: Charles Opute Odili Date: Mon, 11 Mar 2024 07:38:59 -0600 Subject: [PATCH 37/37] bump version for patch --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index bebbbcf..756d300 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@chalu/n-tuple-array", - "version": "0.1.6", - "description": "Get a specified amount of items when iterating over a JavaScript array, instead of just a single item that arrays provide!", + "version": "0.1.7", + "description": "Configure and get a specified amount of items when iterating over a JavaScript array.", "main": "./dist/cjs/index.js", "module": "dist/esm/index.mjs", "types": "./dist/cjs/types/index.d.ts",