strict-qs 6.1.5 → 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.5",
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.17.10",
72
- "@babel/core": "^7.18.2",
73
- "@babel/eslint-parser": "^7.18.2",
74
- "@babel/plugin-proposal-object-rest-spread": "^7.18.0",
75
- "@babel/preset-env": "^7.18.2",
76
- "@babel/register": "^7.17.7",
70
+ "@types/jest": "^28.1.1",
71
+ "@typescript-eslint/eslint-plugin": "^5.27.0",
72
+ "@typescript-eslint/parser": "^5.27.0",
77
73
  "commitizen": "^4.2.4",
78
74
  "conventional-changelog-cli": "^2.2.2",
79
75
  "coveralls": "^3.1.1",
80
76
  "cz-conventional-changelog": "^3.3.0",
81
- "eslint": "^8.16.0",
77
+ "eslint": "^8.17.0",
78
+ "eslint-config-prettier": "^8.5.0",
82
79
  "eslint-plugin-prettier": "^4.0.0",
83
80
  "jest": "^28.1.0",
84
81
  "jsdoc-to-markdown": "^7.1.1",
85
82
  "metapak": "^4.0.3",
86
- "metapak-nfroidure": "11.2.1",
87
- "prettier": "^2.6.2"
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
90
  "debug": "^4.3.4",
91
- "yerror": "^6.0.2"
91
+ "yerror": "^6.1.1"
92
92
  },
93
93
  "engines": {
94
- "node": ">=12.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": [],
@@ -128,11 +126,14 @@
128
126
  ],
129
127
  "eslintConfig": {
130
128
  "extends": [
131
- "eslint:recommended"
129
+ "eslint:recommended",
130
+ "plugin:prettier/recommended",
131
+ "plugin:@typescript-eslint/eslint-recommended",
132
+ "plugin:@typescript-eslint/recommended"
132
133
  ],
133
134
  "parserOptions": {
134
135
  "ecmaVersion": 2018,
135
- "sourceType": "module",
136
+ "sourceType": "script",
136
137
  "modules": true
137
138
  },
138
139
  "env": {
@@ -146,7 +147,11 @@
146
147
  ],
147
148
  "rules": {
148
149
  "prettier/prettier": "error"
149
- }
150
+ },
151
+ "parser": "@typescript-eslint/parser",
152
+ "ignorePatterns": [
153
+ "*.d.ts"
154
+ ]
150
155
  },
151
156
  "prettier": {
152
157
  "semi": true,
@@ -164,6 +169,22 @@
164
169
  ],
165
170
  "roots": [
166
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"
167
188
  ]
168
189
  },
169
190
  "babel": {
@@ -175,7 +196,7 @@
175
196
  "@babel/env",
176
197
  {
177
198
  "targets": {
178
- "node": "12.19.0"
199
+ "node": "16.15.0"
179
200
  }
180
201
  }
181
202
  ]
@@ -211,5 +232,6 @@
211
232
  }
212
233
  },
213
234
  "sourceMaps": true
214
- }
235
+ },
236
+ "type": "module"
215
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',
@@ -1,12 +1,57 @@
1
1
  import initDebug from 'debug';
2
- import YError from 'yerror';
2
+ import { YError } from 'yerror';
3
3
 
4
4
  export const SEARCH_FLAG = '?';
5
5
  export const BASE_10 = 10;
6
6
 
7
7
  const debug = initDebug('strict-qs');
8
8
 
9
- export default qsStrict;
9
+ type QueryPart = {
10
+ name: string;
11
+ value: string;
12
+ };
13
+
14
+ export type QSOptions = {
15
+ allowEmptySearch?: boolean;
16
+ allowUnknownParams?: boolean;
17
+ allowDefault?: boolean;
18
+ allowUnorderedParams?: boolean;
19
+ };
20
+ export type QSValue = string | number | boolean;
21
+ export type QSParamValue = QSValue;
22
+ export type QSParamType = 'string' | 'number' | 'boolean';
23
+
24
+ export type QSUniqueParameter = {
25
+ name: string;
26
+ description?: string;
27
+ in: 'query';
28
+ pattern?: string;
29
+ required?: boolean;
30
+ enum?: QSParamValue[];
31
+ type: QSParamType;
32
+ default?: QSParamValue;
33
+ };
34
+
35
+ export type QSArrayParameter = {
36
+ name: string;
37
+ description?: string;
38
+ in: 'query';
39
+ type: 'array';
40
+ required?: boolean;
41
+ ordered?: boolean;
42
+ default?: QSParamValue[];
43
+ items: {
44
+ pattern?: string;
45
+ enum?: QSParamValue[];
46
+ type: QSParamType;
47
+ };
48
+ };
49
+
50
+ export type QSParameter = QSUniqueParameter | QSArrayParameter;
51
+
52
+ export type QSParameterValues = {
53
+ [name: string]: QSValue | QSValue[];
54
+ };
10
55
 
11
56
  /**
12
57
  * Parse a queryString according to the provided definitions
@@ -49,18 +94,23 @@ export default qsStrict;
49
94
  * // pages: [0, 1, 2], // eslint-disable-line
50
95
  * // }
51
96
  */
52
- function qsStrict(options, definitions, search) {
97
+
98
+ function qsStrict(
99
+ options: QSOptions,
100
+ definitions: QSParameter[],
101
+ search: string,
102
+ ): QSParameterValues {
53
103
  if (!search) {
54
104
  return {};
55
105
  }
56
106
  if (!search.startsWith(SEARCH_FLAG)) {
57
- throw new Error('E_MALFORMED_SEARCH', search);
107
+ throw new YError('E_MALFORMED_SEARCH', search);
58
108
  }
59
109
  if (search === SEARCH_FLAG) {
60
110
  if (options.allowEmptySearch) {
61
111
  return {};
62
112
  }
63
- throw new Error('E_EMPTY_SEARCH', search);
113
+ throw new YError('E_EMPTY_SEARCH', search);
64
114
  }
65
115
 
66
116
  const usefulDefinitions = definitions.filter(swaggerInQueryDefinitions);
@@ -75,7 +125,7 @@ function qsStrict(options, definitions, search) {
75
125
  (queryStringPart) => queryStringPart.name === definition.name,
76
126
  ),
77
127
  ],
78
- [],
128
+ [] as QueryPart[],
79
129
  )
80
130
  .concat(
81
131
  queryStringParts.filter(
@@ -120,7 +170,7 @@ function qsStrict(options, definitions, search) {
120
170
  }
121
171
 
122
172
  function pickupQueryParams(
123
- options,
173
+ options: QSOptions,
124
174
  { queryStringParams, queryStringPartsLeft },
125
175
  queryParamDefinition,
126
176
  ) {
@@ -165,11 +215,14 @@ function pickupQueryParams(
165
215
  }
166
216
 
167
217
  function pickQueryPartsByName(
168
- name,
169
- { lastIndex, keptQueryParts },
170
- queryPart,
171
- index,
172
- ) {
218
+ name: string,
219
+ {
220
+ lastIndex,
221
+ keptQueryParts,
222
+ }: { lastIndex: number; keptQueryParts: QueryPart[] },
223
+ queryPart: QueryPart,
224
+ index: number,
225
+ ): { lastIndex: number; keptQueryParts: QueryPart[] } {
173
226
  if (queryPart.name === name) {
174
227
  const isNotFoundAtNextIndex = index !== lastIndex + 1;
175
228
 
@@ -182,11 +235,11 @@ function pickQueryPartsByName(
182
235
  return { lastIndex, keptQueryParts };
183
236
  }
184
237
 
185
- function swaggerInQueryDefinitions(definition) {
238
+ function swaggerInQueryDefinitions(definition: QSParameter): boolean {
186
239
  return !definition.in || 'query' === definition.in;
187
240
  }
188
241
 
189
- function getQueryStringParts(queryString) {
242
+ function getQueryStringParts(queryString: string): QueryPart[] {
190
243
  return queryString
191
244
  .split('&')
192
245
  .map((queryStringChunk) => queryStringChunk.split('='))
@@ -197,17 +250,18 @@ function getQueryStringParts(queryString) {
197
250
  }
198
251
 
199
252
  function assignQueryStringPart(
200
- options,
201
- queryParamDefinition,
202
- queryStringParams,
203
- queryStringPart,
204
- ) {
253
+ options: QSOptions,
254
+ queryParamDefinition: QSParameter,
255
+ queryStringParams: QSParameterValues,
256
+ queryStringPart: QueryPart,
257
+ ): QSParameterValues {
205
258
  // Supporting only a subset of JSON schema core
206
259
  // http://json-schema.org/latest/json-schema-core.html#rfc.section.4.2
207
- const itemDefinition =
260
+ const itemDefinition = (
208
261
  'array' === queryParamDefinition.type
209
262
  ? queryParamDefinition.items
210
- : queryParamDefinition;
263
+ : queryParamDefinition
264
+ ) as QSUniqueParameter;
211
265
  const value =
212
266
  'string' === itemDefinition.type
213
267
  ? decodeQueryComponent(queryStringPart.value)
@@ -237,7 +291,7 @@ function assignQueryStringPart(
237
291
 
238
292
  if (
239
293
  itemDefinition.pattern &&
240
- !new RegExp(itemDefinition.pattern).test(value)
294
+ !new RegExp(itemDefinition.pattern).test(value.toString())
241
295
  ) {
242
296
  throw new YError(
243
297
  'E_PATTERN_DOES_NOT_MATCH',
@@ -247,32 +301,28 @@ function assignQueryStringPart(
247
301
  }
248
302
 
249
303
  if ('array' === queryParamDefinition.type) {
250
- queryStringParams[queryStringPart.name] =
251
- queryStringParams[queryStringPart.name] || [];
304
+ const values = (queryStringParams[queryStringPart.name] || []) as QSValue[];
252
305
  if (
253
306
  queryParamDefinition.ordered &&
254
- queryStringParams[queryStringPart.name].length &&
255
- queryStringParams[queryStringPart.name][
256
- queryStringParams[queryStringPart.name].length - 1
257
- ] > value
307
+ values.length &&
308
+ values[values.length - 1] > value
258
309
  ) {
259
310
  throw new YError(
260
311
  'E_UNORDERED_QUERY_PARAMS',
261
312
  value,
262
- queryStringParams[queryStringPart.name][
263
- queryStringParams[queryStringPart.name].length - 1
264
- ],
313
+ values[values.length - 1],
265
314
  );
266
315
  }
267
- queryStringParams[queryStringPart.name].push(value);
316
+ values.push(value);
317
+ queryStringParams[queryStringPart.name] = values;
268
318
  } else {
269
319
  queryStringParams[queryStringPart.name] = value;
270
320
  }
271
321
  return queryStringParams;
272
322
  }
273
323
 
274
- export function parseReentrantNumber(str) {
275
- const value = parseFloat(str, BASE_10);
324
+ export function parseReentrantNumber(str: string): number {
325
+ const value = parseFloat(str);
276
326
 
277
327
  if (value.toString(BASE_10) !== str) {
278
328
  throw new YError('E_NON_REENTRANT_NUMBER', str, value.toString(BASE_10));
@@ -281,7 +331,7 @@ export function parseReentrantNumber(str) {
281
331
  return value;
282
332
  }
283
333
 
284
- export function parseBoolean(str) {
334
+ export function parseBoolean(str: string): boolean {
285
335
  if ('true' === str) {
286
336
  return true;
287
337
  } else if ('false' === str) {
@@ -290,6 +340,8 @@ export function parseBoolean(str) {
290
340
  throw new YError('E_BAD_BOOLEAN', str);
291
341
  }
292
342
 
293
- export function decodeQueryComponent(value) {
343
+ export function decodeQueryComponent(value: string): string {
294
344
  return decodeURIComponent(value.replace(/\+/g, '%20'));
295
345
  }
346
+
347
+ export { qsStrict };