import { StyleSheet , StyleProp , ViewStyle , TextStyle } from 'react-native' ; const WRAPPER_TYPE_STYLE_REGEX = /alignSelf|aspectRatio|border.*|bottom|direction|display|end|left|margin.*|position|right|start|top|zIndex|opacity|elevation/ ; const SYNC_TYPE_STYLE_REGEX = /flex|flexBasis|flexGrow|flexShrink/ ; const TEXT_STYLE_REGEX = /color|font.*|text.*|letterSpacing|lineHeight|includeFontPadding|writingDirection/ ; export const extracteTextStyle = ( style ? ) : StyleProp < TextStyle > => { const flattenStyle = StyleSheet . flatten ( style ) ; const textStyle = { } ; if ( flattenStyle ) { Object . keys ( flattenStyle ) . forEach ( ( key ) => { if ( TEXT_STYLE_REGEX . test ( key ) ) { textStyle [ key ] = flattenStyle [ key ] ; } } ) ; } return textStyle ; } ; export const omit = ( obj = { } , fields = [ ] ) : { [ key ] : any ; } => { const shallowCopy = { ... obj } ; fields . forEach ( ( key ) => { delete shallowCopy [ key ] ; } ) ; return shallowCopy ; } ; export const dismemberStyle = ( style ? ) : { wrapperStyle : ViewStyle ; innerStyle : ViewStyle ; } => { const flattenStyle = StyleSheet . flatten ( style ) ; const wrapperStyle = { } ; const innerStyle = { } ; if ( flattenStyle ) { Object . keys ( flattenStyle ) . forEach ( ( key ) => { if ( SYNC_TYPE_STYLE_REGEX . test ( key ) ) { wrapperStyle [ key ] = flattenStyle [ key ] ; innerStyle [ key ] = flattenStyle [ key ] ; } else if ( WRAPPER_TYPE_STYLE_REGEX . test ( key ) ) { wrapperStyle [ key ] = flattenStyle [ key ] ; } else { innerStyle [ key ] = flattenStyle [ key ] ; } } ) ; } return { wrapperStyle , innerStyle } ; } ; param { string } styles returns { Object } export const parseStyles = ( styles = '' ) : { [ key ] : string ; } => { return styles . split ( ';' ) . filter ( ( style ) => style . split ( ':' ) . length === 2 ) . map ( ( style ) => [ style . split ( ':' ) [ 0 ] . trim ( ) . replace ( /-./g , c => c . substr ( 1 ) . toUpperCase ( ) ) , style . split ( ':' ) [ 1 ] . trim ( ) ] ) . reduce ( ( styleObj , style ) => ( { ... styleObj , [ style [ 0 ] ] : style [ 1 ] , } ) , { } ) ; } ; export const noop = ( ... args ) : void => { } ; export default { omit , dismemberStyle , parseStyles , noop , } ;