Skip to content

Commit 6ff6dfb

Browse files
committed
fix: address review feedback
CI: add permissions: contents: read, persist-credentials: false. package.json: nested types in exports for CJS/ESM, add typecheck script. eid.ts: fix %s injection in JFormatter (single-pass replace). preconditions.ts: fix off-by-one in checkElementIndex (index >= size). index.ts: remove misleading backward compat block. Assisted-by: 🤖 claude-opus-4-6@default
1 parent 80f34b5 commit 6ff6dfb

5 files changed

Lines changed: 24 additions & 19 deletions

File tree

.github/workflows/ci.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ on:
66
pull_request:
77
branches: [master, develop]
88

9+
permissions:
10+
contents: read
11+
912
concurrency:
1013
group: ${{ github.workflow }}-${{ github.ref }}
1114
cancel-in-progress: true
@@ -17,6 +20,8 @@ jobs:
1720
timeout-minutes: 5
1821
steps:
1922
- uses: actions/checkout@v4
23+
with:
24+
persist-credentials: false
2025
- uses: actions/setup-node@v4
2126
with:
2227
node-version: 22
@@ -33,6 +38,8 @@ jobs:
3338
node-version: [20, 22]
3439
steps:
3540
- uses: actions/checkout@v4
41+
with:
42+
persist-credentials: false
3643
- uses: actions/setup-node@v4
3744
with:
3845
node-version: ${{ matrix.node-version }}
@@ -47,6 +54,8 @@ jobs:
4754
needs: [lint, test]
4855
steps:
4956
- uses: actions/checkout@v4
57+
with:
58+
persist-credentials: false
5059
- uses: actions/setup-node@v4
5160
with:
5261
node-version: 22

package.json

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,14 @@
99
"unpkg": "./dist/index.global.js",
1010
"exports": {
1111
".": {
12-
"types": "./dist/index.d.ts",
13-
"import": "./dist/index.mjs",
14-
"require": "./dist/index.cjs",
12+
"import": {
13+
"types": "./dist/index.d.ts",
14+
"default": "./dist/index.mjs"
15+
},
16+
"require": {
17+
"types": "./dist/index.d.cts",
18+
"default": "./dist/index.cjs"
19+
},
1520
"default": "./dist/index.mjs"
1621
},
1722
"./package.json": "./package.json"
@@ -24,13 +29,14 @@
2429
},
2530
"scripts": {
2631
"build": "tsup",
32+
"typecheck": "tsc --noEmit",
2733
"test": "vitest run",
2834
"test:watch": "vitest",
2935
"test:coverage": "vitest run --coverage",
3036
"lint": "biome check src/",
3137
"lint:fix": "biome check --write src/",
3238
"format": "biome format --write src/",
33-
"prepublishOnly": "npm run lint && npm run test && npm run build",
39+
"prepublishOnly": "npm run typecheck && npm run lint && npm run test && npm run build",
3440
"clean": "rm -rf dist coverage"
3541
},
3642
"dependencies": {},

src/eid.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,10 @@ class JFormatter {
2626
}
2727

2828
format(args: unknown[]): string {
29-
const regex = /%s/;
30-
const reducer = (p: string, c: unknown): string => p.replace(regex, String(c));
31-
return args.reduce(reducer, this.template) as string;
29+
let i = 0;
30+
return this.template.replace(/%s/g, () => {
31+
return i < args.length ? String(args[i++]) : "%s";
32+
});
3233
}
3334
}
3435

src/index.ts

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,4 @@ import {
3535
} from "./exceptions";
3636
import { EidPreconditions } from "./preconditions";
3737

38-
// Backward compatibility: attach preconditions and exceptions to Eid
39-
const preconditions = EidPreconditions;
40-
const exceptions = {
41-
EidRuntimeException,
42-
EidNullPointerException,
43-
EidIllegalArgumentException,
44-
EidIllegalStateException,
45-
EidIndexOutOfBoundsException,
46-
};
47-
48-
export { preconditions, exceptions };
4938
export default Eid;

src/preconditions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ function ensureEid(candidate: string | Eid | null | undefined): Eid {
4343
}
4444

4545
function isIndexAndSizeIllegal(index: number, size: number): boolean {
46-
return index < 0 || index > size;
46+
return index < 0 || index >= size;
4747
}
4848

4949
function isSizeIllegal(size: number): boolean {

0 commit comments

Comments
 (0)