Skip to content

Commit 02706ff

Browse files
[Enterprise Search] Add parseQueryParams helper (#83750) (#83842)
* [Enterprise Search] Add parseQueryParams helper This PR migrates part of the ent-search queryParams util, `parseQueryParams` for use in Workplace Search. `setQueryParams` was no a part of this PR because it is only used one time in App Search and a better alternative might be available for that use-case * Remove mock * Actually test functionality of query-string * Add test for array * Better test name
1 parent 064fd8e commit 02706ff

File tree

3 files changed

+31
-0
lines changed

3 files changed

+31
-0
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License;
4+
* you may not use this file except in compliance with the Elastic License.
5+
*/
6+
7+
export { parseQueryParams } from './query_params';
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License;
4+
* you may not use this file except in compliance with the Elastic License.
5+
*/
6+
7+
import { parseQueryParams } from './';
8+
9+
describe('parseQueryParams', () => {
10+
it('parse query strings', () => {
11+
expect(parseQueryParams('?foo=bar')).toEqual({ foo: 'bar' });
12+
expect(parseQueryParams('?foo[]=bar&foo[]=baz')).toEqual({ foo: ['bar', 'baz'] });
13+
});
14+
});
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License;
4+
* you may not use this file except in compliance with the Elastic License.
5+
*/
6+
7+
import queryString from 'query-string';
8+
9+
export const parseQueryParams = (search: string) =>
10+
queryString.parse(search, { arrayFormat: 'bracket' });

0 commit comments

Comments
 (0)