import { BemObject } from "./interface" ; export const R_BEM_REGEX = /^.(?:((?:[a-z0-9]+-)*[a-z0-9]+)(__(?:[a-z0-9]+-)*[a-z0-9]+)?(--(?:[a-z0-9]+-)*[a-z0-9]+)?)$/ ; /**
 * function to find the LCS (longest common substring) from a string array
 *
 */ export function findLcsMap ( arr ) { let wordMap = { } ; let splitArr = arr . map ( item => item . split ( "-" ) ) ; splitArr . forEach ( word => { if ( wordMap [ word [ 0 ] ] ) { wordMap [ word [ 0 ] ] . push ( word . join ( "-" ) ) ; } else { wordMap [ word [ 0 ] ] = new Array ( word . join ( "-" ) ) ; } } ) ; let reducedWordMap = { } ; for ( let [ key , value ] of Object . entries ( wordMap ) ) { if ( value . length > 1 ) { value . forEach ( item => { reducedWordMap [ item ] = key ; } ) ; } } return reducedWordMap ; } param selector returns export function parseBemSelector ( selector ) { if ( R_BEM_REGEX . test ( selector ) ) { const [ , block , element , modifier ] = R_BEM_REGEX . exec ( selector ) || [ undefined , undefined , undefined , undefined ] ; if ( block || element || modifier ) { return { block , element , modifier } ; } } return null ; }