-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(v2.1.1): add typescript compilation to husky; add createQueryStr…
…ingParamsObjectFromString()
- Loading branch information
1 parent
d10d550
commit e787a44
Showing
7 changed files
with
236 additions
and
178 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
#!/bin/sh | ||
. "$(dirname "$0")/_/husky.sh" | ||
|
||
npx tsc | ||
npm run build | ||
npm run test | ||
npm run docs:madge | ||
|
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
src/application/createQueryStringParamsObjectFromString.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/** | ||
* @description Create a conventional object of query string parameters | ||
* from an HTTP API's `event` object that only has query string parameters | ||
* in the shape of a "raw" string. | ||
*/ | ||
export function createQueryStringParamsObjectFromString(event: Record<string, any>) { | ||
const queryStringParameters: Record<string, any> = {}; | ||
|
||
const parts = event?.rawQueryString?.split('&'); | ||
if (parts && parts.length > 0) | ||
parts.forEach((part: string) => { | ||
const [key, value] = part.split('='); | ||
queryStringParameters[key] = value.replace('%2F', '/'); | ||
}); | ||
|
||
return queryStringParameters; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
tests/unit/application/createQueryStringParamsObjectFromString.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import test from 'ava'; | ||
|
||
import { createQueryStringParamsObjectFromString } from '../../../src/application/createQueryStringParamsObjectFromString'; | ||
|
||
/** | ||
* POSITIVE TESTS | ||
*/ | ||
|
||
test.serial('It should return a clean object from a query parameter string', (t) => { | ||
const expected = { repo: 'SOMEORG/SOMEREPO', from: '20230220', to: '20230225' }; | ||
|
||
const result = createQueryStringParamsObjectFromString({ | ||
rawQueryString: 'repo=SOMEORG/SOMEREPO&from=20230220&to=20230225' | ||
}); | ||
|
||
t.deepEqual(result, expected); | ||
}); | ||
|
||
test.serial('It should return an empty object for an unknown input', (t) => { | ||
const expected = {}; | ||
|
||
const result = createQueryStringParamsObjectFromString({}); | ||
|
||
t.deepEqual(result, expected); | ||
}); |