import htmlTags from "html-tags" ; const englishWords = require ( "an-array-of-english-words/index.json" ) ; const SPLIT_REGEXP = /[ \-_:]+/ ; const REG_EXP = /^[a-z]+$/ ; const allWords = new Set ( [ "btn" , "checkbox" , "dropdown" , "fa" , "grid" , "inputtext" , "lg" , "login" , "logout" , "md" , "mui" , "nav" , "signin" , "signout" , "signup" , "sm" , "textinput" , "todo" , "cvc" , "paypal" , ... htmlTags , ... englishWords , ] ) ; for ( let i = 0 ; i < 26 ; i ++ ) allWords . delete ( ( i + 10 ) . toString ( 36 ) ) ; function splitCamelCaseWithAbbreviations ( text ) { return text . split ( /([A-Z][a-z]+)/ ) . filter ( ( val ) => val . length ) ; } export const getTokens = ( value ) : string [ ] => { const tokens = [ ] ; value . split ( SPLIT_REGEXP ) . forEach ( ( token ) => { if ( token . match ( /\d/ ) ) { tokens . push ( token ) ; } else { tokens . push ( ... splitCamelCaseWithAbbreviations ( token ) ) ; } } ) ; return tokens . map ( ( token ) => token . toLowerCase ( ) ) ; } ; export const isDynamicEpoch = ( value ) => { const dateValue = new Date ( value ) ; const currentDate = new Date ( ) ; const diffTime = Math . abs ( currentDate - dateValue ) ; if ( diffTime < 3600000 ) return true ; return false ; } ; summary param { String } value return { Boolean } export const isDynamic = ( value ) : boolean => { if ( ! value || typeof value !== "string" ) return true ; if ( value . startsWith ( "Styled" ) ) return true ; const tokens = getTokens ( value ) ; let words = 0 ; let numbers = 0 ; let penalty = 0 ; for ( let i = 0 ; i < tokens . length ; i ++ ) { const token = tokens [ i ] ; if ( allWords . has ( token ) ) { words += 1 ; } else if ( ! isNaN ( Number ( token ) ) ) { if ( ! isDynamicEpoch ( Number ( token ) ) ) { numbers += 1 ; } else { penalty += 2 ; } } else if ( /\d/ . test ( token ) ) { return true ; } } return ( words + numbers ) / ( tokens . length + penalty ) <= 0.5 ; } ;