import { AsyncStorage } from '../jobPersistence' ; import { AsyncStorage as AsyncStorageReactNative } from 'react-native' ; export default ( asyncStorage ) : AsyncStorage => { const serializeItem = ( item ) => { if ( typeof item === 'object' ) { return JSON . stringify ( item ) ; } else { return item + '' ; } } ; async function getItem ( key ) { const serializedData = < string > await asyncStorage . getItem ( key ) ; try { return JSON . parse ( serializedData ) ; } catch ( e ) { return parseInt ( serializedData ) || serializedData ; } } async function setItem ( key , value ) { asyncStorage . setItem ( key , serializeItem ( value ) ) ; } async function multiSet ( keyValuePairs ) { if ( keyValuePairs . length === 0 ) return ; const pairsAsArray = keyValuePairs . map ( ( { key , value } ) => [ key , serializeItem ( value ) ] ) ; await asyncStorage . multiSet ( pairsAsArray ) ; } async function multiRemove ( keys ) { if ( keys . length === 0 ) return ; await asyncStorage . multiRemove ( keys ) ; } return { removeItem : asyncStorage . removeItem , multiRemove , getItem , setItem , multiSet } ; } ;