import KeyCodes from './keyCodes' ; export const keyReg = /^on(Alt|Ctrl|Meta|Shift){0,4}([A-Z][a-z]*)+$/ ; export const splitKey = ( str ) : Array < string > | null => { let reg = /[A-Z][a-z]*/g ; return str . match ( reg ) ; } ; export const isSpecialKey = ( key ) => { return [ "Alt" , "Ctrl" , "Meta" , "Shift" ] . includes ( key ) ; } ; export const validatKey = ( e , ename ) => { const keys = splitKey ( ename ) ; if ( ! keys ) return ; for ( let index = 0 ; index < keys . length ; index ++ ) { const key = keys [ index ] ; if ( isSpecialKey ( key ) ) { if ( ! e [ `${ key . toLowerCase ( ) }Key` ] ) return false ; } else { if ( e . keyCode !== KeyCodes [ key . toUpperCase ( ) ] ) return false ; } } return true ; } ; export const validPropName = ( e , keyName ) => { if ( keyReg . test ( keyName ) && validatKey ( e , keyName ) ) { return true ; } return false ; } ;