Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: trojs/arrays
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 6.0.2
Choose a base ref
...
head repository: trojs/arrays
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: main
Choose a head ref
Loading
68 changes: 68 additions & 0 deletions .github/copilot-instructions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# Copilot Instructions

## Philosophy

- **Pure Functions**: Favor pure functions (no side effects, no mutation, deterministic) as advocated by Eric Elliott.
- **Test-Driven Development (TDD)**: Write tests first, code in small, testable increments, following Uncle Bob’s TDD cycle.
- **Extreme Programming (XP)**: Embrace simplicity, communication, feedback, and courage. Prefer small, frequent, high-quality changes.
- **Framework Agnostic**: Do not use any frameworks or libraries unless explicitly requested. Use only standard JavaScript (ESM).
- **JSDoc**: All functions, classes, and modules must be documented with JSDoc for type safety and clarity.
- **Design Patterns**: Use classic, well-known patterns (factory, strategy, observer, etc.) only when they add clarity or testability.
- **Clean Code**: Prioritize readability, maintainability, and simplicity. Avoid cleverness for its own sake.
- **Testability**: All code should be easily testable. Avoid hidden dependencies and global state.
- **Small Iterations**: Make small, incremental changes. Each change should be easy to review and test.
- **No Frameworks**: Do not use React, Vue, Angular, or any other framework. No build tools unless explicitly requested.

## Coding Guidelines

- Use **ES Modules** (`import`/`export`).
- Use **pure functions** wherever possible.
- Use **const** and **let** (never `var`).
- Use **arrow functions** for short, stateless functions.
- Use **descriptive names** for variables, functions, and classes.
- **No mutation** of input arguments.
- **No side effects** in pure functions.
- **No global state** unless absolutely necessary (and then, document it).
- **JSDoc** for every function, class, and exported symbol.
- **Write a test** for every new function or feature (see `/src/*.test.js` for examples).
- **Keep files small** and focused on a single responsibility.
- **No magic numbers**—use named constants.
- **No unnecessary abstractions**—keep it simple.

## Example Function

```js
/**
* Adds two numbers (pure function).
* @param {number} a
* @param {number} b
* @returns {number}
*/
export const add = (a, b) => a + b
```

## Example Test

```js
import assert from 'node:assert/strict'
import { add } from './add.js'

assert.equal(add(2, 3), 5)
```

## When in Doubt

- **Ask for clarification** if requirements are unclear.
- **Prefer simplicity** over cleverness.
- **Write tests** for all edge cases.
- **Document** all exported symbols with JSDoc.

---

**Summary:**
Write clean, pure, framework-agnostic JavaScript (ESM) with JSDoc and tests.
Favor small, testable, incremental changes.
No frameworks, no unnecessary abstractions, no side effects.

---

1 change: 1 addition & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -18,5 +18,6 @@ jobs:
run: |
npm ci
npm run lint
npm run lint:types
env:
CI: true
36 changes: 21 additions & 15 deletions .github/workflows/npm-publish.yml
Original file line number Diff line number Diff line change
@@ -1,34 +1,40 @@
# This workflow will run tests using node and then publish a package to GitHub Packages when a release is created
# For more information see: https://help.github.com/actions/language-and-framework-guides/publishing-nodejs-packages

name: Node.js Package

on:
release:
types: [created]

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 22
- run: npm ci
- run: npm test

publish-npm:
needs: build
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write
steps:
- uses: actions/checkout@v4
with:
token: ${{ secrets.GH_PAT }} # Use your PAT here!
- uses: actions/setup-node@v4
with:
node-version: 22
registry-url: https://registry.npmjs.org/
- run: npm ci
- name: Set version from tag
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
TAG=${GITHUB_REF#refs/tags/}
TAG=${TAG#v}
git fetch origin main
git checkout main
git pull
npm version $TAG --no-git-tag-version
jq '.version = "'$TAG'"' jsr.json > jsr.json.tmp && mv jsr.json.tmp jsr.json
git add package.json package-lock.json jsr.json
git commit -m "ci: set version to $TAG [skip ci]" || true
git push origin main
- run: npm run build --if-present
- run: npm publish --access public
env:
NODE_AUTH_TOKEN: ${{secrets.npm_token}}
NODE_AUTH_TOKEN: ${{ secrets.npm_token }}
- run: npx jsr publish
37 changes: 23 additions & 14 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -4,23 +4,32 @@ on: [push]

jobs:
build:

runs-on: ubuntu-latest

strategy:
matrix:
node-version: [20.x, 21.x, 22.x, 23.x]
node-version: [22.x, 23.x, 24.x]

steps:
- uses: actions/checkout@v4
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
- name: npm test
run: |
npm ci
npm test
env:
CI: true
- uses: actions/checkout@v4
- name: Cache node_modules
uses: actions/cache@v4
with:
path: |
~/.npm
node_modules
key: ${{ runner.os }}-node-${{ matrix.node-version }}-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-${{ matrix.node-version }}-
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
cache: "npm"
- name: npm test
run: |
npm ci
npm test
env:
CI: true
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
22.14.0
24
16 changes: 15 additions & 1 deletion jsconfig.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,28 @@
{
"compilerOptions": {
"allowJs": true,
"checkJs": true,
"target": "ESNext",
"module": "NodeNext",
"moduleResolution": "nodenext",
"lib": [
"ESNext"
],
"rootDirs": [
"src"
],
"resolveJsonModule": true
"baseUrl": ".",
"resolveJsonModule": true,
"types": [
"node"
],
"skipLibCheck": true,
"esModuleInterop": true,
"noEmit": true
},
"include": [
"src/**/*"
],
"exclude": [
"node_modules",
"**/node_modules/*"
6 changes: 6 additions & 0 deletions jsr.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name": "@trojs/arrays",
"version": "7.1.10",
"license": "MIT",
"exports": "./src/helpers.js"
}
Loading