Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
e7db04f
init
chalu Feb 15, 2024
0132918
get started with the implementation
chalu Feb 15, 2024
f6241ef
allow caller filter in elements with a match function
chalu Feb 15, 2024
9ea6c84
setup unit tests
chalu Feb 15, 2024
477c5df
add smoke tests for the list parameter
chalu Feb 15, 2024
a8513ce
add smoke tests for maxItems param
chalu Feb 15, 2024
87d8c36
add smoke tests for the match param
chalu Feb 15, 2024
9b41f0a
refactor param validation into a separate function
chalu Feb 15, 2024
3a9dfbf
add basic CI workflow
chalu Feb 15, 2024
72bf07d
re-add CI workflow file
chalu Feb 15, 2024
3795560
add catch all branch in CI workflow
chalu Feb 15, 2024
e2c42cd
try install pnpm before node in CI workflow
chalu Feb 15, 2024
7c81b61
attempt display test summary on GHA overview page
chalu Feb 15, 2024
18b2461
add TAP reporter for tests in CI
chalu Feb 15, 2024
15eada8
attempt junit reporter for summary in CI
chalu Feb 15, 2024
66f93e3
remove TAP reporter
chalu Feb 15, 2024
e1efbf2
improve setup for tests
chalu Feb 16, 2024
97db447
add matchers from jest-extended
chalu Feb 16, 2024
5aa4f84
add smoke tests
chalu Feb 16, 2024
ac99976
add festures tests
chalu Feb 16, 2024
ae39890
enforce code style with XO
chalu Feb 16, 2024
433c458
add pre-commit hook to run lint, build, and test scripts
chalu Feb 16, 2024
6c9f083
simplify pre-commit script
chalu Feb 16, 2024
c0646b8
add built files in dist folder
chalu Feb 16, 2024
ea42403
Merge pull request #5 from chalu/add-unit-tests
chalu Feb 16, 2024
abb0cd8
add docs and samples (#7)
chalu Feb 17, 2024
5c8e09d
Merge branch 'main' into dev
chalu Feb 17, 2024
6c301d0
Go publish (#9)
chalu Feb 18, 2024
2f62a5d
Merge branch 'main' into dev
chalu Feb 18, 2024
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