import { escapeDoubleQuote , reverseEscape , string2RegArray , string2ReplaceParam } from "utils/input" ; import { util as magicaction } from "addons/magicaction" ; import { getMNLinkValue } from "utils/profile/updateDataSource" ; const checkInputCorrect = ( str , key ) : boolean => { try { switch ( key ) { case "wordCount" : { const input = reverseEscape ( str ) ; if ( Array . isArray ( input ) && input . length == 2 && input . every ( item => Number . isInteger ( item ) ) ) { } else throw "" ; break ; } case "wordCountArea" : { const input = reverseEscape ( str ) ; if ( Array . isArray ( input ) && input . length == 3 && input . every ( item => Number . isInteger ( item ) ) ) { } else throw "" ; break ; } case "mergeText" : case "customComplete" : reverseEscape ( `"${ escapeDoubleQuote ( str ) }"` ) ; break ; case "changeColor" : { const index = Number ( str ) ; if ( ! Number . isInteger ( index ) ) throw "" ; if ( index > 16 || index < 1 ) throw "" ; break ; } case "filterCards" : { string2RegArray ( str ) . flat ( ) . forEach ( reg => void reg . test ( "test" ) ) ; } case "customDefLink" : case "customBeTitle" : case "customSplit" : { const res = getMNLinkValue ( str ) ; if ( ! res ) throw "" ; string2RegArray ( res ) . flat ( ) . forEach ( reg => void reg . test ( "test" ) ) ; break ; } case "renameTitle" : { str = /^\(.*\)$/ . test ( str ) ? str : `(/^.*$/g, "${ escapeDoubleQuote ( str ) }")` ; const { regexp , newSubStr } = string2ReplaceParam ( str ) [ 0 ] ; "test" . replace ( regexp , newSubStr ) ; if ( /%\[.*\]/ . test ( newSubStr ) ) magicaction . getSerialInfo ( newSubStr , 1 ) ; break ; } case "customTag" : case "customList" : case "customReplace" : case "customExtractTitle" : case "customStandardize" : { const res = getMNLinkValue ( str ) ; if ( ! res ) throw "" ; string2ReplaceParam ( res ) . forEach ( param => { "test" . replace ( param . regexp , param . newSubStr ) ; } ) ; break ; } case "tagSelected" : str = /^\(.*\)$/ . test ( str ) ? str : `(/./, "${ escapeDoubleQuote ( str ) }")` ; default : string2ReplaceParam ( str ) . forEach ( param => { "test" . replace ( param . regexp , param . newSubStr ) ; } ) ; break ; } } catch { return false ; } return true ; } ; export default checkInputCorrect ;