author CaMnter
  import { AppletType } from "../type/applet-type" ; import { alipayToWechatXmlMap } from "../map/xml/alipay-to-wechat-map" ; import { wechatToAlipayXmlMap } from "../map/xml/wechat-to-alipay-map" ; param target param expect param $ export function replaceAttrs ( target , expect , $ ? ) { if ( ! $ ) { return undefined ; } const map = getXmlAttrsMap ( target , expect ) ; if ( ! map ) { return undefined ; } let table = { ... map . $base } ; $ ( '*' ) . each ( ( index , element ) => { const name = element . name ; const extendTable = map [ name ] ; if ( extendTable && Object . keys ( extendTable ) . length > 0 ) { table = { ... table , ... extendTable } ; } let expectTable = { } ; Object . keys ( table ) . forEach ( ( property ) => { expectTable [ property . toLowerCase ( ) ] = table [ property ] ; } ) ; const attribs = element . attribs ; if ( attribs ) { const expectAttribs = { } ; Object . keys ( element . attribs ) . forEach ( ( attrName ) => { const alipayAttrName = expectTable [ attrName ] ; if ( alipayAttrName ) { const value = element . attribs [ attrName ] ; expectAttribs [ alipayAttrName ] = value ; } } ) ; element . attribs = expectAttribs ; } } ) ; return $ ; } param target param expect export function getXmlAttrsMap ( target , expect ) { let map = undefined ; if ( AppletType . wx === target && AppletType . my === expect ) { map = wechatToAlipayXmlMap ; } else if ( AppletType . my === target && AppletType . wx === expect ) { map = alipayToWechatXmlMap ; } return map ; }