import { SettingName, SettingValue } from '../models/setting'; import ParsingLib from './parsing'; export default class SettingLib { /** * Convert the provided data to a map, as expected by BulkUpdate */ static objectToBulkMap = (data: Record, options?: { stripNaN: boolean }): Map => { const res = new Map(); for (const key in data) { if (!options?.stripNaN || !Number.isNaN(data[key])) { res.set(key as SettingName, `${data[key]}`); } } return res; }; /** * Convert the provided map to a simple javascript object, usable by react-hook-form */ static bulkMapToObject = (data: Map): Record => { const res = {} as Record; data.forEach((value, key) => { res[key] = ParsingLib.simpleParse(value); }); return res; }; }