import { JSDOM } from 'jsdom' ; import combine from './combine' ; import extractClassesFromNgClass from './extractClassesFromNgClass' ; param { JSDOM } dom param { element } e param { Array < string > } classes function createCopyOfElementWithClasses ( dom , e , classes ) { const el = dom . window . document . createElement ( e . tagName ) ; el . classList = e . classList ; classes . forEach ( c => el . classList . add ( c ) ) ; return el ; } param { string } html param { string } cssPath function parseNgClass ( html , cssPath ) { const dom = new JSDOM ( html ) ; const all = dom . window . document . getElementsByTagName ( '*' ) ; const inputList = Array . prototype . slice . call ( all ) ; inputList . forEach ( e => { const attrs = Array . prototype . slice . call ( e . attributes ) ; attrs . forEach ( a => { if ( a . name === '[ngclass]' ) { const classes = extractClassesFromNgClass ( a . value ) ; e . removeAttribute ( '[ngclass]' ) ; const classCombinations = combine ( classes ) ; classCombinations . forEach ( c => { const el = createCopyOfElementWithClasses ( dom , e , c ) ; e . parentNode . insertBefore ( el , e . nextSibling ) ; } ) ; } } ) ; } ) ; return dom . serialize ( ) ; } export default parseNgClass ;