import hmacSHA256 from 'crypto-js/hmac-sha256' ; import encHex from 'crypto-js/enc-hex' ; export const getChineseNumber = ( num ) : string => [ '零' , '一' , '二' , '三' , '四' , '五' , '六' , '七' , '八' , '九' , '十' ] [ num ] || '' ; export const getPluginIcon = ( name ) : string => `https://gitee.com/frederick-wang/scu-urp-assistant/raw/master/src/plugins/${ name }/icon.png` ; const getLevenshteinDistance = ( a , b ) : number => { const distanceMatrix = Array ( b . length + 1 ) . fill ( null ) . map ( ( ) => Array ( a . length + 1 ) . fill ( null ) ) ; for ( let i = 0 ; i <= a . length ; i += 1 ) { distanceMatrix [ 0 ] [ i ] = i ; } for ( let j = 0 ; j <= b . length ; j += 1 ) { distanceMatrix [ j ] [ 0 ] = j ; } for ( let j = 1 ; j <= b . length ; j += 1 ) { for ( let i = 1 ; i <= a . length ; i += 1 ) { const indicator = a [ i - 1 ] === b [ j - 1 ] ? 0 : 1 ; distanceMatrix [ j ] [ i ] = Math . min ( distanceMatrix [ j ] [ i - 1 ] + 1 , distanceMatrix [ j - 1 ] [ i ] + 1 , distanceMatrix [ j - 1 ] [ i - 1 ] + indicator ) ; } } return distanceMatrix [ b . length ] [ a . length ] ; } ; export const getTextSimilarity = ( str1 , str2 ) : number => 1 - getLevenshteinDistance ( str1 , str2 ) / Math . max ( str1 . length , str2 . length ) ; export const getUserId = ( studentInfos ) : string => { const studentNumber = studentInfos . get ( '学号' ) ?? '' ; const idNumber = studentInfos . get ( '证件号码' ) ?? '' ; const gaokaoScore = studentInfos . get ( '高考总分' ) ?? '' ; const secret = [ studentNumber , idNumber , gaokaoScore ] . join ( '' ) ; const hmac = hmacSHA256 ( 'scu-urp-assistant' , secret ) . toString ( encHex ) ; return hmac ; } ;