import { isStr } from './utils' ; export const validateContent = ( svgContent ) => { if ( svgContent ) { const div = document . createElement ( 'div' ) ; div . innerHTML = svgContent ; for ( let i = div . childNodes . length - 1 ; i >= 0 ; i -- ) { if ( div . childNodes [ i ] . nodeName . toLowerCase ( ) !== 'svg' ) { div . removeChild ( div . childNodes [ i ] ) ; } } const svgElm = div . firstElementChild ; if ( svgElm && svgElm . nodeName . toLowerCase ( ) === 'svg' ) { svgElm . setAttribute ( 'class' , 's-ion-icon' ) ; if ( isValid ( svgElm as any ) ) { return div . innerHTML ; } } } return '' ; } ; export const isValid = ( elm ) => { if ( elm . nodeType === 1 ) { if ( elm . nodeName . toLowerCase ( ) === 'script' ) { return false ; } for ( let i = 0 ; i < elm . attributes . length ; i ++ ) { const val = elm . attributes [ i ] . value ; if ( isStr ( val ) && val . toLowerCase ( ) . indexOf ( 'on' ) === 0 ) { return false ; } } for ( let i = 0 ; i < elm . childNodes . length ; i ++ ) { if ( ! isValid ( elm . childNodes [ i ] as any ) ) { return false ; } } } return true ; } ;