import { camelCase , snakeCase } from 'lodash' ; import { flatten } from '../../common/lib' ; import { cleanSettings } from './clean_settings' ; interface RepositorySettings { [ key ] : any ; } const booleanizeValue = ( value ) => { if ( value === 'true' ) { return true ; } else if ( value === 'false' ) { return false ; } return value ; } ; export const deserializeRepositorySettings = ( settings ) : RepositorySettings => { const flattenedSettings = flatten ( settings ) ; const deserializedSettings = { } ; Object . entries ( flattenedSettings ) . forEach ( ( [ key , value ] ) => { if ( key . includes ( '.' ) ) { deserializedSettings [ key ] = booleanizeValue ( value ) ; } else { deserializedSettings [ camelCase ( key ) ] = booleanizeValue ( value ) ; } } ) ; return deserializedSettings ; } ; export const serializeRepositorySettings = ( settings ) : RepositorySettings => { const serializedSettings = { } ; Object . entries ( settings ) . forEach ( ( [ key , value ] ) => { if ( key . includes ( '.' ) ) { serializedSettings [ key ] = value ; } else { serializedSettings [ snakeCase ( key ) ] = value ; } } ) ; return cleanSettings ( serializedSettings ) ; } ;