优化 isHashable
This commit is contained in:
parent
069a3ff28c
commit
73c33e3175
12
index.js
12
index.js
@ -46,7 +46,7 @@ class TICrypto {
|
||||
*/
|
||||
static isHashable(data, { strict = false } = {}) {
|
||||
if (strict) {
|
||||
return data ? true : false && typeof data !== 'boolean' && data !== Infinity // 允许大多数数据,除了null、''、0、布尔值、无限数。注意 data 要放在最后,否则会被 return 直接返回,而不是返回 Boolean
|
||||
return typeof data !== 'boolean' && data !== Infinity && data ? true : false // 允许大多数数据,除了null、''、0、布尔值、无限数。注意 data 要放在最后,否则会被 return 直接返回,而不是返回 Boolean
|
||||
}
|
||||
return typeof data !== 'undefined' // 允许一切数据,除非 undefined
|
||||
}
|
||||
@ -1310,14 +1310,22 @@ class TICrypto {
|
||||
* @memberof TICrypto
|
||||
*/
|
||||
static regcode2aiid(code) {
|
||||
if (typeof code === 'string' && /^[a-zA-Z0-9]+$/.test(code)) {
|
||||
const alphabet = 'e5fcdg3hqa4b1n0pij2rstuv67mwx89klyz'
|
||||
const base = 16367
|
||||
code = code.toLowerCase()
|
||||
let len = code.length
|
||||
let num = 0
|
||||
for (let i = 0; i < len; i++) {
|
||||
num += alphabet.indexOf(code[i]) * Math.pow(alphabet.length, i)
|
||||
}
|
||||
return num / (base - alphabet.length) - base
|
||||
let aiid = num / (base - alphabet.length) - base
|
||||
if (aiid >= 0 && Number.isInteger(aiid)) {
|
||||
// 允许 aiid===0:当第一个用户(aiid==1)登录时,需要一个系统默认的邀请码。
|
||||
return aiid
|
||||
}
|
||||
}
|
||||
return null // null 代表一切非法的regcode
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user