Skip to content

Commit d746c75

Browse files
dependency updates (#13)
1 parent 303b49b commit d746c75

10 files changed

+2946
-6227
lines changed

.github/dependabot.yml

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
version: 2
2+
updates:
3+
- package-ecosystem: 'npm'
4+
directory: '/'
5+
schedule:
6+
interval: 'weekly'
7+
groups:
8+
# Group everything except major version updates
9+
# and security vulnerabilities together
10+
regular-updates:
11+
update-types:
12+
- 'minor'
13+
- 'patch'
14+
15+
- package-ecosystem: 'github-actions'
16+
directory: '/'
17+
schedule:
18+
interval: 'weekly'

.github/workflows/test_and_lint.yml

+7-4
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,18 @@ on:
1111

1212
jobs:
1313
test:
14-
1514
runs-on: ubuntu-latest
1615

16+
strategy:
17+
matrix:
18+
node-version: [18, 20, 22]
19+
1720
steps:
18-
- uses: actions/checkout@v3
21+
- uses: actions/checkout@v4
1922
- name: Use Node.js
20-
uses: actions/setup-node@v3
23+
uses: actions/setup-node@v4
2124
with:
22-
node-version: '16'
25+
node-version: ${{ matrix.node-version }}
2326
- name: Install dependencies
2427
run: npm install
2528
- name: Run eslint

CHANGELOG.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@
99

1010
- Allows passing an existing `FormData` object
1111

12-
## [v1.0.0]
12+
## [v1.0.0]
1313

1414
- Initial release

README.md

+10-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,16 @@ This is mainly intended for testing JavaScript components that generate HTML for
88

99
```html
1010
<form>
11-
<input type="hidden" name="foo[bar][][id]" value="1" />
12-
<input type="hidden" name="foo[bar][][id]" value="2" />
11+
<input
12+
type="hidden"
13+
name="foo[bar][][id]"
14+
value="1"
15+
/>
16+
<input
17+
type="hidden"
18+
name="foo[bar][][id]"
19+
value="2"
20+
/>
1321
</form>
1422
```
1523

eslint.config.mjs

+73
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
import comments from '@eslint-community/eslint-plugin-eslint-comments/configs';
2+
import eslintConfigPrettier from 'eslint-config-prettier';
3+
import globals from 'globals';
4+
import importPlugin from 'eslint-plugin-import';
5+
import jest from 'eslint-plugin-jest';
6+
import js from '@eslint/js';
7+
8+
export default [
9+
{
10+
ignores: ['node_modules'],
11+
},
12+
js.configs.recommended,
13+
importPlugin.flatConfigs.recommended,
14+
comments.recommended,
15+
eslintConfigPrettier,
16+
{
17+
languageOptions: {
18+
globals: {
19+
...globals.browser,
20+
},
21+
22+
ecmaVersion: 'latest',
23+
sourceType: 'module',
24+
},
25+
26+
settings: {
27+
'import/resolver': {
28+
node: {
29+
extensions: ['.js', '.json'],
30+
},
31+
},
32+
},
33+
34+
rules: {
35+
'@eslint-community/eslint-comments/no-unused-disable': 'error',
36+
37+
'@eslint-community/eslint-comments/disable-enable-pair': [
38+
'error',
39+
{
40+
allowWholeFile: true,
41+
},
42+
],
43+
},
44+
},
45+
{
46+
files: ['**/*.test.js'],
47+
48+
plugins: {
49+
jest,
50+
},
51+
52+
languageOptions: {
53+
globals: {
54+
...globals.jest,
55+
require: false,
56+
},
57+
},
58+
59+
rules: {
60+
...jest.configs['flat/recommended'].rules,
61+
'import/no-extraneous-dependencies': 'off',
62+
'jest/expect-expect': 'off',
63+
'jest/no-standalone-expect': 'off',
64+
},
65+
},
66+
{
67+
files: ['eslint.config.mjs', 'jest.config.js'],
68+
69+
rules: {
70+
'import/no-default-export': 'off',
71+
},
72+
},
73+
];

index.js

+12-4
Original file line numberDiff line numberDiff line change
@@ -63,26 +63,34 @@ function normalizeParams(params, name, v, depth) {
6363
} else if (after === '[]') {
6464
params[k] ||= [];
6565
if (!Array.isArray(params[k])) {
66-
throw new Error(`expected Array (got ${typeof params[k]}) for param \`${k}\``);
66+
throw new Error(
67+
`expected Array (got ${typeof params[k]}) for param \`${k}\``,
68+
);
6769
}
6870
params[k].push(v);
6971
} else if (after.startsWith('[]')) {
7072
// Recognize x[][y] (hash inside array) parameters
7173
const childKey = after.slice(2, after.length);
7274
params[k] ||= [];
7375
if (!Array.isArray(params[k])) {
74-
throw new Error(`expected Array (got ${typeof params[k]}) for param \`${k}\``);
76+
throw new Error(
77+
`expected Array (got ${typeof params[k]}) for param \`${k}\``,
78+
);
7579
}
7680
const last = params[k][params[k].length - 1];
7781
if (typeof last === 'object' && !paramsHashHasKey(last, childKey)) {
7882
normalizeParams(last, childKey, v, depth + 1);
7983
} else {
80-
params[k].push(normalizeParams(Object.create(null), childKey, v, depth + 1));
84+
params[k].push(
85+
normalizeParams(Object.create(null), childKey, v, depth + 1),
86+
);
8187
}
8288
} else {
8389
params[k] ||= Object.create(null);
8490
if (typeof params[k] !== 'object') {
85-
throw new Error(`expected Hash (got ${params[k].constructor?.name}) for param \`${k}\``);
91+
throw new Error(
92+
`expected Hash (got ${params[k].constructor?.name}) for param \`${k}\``,
93+
);
8694
}
8795
params[k] = normalizeParams(params[k], after, v, depth + 1);
8896
}

index.test.js

+44-9
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,10 @@ describe.each([
2424
['foo=bar&foo=quux', { foo: 'quux' }],
2525
['foo=1&bar=2', { foo: '1', bar: '2' }],
2626
['foo=bar&baz=', { foo: 'bar', baz: '' }],
27-
['my+weird+field=q1%212%22%27w%245%267%2Fz8%29%3F', { 'my weird field': 'q1!2"\'w$5&7/z8)?' }],
27+
[
28+
'my+weird+field=q1%212%22%27w%245%267%2Fz8%29%3F',
29+
{ 'my weird field': 'q1!2"\'w$5&7/z8)?' },
30+
],
2831
['a=b&pid%3D1234=1023', { 'pid=1234': '1023', a: 'b' }],
2932
['foo[]=', { foo: [''] }],
3033
['foo[]=bar', { foo: ['bar'] }],
@@ -43,10 +46,39 @@ describe.each([
4346
['x[y][][v][w]=1', { x: { y: [{ v: { w: '1' } }] } }],
4447
['x[y][][z]=1&x[y][][v][w]=2', { x: { y: [{ z: '1', v: { w: '2' } }] } }],
4548
['x[y][][z]=1&x[y][][z]=2', { x: { y: [{ z: '1' }, { z: '2' }] } }],
46-
['x[y][][z]=1&x[y][][w]=a&x[y][][z]=2&x[y][][w]=3', { x: { y: [{ z: '1', w: 'a' }, { z: '2', w: '3' }] } }],
47-
['x[][y]=1&x[][z][w]=a&x[][y]=2&x[][z][w]=b', { x: [{ y: '1', z: { w: 'a' } }, { y: '2', z: { w: 'b' } }] }],
48-
['x[][z][w]=a&x[][y]=1&x[][z][w]=b&x[][y]=2', { x: [{ y: '1', z: { w: 'a' } }, { y: '2', z: { w: 'b' } }] }],
49-
['data[books][][data][page]=1&data[books][][data][page]=2', { data: { books: [{ data: { page: '1' } }, { data: { page: '2' } }] } }],
49+
[
50+
'x[y][][z]=1&x[y][][w]=a&x[y][][z]=2&x[y][][w]=3',
51+
{
52+
x: {
53+
y: [
54+
{ z: '1', w: 'a' },
55+
{ z: '2', w: '3' },
56+
],
57+
},
58+
},
59+
],
60+
[
61+
'x[][y]=1&x[][z][w]=a&x[][y]=2&x[][z][w]=b',
62+
{
63+
x: [
64+
{ y: '1', z: { w: 'a' } },
65+
{ y: '2', z: { w: 'b' } },
66+
],
67+
},
68+
],
69+
[
70+
'x[][z][w]=a&x[][y]=1&x[][z][w]=b&x[][y]=2',
71+
{
72+
x: [
73+
{ y: '1', z: { w: 'a' } },
74+
{ y: '2', z: { w: 'b' } },
75+
],
76+
},
77+
],
78+
[
79+
'data[books][][data][page]=1&data[books][][data][page]=2',
80+
{ data: { books: [{ data: { page: '1' } }, { data: { page: '2' } }] } },
81+
],
5082
['x[][y][][z]=1&x[][y][][w]=2', { x: [{ y: [{ z: '1', w: '2' }] }] }],
5183
[
5284
'x[][id]=1&x[][y][a]=5&x[][y][b]=7&x[][z][id]=3&x[][z][w]=0&x[][id]=2&x[][y][a]=6&x[][y][b]=8&x[][z][id]=4&x[][z][w]=0',
@@ -58,7 +90,10 @@ describe.each([
5890
},
5991
],
6092
['[]=1&[a]=2&b[=3&c]=4', { '[]': '1', '[a]': '2', 'b[': '3', 'c]': '4' }],
61-
['d[[]=5&e][]=6&f[[]]=7', { d: { '[': '5' }, 'e]': ['6'], f: { '[': { ']': '7' } } }],
93+
[
94+
'd[[]=5&e][]=6&f[[]]=7',
95+
{ d: { '[': '5' }, 'e]': ['6'], f: { '[': { ']': '7' } } },
96+
],
6297
['g[h]i=8&j[k]l[m]=9', { g: { h: { i: '8' } }, j: { k: { 'l[m]': '9' } } }],
6398
['l[[[[[[[[]]]]]]]=10', { l: { '[[[[[[[': { ']]]]]]': '10' } } }],
6499
['[foo]=1', { '[foo]': '1' }],
@@ -77,7 +112,7 @@ describe('foo[__proto__][x]=1', () => {
77112
const form = document.querySelector('form');
78113

79114
const ob = Object.create(null);
80-
ob.__proto__ = { x: '1' }; // eslint-disable-line no-proto
115+
ob.__proto__ = { x: '1' };
81116

82117
expect(formToRackParams(form)).toEqual({ foo: ob });
83118
});
@@ -90,7 +125,7 @@ describe('foo[][__proto__][x]=1', () => {
90125
const form = document.querySelector('form');
91126

92127
const ob = Object.create(null);
93-
ob.__proto__ = { x: '1' }; // eslint-disable-line no-proto
128+
ob.__proto__ = { x: '1' };
94129

95130
expect(formToRackParams(form)).toEqual({ foo: [ob] });
96131
});
@@ -103,7 +138,7 @@ describe('__proto__[x]=1', () => {
103138
const form = document.querySelector('form');
104139

105140
const ob = Object.create(null);
106-
ob.__proto__ = { x: '1' }; // eslint-disable-line no-proto
141+
ob.__proto__ = { x: '1' };
107142

108143
expect(formToRackParams(form)).toEqual(ob);
109144
});

jest.config.mjs

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export default {
2+
transform: {},
3+
testEnvironment: 'jsdom',
4+
};

0 commit comments

Comments
 (0)