From e3d7111442f34dfaa3ae996a680b1be6cf39a3d3 Mon Sep 17 00:00:00 2001 From: Charles Opute Odili Date: Sun, 18 Feb 2024 06:49:19 -0700 Subject: [PATCH 1/5] 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 2/5] 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 3/5] 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 4/5] 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 5/5] 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"