strict-qs 6.1.3 → 7.0.0

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