RocketChat/Rocket.Chat

View on GitHub
apps/meteor/app/settings/server/functions/convertValue.ts

Summary

Maintainability
A
30 mins
Test Coverage
import type { ISetting, SettingValue } from '@rocket.chat/core-typings';

export const convertValue = (value: 'true' | 'false' | string, type: ISetting['type']): SettingValue => {
    if (value.toLowerCase() === 'true') {
        return true;
    }
    if (value.toLowerCase() === 'false') {
        return false;
    }
    if (type === 'int') {
        return parseInt(value);
    }
    if (type === 'multiSelect') {
        return JSON.parse(value);
    }
    return value;
};