strict-qs 6.1.4 → 7.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,24 +1,26 @@
1
1
  {
2
2
  "name": "strict-qs",
3
- "version": "6.1.4",
3
+ "version": "7.0.1",
4
4
  "description": "A stricter Query String parser",
5
- "main": "dist/index",
6
- "module": "dist/index.mjs",
7
- "types": "src/index.d.js",
5
+ "type": "module",
6
+ "main": "dist/index.js",
7
+ "types": "dist/index.d.ts",
8
8
  "metapak": {
9
9
  "configs": [
10
10
  "main",
11
- "jsdocs",
12
11
  "readme",
13
- "travis",
12
+ "ghactions",
13
+ "tsesm",
14
14
  "eslint",
15
15
  "codeclimate",
16
- "jest",
17
- "babel"
16
+ "coveralls",
17
+ "jsdocs",
18
+ "jest"
18
19
  ],
19
20
  "data": {
20
- "files": "'src/**/*.js'",
21
- "testsFiles": "'src/**/*.test.js'",
21
+ "files": "src/*.ts",
22
+ "distFiles": "dist/*.js",
23
+ "testsFiles": "src/*.test.ts",
22
24
  "ignore": [
23
25
  "dist"
24
26
  ],
@@ -29,21 +31,19 @@
29
31
  }
30
32
  },
31
33
  "scripts": {
34
+ "build": "rimraf -f 'dist' && tsc --outDir dist",
32
35
  "changelog": "conventional-changelog -p angular -i CHANGELOG.md -s && git add CHANGELOG.md",
33
36
  "cli": "env NODE_ENV=${NODE_ENV:-cli}",
34
- "compile": "rimraf -f 'dist' && npm run compile:cjs && npm run compile:mjs",
35
- "compile:cjs": "babel --env-name=cjs --out-dir=dist --source-maps=true src",
36
- "compile:mjs": "babel --env-name=mjs --out-file-extension=.mjs --out-dir=dist --source-maps=true src",
37
37
  "cover": "npm run jest -- --coverage",
38
38
  "coveralls": "npm run cover && cat ./coverage/lcov.info | coveralls && rm -rf ./coverage",
39
39
  "cz": "env NODE_ENV=${NODE_ENV:-cli} git cz",
40
- "doc": "echo \"# API\" > API.md; jsdoc2md 'src/**/*.js' >> API.md && git add API.md",
41
- "jest": "NODE_ENV=test jest",
42
- "lint": "eslint 'src/**/*.js'",
40
+ "doc": "echo \"# API\" > API.md; jsdoc2md dist/*.js >> API.md && git add API.md",
41
+ "jest": "NODE_OPTIONS=--experimental-vm-modules NODE_ENV=test jest",
42
+ "lint": "eslint src/*.ts",
43
43
  "metapak": "metapak",
44
- "precz": "npm t && npm run lint && npm run compile && npm run doc && npm run metapak -- -s",
45
- "prettier": "prettier --write 'src/**/*.js'",
46
- "preversion": "npm t && npm run lint && npm run compile && npm run doc && npm run metapak -- -s",
44
+ "precz": "npm t && npm run lint && npm run build && npm run doc && npm run metapak -- -s",
45
+ "prettier": "prettier --write src/*.ts",
46
+ "preversion": "npm t && npm run lint && npm run build && npm run doc && npm run metapak -- -s",
47
47
  "test": "npm run jest",
48
48
  "version": "npm run changelog"
49
49
  },
@@ -68,30 +68,31 @@
68
68
  },
69
69
  "homepage": "https://github.com/nfroidure/strict-qs#readme",
70
70
  "devDependencies": {
71
- "@babel/cli": "^7.13.14",
72
- "@babel/core": "^7.13.15",
73
- "@babel/eslint-parser": "^7.13.14",
74
- "@babel/plugin-proposal-object-rest-spread": "^7.13.8",
75
- "@babel/preset-env": "^7.13.15",
76
- "@babel/register": "^7.13.14",
77
- "commitizen": "^4.2.3",
78
- "conventional-changelog-cli": "^2.1.1",
79
- "coveralls": "^3.1.0",
71
+ "@typescript-eslint/eslint-plugin": "^5.36.0",
72
+ "@typescript-eslint/parser": "^5.36.0",
73
+ "commitizen": "^4.2.5",
74
+ "conventional-changelog-cli": "^2.2.2",
75
+ "coveralls": "^3.1.1",
80
76
  "cz-conventional-changelog": "^3.3.0",
81
- "eslint": "^7.23.0",
82
- "eslint-plugin-prettier": "^3.3.1",
83
- "jest": "^26.6.3",
84
- "jsdoc-to-markdown": "^7.0.1",
85
- "metapak": "^4.0.1",
86
- "metapak-nfroidure": "11.0.7",
87
- "prettier": "^2.2.1"
77
+ "esbuild": "^0.15.6",
78
+ "esbuild-jest": "^0.5.0",
79
+ "eslint": "^8.23.0",
80
+ "eslint-config-prettier": "^8.5.0",
81
+ "eslint-plugin-prettier": "^4.2.1",
82
+ "jest": "^29.0.1",
83
+ "jsdoc-to-markdown": "^7.1.1",
84
+ "metapak": "^4.0.4",
85
+ "metapak-nfroidure": "12.3.0",
86
+ "prettier": "^2.7.1",
87
+ "rimraf": "^3.0.2",
88
+ "typescript": "^4.8.2"
88
89
  },
89
90
  "dependencies": {
90
- "debug": "^4.3.1",
91
- "yerror": "^6.0.0"
91
+ "debug": "^4.3.4",
92
+ "yerror": "^6.1.1"
92
93
  },
93
94
  "engines": {
94
- "node": ">=12.19.0"
95
+ "node": ">=16.15.0"
95
96
  },
96
97
  "config": {
97
98
  "commitizen": {
@@ -103,19 +104,17 @@
103
104
  "commitizen",
104
105
  "cz-conventional-changelog",
105
106
  "conventional-changelog-cli",
106
- "jsdoc-to-markdown",
107
+ "typescript",
108
+ "rimraf",
107
109
  "eslint",
108
110
  "eslint-config-prettier",
111
+ "eslint-plugin-prettier",
109
112
  "prettier",
113
+ "@typescript-eslint/eslint-plugin",
114
+ "@typescript-eslint/parser",
115
+ "jsdoc-to-markdown",
110
116
  "jest",
111
- "coveralls",
112
- "@babel/cli",
113
- "@babel/core",
114
- "@babel/register",
115
- "@babel/preset-env",
116
- "@babel/plugin-proposal-object-rest-spread",
117
- "babel-eslint",
118
- "babel-core"
117
+ "coveralls"
119
118
  ]
120
119
  },
121
120
  "contributors": [],
@@ -128,11 +127,14 @@
128
127
  ],
129
128
  "eslintConfig": {
130
129
  "extends": [
131
- "eslint:recommended"
130
+ "eslint:recommended",
131
+ "plugin:prettier/recommended",
132
+ "plugin:@typescript-eslint/eslint-recommended",
133
+ "plugin:@typescript-eslint/recommended"
132
134
  ],
133
135
  "parserOptions": {
134
136
  "ecmaVersion": 2018,
135
- "sourceType": "module",
137
+ "sourceType": "script",
136
138
  "modules": true
137
139
  },
138
140
  "env": {
@@ -146,7 +148,11 @@
146
148
  ],
147
149
  "rules": {
148
150
  "prettier/prettier": "error"
149
- }
151
+ },
152
+ "parser": "@typescript-eslint/parser",
153
+ "ignorePatterns": [
154
+ "*.d.ts"
155
+ ]
150
156
  },
151
157
  "prettier": {
152
158
  "semi": true,
@@ -164,52 +170,22 @@
164
170
  ],
165
171
  "roots": [
166
172
  "<rootDir>/src"
167
- ]
168
- },
169
- "babel": {
170
- "plugins": [
171
- "@babel/plugin-proposal-object-rest-spread"
172
173
  ],
173
- "presets": [
174
- [
175
- "@babel/env",
174
+ "transform": {
175
+ "^.+\\.tsx?$": [
176
+ "esbuild-jest",
176
177
  {
177
- "targets": {
178
- "node": "12.19.0"
179
- }
178
+ "sourcemap": true,
179
+ "format": "esm"
180
180
  }
181
181
  ]
182
- ],
183
- "env": {
184
- "cjs": {
185
- "presets": [
186
- [
187
- "@babel/env",
188
- {
189
- "targets": {
190
- "node": "10"
191
- },
192
- "modules": "commonjs"
193
- }
194
- ]
195
- ],
196
- "comments": true
197
- },
198
- "mjs": {
199
- "presets": [
200
- [
201
- "@babel/env",
202
- {
203
- "targets": {
204
- "node": "12"
205
- },
206
- "modules": false
207
- }
208
- ]
209
- ],
210
- "comments": false
211
- }
212
182
  },
213
- "sourceMaps": true
183
+ "testEnvironment": "node",
184
+ "moduleNameMapper": {
185
+ "(.+)\\.js": "$1"
186
+ },
187
+ "extensionsToTreatAsEsm": [
188
+ ".ts"
189
+ ]
214
190
  }
215
191
  }
@@ -1,12 +1,14 @@
1
+ import { describe, test } from '@jest/globals';
1
2
  import assert from 'assert';
2
- import qs from '.';
3
+ import { qsStrict } from './index.js';
4
+ import type { QSParameter } from './index.js';
3
5
 
4
6
  describe('strict-qs', () => {
5
7
  describe('with no search', () => {
6
8
  const qsDefinition = [];
7
9
 
8
10
  test('should work', () => {
9
- assert.deepEqual(qs(qsDefinition, ''), {});
11
+ assert.deepEqual(qsStrict({}, qsDefinition, ''), {});
10
12
  });
11
13
  });
12
14
 
@@ -15,17 +17,20 @@ describe('strict-qs', () => {
15
17
 
16
18
  test('should fail', () => {
17
19
  assert.throws(() => {
18
- qs({}, qsDefinition, '?');
20
+ qsStrict({}, qsDefinition, '?');
19
21
  }, /E_EMPTY_SEARCH/);
20
22
  });
21
23
 
22
24
  test('should work when allowed', () => {
23
- assert.deepEqual(qs({ allowEmptySearch: true }, qsDefinition, '?'), {});
25
+ assert.deepEqual(
26
+ qsStrict({ allowEmptySearch: true }, qsDefinition, '?'),
27
+ {},
28
+ );
24
29
  });
25
30
 
26
31
  test('should fail', () => {
27
32
  assert.throws(() => {
28
- qs({}, qsDefinition, 'lol');
33
+ qsStrict({}, qsDefinition, 'lol');
29
34
  }, /E_MALFORMED_SEARCH/);
30
35
  });
31
36
  });
@@ -38,18 +43,18 @@ describe('strict-qs', () => {
38
43
  type: 'object',
39
44
  required: true,
40
45
  description: 'The user',
41
- },
46
+ } as unknown as QSParameter,
42
47
  ];
43
48
 
44
49
  test('should fail', () => {
45
50
  assert.throws(() => {
46
- qs({}, qsDefinition, '?user=lol');
51
+ qsStrict({}, qsDefinition, '?user=lol');
47
52
  }, /E_UNSUPPORTED_TYPE/);
48
53
  });
49
54
  });
50
55
 
51
56
  describe('with ordered collections', () => {
52
- const qsDefinition = [
57
+ const qsDefinition: QSParameter[] = [
53
58
  {
54
59
  name: 'pages',
55
60
  in: 'query',
@@ -63,20 +68,20 @@ describe('strict-qs', () => {
63
68
  ];
64
69
 
65
70
  test('should work when params are ordered', () => {
66
- assert.deepEqual(qs({}, qsDefinition, '?pages=0&pages=1&pages=2'), {
71
+ assert.deepEqual(qsStrict({}, qsDefinition, '?pages=0&pages=1&pages=2'), {
67
72
  pages: [0, 1, 2], // eslint-disable-line
68
73
  });
69
74
  });
70
75
 
71
76
  test('should fail when params are not ordered', () => {
72
77
  assert.throws(() => {
73
- qs({}, qsDefinition, '?pages=0&pages=2&pages=1');
78
+ qsStrict({}, qsDefinition, '?pages=0&pages=2&pages=1');
74
79
  }, /E_UNORDERED_QUERY_PARAMS/);
75
80
  });
76
81
  });
77
82
 
78
83
  describe('with encoded components', () => {
79
- const qsDefinition = [
84
+ const qsDefinition: QSParameter[] = [
80
85
  {
81
86
  name: 'redirectURL',
82
87
  in: 'query',
@@ -86,7 +91,7 @@ describe('strict-qs', () => {
86
91
 
87
92
  test('should work', () => {
88
93
  assert.deepEqual(
89
- qs(
94
+ qsStrict(
90
95
  {},
91
96
  qsDefinition,
92
97
  '?redirectURL=' + encodeURIComponent('http://localhost/plop'),
@@ -99,7 +104,7 @@ describe('strict-qs', () => {
99
104
  });
100
105
 
101
106
  describe('with axios components', () => {
102
- const qsDefinition = [
107
+ const qsDefinition: QSParameter[] = [
103
108
  {
104
109
  name: 'query',
105
110
  in: 'query',
@@ -108,14 +113,14 @@ describe('strict-qs', () => {
108
113
  ];
109
114
 
110
115
  test('should work', () => {
111
- assert.deepEqual(qs({}, qsDefinition, '?query=a+b+c'), {
116
+ assert.deepEqual(qsStrict({}, qsDefinition, '?query=a+b+c'), {
112
117
  query: 'a b c',
113
118
  });
114
119
  });
115
120
  });
116
121
 
117
122
  describe('with lots of different definitions', () => {
118
- const qsDefinition = [
123
+ const qsDefinition: QSParameter[] = [
119
124
  {
120
125
  name: 'lang',
121
126
  in: 'query',
@@ -162,7 +167,7 @@ describe('strict-qs', () => {
162
167
 
163
168
  test('should work with good params', () => {
164
169
  assert.deepEqual(
165
- qs(
170
+ qsStrict(
166
171
  {},
167
172
  qsDefinition,
168
173
  '?lang=fr&types=open&types=closed&types=pending&code=3&full=true',
@@ -175,7 +180,7 @@ describe('strict-qs', () => {
175
180
  },
176
181
  );
177
182
  assert.throws(
178
- qs.bind(
183
+ qsStrict.bind(
179
184
  null,
180
185
  {},
181
186
  qsDefinition,
@@ -184,7 +189,7 @@ describe('strict-qs', () => {
184
189
  /E_NOT_IN_ENUM/,
185
190
  );
186
191
  assert.throws(
187
- qs.bind(
192
+ qsStrict.bind(
188
193
  null,
189
194
  {},
190
195
  qsDefinition,
@@ -196,7 +201,7 @@ describe('strict-qs', () => {
196
201
 
197
202
  test('should work with all params', () => {
198
203
  assert.deepEqual(
199
- qs(
204
+ qsStrict(
200
205
  {},
201
206
  qsDefinition,
202
207
  '?lang=fr&types=open&types=closed&types=pending&code=3&full=false&nums=4',
@@ -213,7 +218,7 @@ describe('strict-qs', () => {
213
218
 
214
219
  test('should fail when required params are not in order', () => {
215
220
  assert.throws(() => {
216
- qs(
221
+ qsStrict(
217
222
  {},
218
223
  qsDefinition,
219
224
  '?lang=fr&types=open&lang=hop&types=closed&types=pending&code=3&full=true',
@@ -223,7 +228,7 @@ describe('strict-qs', () => {
223
228
 
224
229
  test('should work when required params are not in order with option allowUnorderedParams', () => {
225
230
  assert.deepEqual(
226
- qs(
231
+ qsStrict(
227
232
  { allowUnorderedParams: true },
228
233
  qsDefinition,
229
234
  '?lang=fr&types=open&lang=fr&types=closed&types=pending&code=3&full=true',
@@ -239,7 +244,7 @@ describe('strict-qs', () => {
239
244
 
240
245
  test('should work when required params are not in order with option allowUnorderedParams and allowUnknownParams', () => {
241
246
  assert.deepEqual(
242
- qs(
247
+ qsStrict(
243
248
  { allowUnorderedParams: true, allowUnknownParams: true },
244
249
  qsDefinition,
245
250
  '?lang=fr&types=open&pippip=yeah&lang=fr&types=closed&types=pending&code=3&full=true',
@@ -255,7 +260,7 @@ describe('strict-qs', () => {
255
260
 
256
261
  test('should fail when required params are not provided', () => {
257
262
  assert.throws(() => {
258
- qs(
263
+ qsStrict(
259
264
  {},
260
265
  qsDefinition,
261
266
  '?types=open&types=closed&types=pending&code=3&full=true',
@@ -265,7 +270,7 @@ describe('strict-qs', () => {
265
270
 
266
271
  test('should fail when a bad boolean is provided', () => {
267
272
  assert.throws(() => {
268
- qs(
273
+ qsStrict(
269
274
  {},
270
275
  qsDefinition,
271
276
  '?lang=fr&types=open&types=closed&types=pending&code=3&full=1',
@@ -275,7 +280,7 @@ describe('strict-qs', () => {
275
280
 
276
281
  test('should fail when a bad array item is given', () => {
277
282
  assert.throws(() => {
278
- qs(
283
+ qsStrict(
279
284
  {},
280
285
  qsDefinition,
281
286
  '?lang=fr&types=open&types=closed&types=pending&code=3&full=true&nums=1&nums=0.0',
@@ -285,7 +290,7 @@ describe('strict-qs', () => {
285
290
 
286
291
  test('should work whith an unexisting param and the allowUnknownParams option', () => {
287
292
  assert.deepEqual(
288
- qs(
293
+ qsStrict(
289
294
  { allowUnknownParams: true },
290
295
  qsDefinition,
291
296
  '?lol=9&lang=fr&types=open&types=closed&types=pending&code=3&full=true',
@@ -301,7 +306,7 @@ describe('strict-qs', () => {
301
306
 
302
307
  test('should fail when an unexisting param is set at the begin', () => {
303
308
  assert.throws(() => {
304
- qs(
309
+ qsStrict(
305
310
  {},
306
311
  qsDefinition,
307
312
  '?lol=9&lang=fr&types=open&types=closed&types=pending&code=3&full=true',
@@ -311,7 +316,7 @@ describe('strict-qs', () => {
311
316
 
312
317
  test('should fail when an unexisting param is set in the middle', () => {
313
318
  assert.throws(() => {
314
- qs(
319
+ qsStrict(
315
320
  {},
316
321
  qsDefinition,
317
322
  '?lang=fr&types=open&types=closed&types=pendinglol=9&&code=3&full=true',
@@ -321,7 +326,7 @@ describe('strict-qs', () => {
321
326
 
322
327
  test('should fail when an unexisting param is set at the end', () => {
323
328
  assert.throws(() => {
324
- qs(
329
+ qsStrict(
325
330
  {},
326
331
  qsDefinition,
327
332
  '?lang=fr&types=open&types=closed&types=pending&code=3&full=true&lol=9',
@@ -331,7 +336,7 @@ describe('strict-qs', () => {
331
336
 
332
337
  test('should fail when setting a query param to the default value', () => {
333
338
  assert.throws(() => {
334
- qs(
339
+ qsStrict(
335
340
  {},
336
341
  qsDefinition,
337
342
  '?lang=en&types=open&types=closed&types=pending&code=3&full=true',
@@ -340,7 +345,7 @@ describe('strict-qs', () => {
340
345
  });
341
346
  test('should work when setting a query param to the default value and allowDefault option', () => {
342
347
  assert.deepEqual(
343
- qs(
348
+ qsStrict(
344
349
  { allowDefault: true },
345
350
  qsDefinition,
346
351
  '?lang=en&types=open&types=closed&types=pending&code=3&full=true',