import _ from 'lodash' ; returns { object } param userInput export function fromUser ( userInput ) { const matchAll = '' ; if ( _ . isEmpty ( userInput ) ) { return '' ; } if ( _ . isObject ( userInput ) ) { return userInput ; } userInput = userInput || '' ; if ( typeof userInput === 'string' ) { const trimmedUserInput = userInput . trim ( ) ; if ( trimmedUserInput . length === 0 ) { return matchAll ; } if ( trimmedUserInput [ 0 ] === '{' ) { try { return JSON . parse ( trimmedUserInput ) ; } catch ( e ) { return userInput ; } } else { return userInput ; } } }