import { defaultSettings } from '@config/defaultSettings' ; import { Settings } from '@typings/settings' ; import config from '@config/config' ; import { stringifyJson } from './stringifyJson' ; return const getSettings = ( ) : Settings => { let storedSettings = figma . root . getPluginData ( config . key . settings ) ; if ( storedSettings === '' ) { return defaultSettings ; } storedSettings = JSON . parse ( storedSettings ) ; return < Settings > Object . fromEntries ( Object . entries ( defaultSettings ) . map ( ( [ key , value ] ) => { if ( value !== undefined && typeof storedSettings [ key ] !== typeof value ) { return [ key , defaultSettings [ key ] ] ; } return [ key , storedSettings [ key ] ] ; } ) ) ; } ; name description param { UserSettings } settings const setSettings = ( settings ) => { settings = { ... defaultSettings , ... settings } ; figma . root . setPluginData ( config . key . settings , stringifyJson ( settings ) ) ; } ; name description const resetSettings = ( ) => figma . root . setPluginData ( config . key . settings , stringifyJson ( defaultSettings ) ) ; export { getSettings , setSettings , resetSettings } ;