ノーマライズ処理を共通化

This commit is contained in:
kakkokari-gtyih
2024-06-26 11:38:18 +09:00
parent be15242bf6
commit 57906fd563
2 changed files with 17 additions and 6 deletions

View File

@@ -35,11 +35,22 @@ export type EmbedParams = {
header?: boolean;
};
// パラメータのデフォルトの値
export const defaultEmbedParams: EmbedParams = {
maxHeight: undefined,
colorMode: undefined,
rounded: true,
border: true,
autoload: false,
header: true,
};
export function normalizeEmbedParams(params: EmbedParams): Record<string, string> {
// paramsのvalueをすべてstringに変換。undefinedやnullはプロパティごと消す
const normalizedParams: Record<string, string> = {};
for (const key in params) {
if (params[key] == null) {
// デフォルトの値と同じならparamsに含めない
if (params[key] == null || params[key] === defaultEmbedParams[key]) {
continue;
}
switch (typeof params[key]) {