MCPcopy Index your code
hub / github.com/massCodeIO/massCode / sanitizePreferences

Function sanitizePreferences

src/main/store/module/preferences.ts:241–324  ·  view source on GitHub ↗
(value: unknown)

Source from the content-addressed store, hash-verified

239}
240
241function sanitizePreferences(value: unknown): PreferencesStore {
242 const source = asRecord(value)
243 const appearanceSource = asRecord(source.appearance)
244 const localizationSource = asRecord(source.localization)
245 const apiSource = asRecord(source.api)
246 const storageSource = asRecord(source.storage)
247 const editorSource = asRecord(source.editor)
248 const codeEditorSource
249 = Object.keys(asRecord(editorSource.code)).length > 0
250 ? asRecord(editorSource.code)
251 : editorSource
252 const notesEditorSource
253 = Object.keys(asRecord(editorSource.notes)).length > 0
254 ? asRecord(editorSource.notes)
255 : asRecord(source.notesEditor)
256 const markdownSource
257 = Object.keys(asRecord(editorSource.markdown)).length > 0
258 ? asRecord(editorSource.markdown)
259 : asRecord(source.markdown)
260 const mathSource = asRecord(source.math)
261 const httpSource = asRecord(source.http)
262
263 return {
264 appearance: {
265 theme: readString(
266 appearanceSource,
267 'theme',
268 readString(source, 'theme', PREFERENCES_DEFAULTS.appearance.theme),
269 ),
270 },
271 updates: {
272 autoUpdate:
273 typeof asRecord(source.updates).autoUpdate === 'boolean'
274 ? Boolean(asRecord(source.updates).autoUpdate)
275 : PREFERENCES_DEFAULTS.updates.autoUpdate,
276 },
277 localization: {
278 locale: readString(
279 localizationSource,
280 'locale',
281 readString(
282 source,
283 'language',
284 PREFERENCES_DEFAULTS.localization.locale,
285 ),
286 ),
287 },
288 api: {
289 port: readNumber(
290 apiSource,
291 'port',
292 readNumber(source, 'apiPort', PREFERENCES_DEFAULTS.api.port),
293 ),
294 integrations: sanitizeApiIntegrationsSettings(apiSource.integrations),
295 },
296 storage: {
297 rootPath: readString(
298 storageSource,

Callers 1

preferences.tsFile · 0.85

Calls 10

asRecordFunction · 0.90
readStringFunction · 0.90
readNumberFunction · 0.90
readNullableStringFunction · 0.90
sanitizeMarkdownSettingsFunction · 0.85
sanitizeMathSettingsFunction · 0.85
sanitizeHttpSettingsFunction · 0.85

Tested by

no test coverage detected