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

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions .github/workflows/CD.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: CD
on:
pull_request:
types: [ closed ]

jobs:
publish-to-registry:
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 }}

4 changes: 0 additions & 4 deletions .github/workflows/CI.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
name: CI
on:
push:
branches:
- "!main"
- "*"
pull_request:
branches:
- "dev"
Expand Down
15 changes: 11 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ JS challenge by @thdxr on X.com <br>
<br> <br>

`n-tuple-array` solution code <br>
[<img src="./assets/demo-classic.png">](./assets/demo-classic.svg)
[<img src="./assets/demo-classic.png">](https://github.com/chalu/n-tuple-array/blob/main/src/demo/demo-classic.ts#L6-L40)
<br> <br>

`n-tuple-array` n-tuple-array solution demo <br>
Expand All @@ -56,12 +56,13 @@ JS challenge by @thdxr on X.com <br>
## 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 (
Expand All @@ -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);
}
```

Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -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'",
Expand Down