export function ModeToString ( mode ) { switch ( mode ) { case VimMode . Insert : return "INSERT" ; case VimMode . Normal : return "NORMAL" ; case VimMode . Visual : return "VISUAL" ; case VimMode . VisualLine : return "VISUAL LINE" ; default : throw new Error ( "Panic!" ) ; } } /**
 * isNumber: Check if value is a number, including
 * the number 0.
 */ export function isNumber ( val ) { let res = parseInt ( val , 10 ) ; return isNaN ? null : res ; } export function KeyToNum ( key ) { let num = key . charCodeAt ( 0 ) - 0x30 ; if ( num < 0 || 9 < num ) { return NaN ; } return num ; } export function GetKeyType ( key ) { let charCode = key . charCodeAt ( 0 ) ; if ( charCode <= 0x2F ) { return VimKeyType . Mark ; } if ( charCode <= 0x39 ) { return VimKeyType . Number ; } if ( charCode <= 0x40 ) { return VimKeyType . Number ; } if ( charCode <= 0x5A ) { return VimKeyType . Charactor ; } if ( charCode <= 0x60 ) { return VimKeyType . Mark ; } if ( charCode <= 0x7A ) { return VimKeyType . Charactor ; } return VimKeyType . Mark ; } export function GetCharClass ( charCode ) { if ( charCode <= 0x20 ) { return CharGroup . Spaces ; } if ( charCode <= 0x2F ) { return CharGroup . Marks ; } if ( charCode <= 0x39 ) { return CharGroup . AlphabetAndNumber ; } if ( charCode <= 0x40 ) { return CharGroup . Marks ; } if ( charCode <= 0x5A ) { return CharGroup . AlphabetAndNumber ; } if ( charCode <= 0x5E ) { return CharGroup . Marks ; } if ( charCode === 0x5F ) { return CharGroup . AlphabetAndNumber ; } if ( charCode === 0x60 ) { return CharGroup . Marks ; } if ( charCode <= 0x7A ) { return CharGroup . AlphabetAndNumber ; } if ( charCode <= 0x7E ) { return CharGroup . Marks ; } if ( charCode === 0x7F ) { return CharGroup . Spaces ; } if ( charCode < 0x3000 ) { return CharGroup . Other ; } if ( charCode === 0x3000 ) { return CharGroup . Spaces ; } if ( charCode <= 0x303F ) { return CharGroup . Marks ; } if ( charCode <= 0x309F ) { return CharGroup . Hiragana ; } if ( charCode <= 0x30FF ) { return CharGroup . Katakana ; } return CharGroup . Other ; } export function CalcVisialPosition ( systemPosition , text , tabSize ) { let tabCount = 0 ; for ( let char of text ) { if ( char === "\t" ) { tabCount ++ ; } else { break ; } } return ( tabSize - 1 ) * tabCount + systemPosition ; } export function CalcSystemPosition ( visualPosition , text , tabSize ) { let tabCount = 0 ; for ( let char of text ) { if ( char === "\t" ) { tabCount ++ ; } else { break ; } } if ( visualPosition <= tabSize * tabCount ) { return Math . floor ( visualPosition / tabSize ) ; } return visualPosition - ( tabSize - 1 ) * tabCount ; }