Skip to content

Commit

Permalink
fixup! feat: Stringify config data if it's an object
Browse files Browse the repository at this point in the history
  • Loading branch information
pitahorn committed May 3, 2024
1 parent 733dedc commit 16d2dc4
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions src/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,25 @@ import { EVENT_MAP } from './constants';

const defaultHanlder = () => null;

export const buildQueryString = (
config: Record<string, string | Record<string, string>>,
): string => Object.keys(config).map((key) => {
if (typeof config[key] === 'string') {
return `${key}=${config[key]}`
type QueryValue = string | number | boolean | QueryObject;

Check failure on line 7 in src/lib/utils.ts

View workflow job for this annotation

GitHub Actions / eslint

'QueryObject' was used before it was defined
interface QueryObject { [key: string]: QueryValue; }

export const buildQueryString = (config: QueryObject, configKey?: string): string => {
const pairs: string[] = [];

for (const [key, value] of Object.entries(config)) {

Check failure on line 13 in src/lib/utils.ts

View workflow job for this annotation

GitHub Actions / eslint

iterators/generators require regenerator-runtime, which is too heavyweight for this guide to allow them. Separately, loops should be avoided in favor of array iterations
const nestedKey = configKey ? `${configKey}[${encodeURIComponent(key)}]` : encodeURIComponent(key);
const valueIsObject = typeof value === 'object' && value !== null && !Array.isArray(value);

if (valueIsObject) {
pairs.push(buildQueryString(value as QueryObject, nestedKey));
} else {
pairs.push(`${nestedKey}=${encodeURIComponent(String(value))}`);
}
}
return `${key}=${JSON.stringify(config[key])}`
}).join('&');

return pairs.join('&');
}

Check failure on line 25 in src/lib/utils.ts

View workflow job for this annotation

GitHub Actions / eslint

Missing semicolon

export const buildMessageHandler = (handlers: FintocWidgetEventHandlers) => (
(event: WebViewMessageEvent) => {
Expand Down

0 comments on commit 16d2dc4

Please sign in to comment.