UNPKG

@muban/storybook

Version:
30 lines (29 loc) 1.26 kB
const sanitizeByType = { unused: String, // boolean: (value: unknown): boolean => value === true || value === 'true', // number: Number, // select: Number, // range: Number, // date: Number, // string: String, }; // eslint-disable-next-line @typescript-eslint/no-explicit-any,@typescript-eslint/explicit-module-boundary-types export function sanitizeParams(parameters, argumentTypes) { // there is a bug in storybook where values are "stored in the url", // so if the page gets reloaded, boolean values are passed as strings // here we look at the argType control and set them back return Object.fromEntries(Object.entries(parameters).map(([key, value]) => { var _a, _b; const dataType = // eslint-disable-next-line @typescript-eslint/no-non-null-assertion (_b = (_a = argumentTypes[key]['control']) === null || _a === void 0 ? void 0 : _a.type) !== null && _b !== void 0 ? _b : // eslint-disable-next-line @typescript-eslint/no-non-null-assertion argumentTypes[key]['control']; return [ key, Object.hasOwn(sanitizeByType, dataType) ? sanitizeByType[dataType](value) : value, ]; })); }