优化 isHashable
This commit is contained in:
parent
069a3ff28c
commit
73c33e3175
24
index.js
24
index.js
@ -46,7 +46,7 @@ class TICrypto {
|
|||||||
*/
|
*/
|
||||||
static isHashable(data, { strict = false } = {}) {
|
static isHashable(data, { strict = false } = {}) {
|
||||||
if (strict) {
|
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
|
return typeof data !== 'undefined' // 允许一切数据,除非 undefined
|
||||||
}
|
}
|
||||||
@ -1310,14 +1310,22 @@ class TICrypto {
|
|||||||
* @memberof TICrypto
|
* @memberof TICrypto
|
||||||
*/
|
*/
|
||||||
static regcode2aiid(code) {
|
static regcode2aiid(code) {
|
||||||
const alphabet = 'e5fcdg3hqa4b1n0pij2rstuv67mwx89klyz'
|
if (typeof code === 'string' && /^[a-zA-Z0-9]+$/.test(code)) {
|
||||||
const base = 16367
|
const alphabet = 'e5fcdg3hqa4b1n0pij2rstuv67mwx89klyz'
|
||||||
let len = code.length
|
const base = 16367
|
||||||
let num = 0
|
code = code.toLowerCase()
|
||||||
for (let i = 0; i < len; i++) {
|
let len = code.length
|
||||||
num += alphabet.indexOf(code[i]) * Math.pow(alphabet.length, i)
|
let num = 0
|
||||||
|
for (let i = 0; i < len; i++) {
|
||||||
|
num += alphabet.indexOf(code[i]) * Math.pow(alphabet.length, i)
|
||||||
|
}
|
||||||
|
let aiid = num / (base - alphabet.length) - base
|
||||||
|
if (aiid >= 0 && Number.isInteger(aiid)) {
|
||||||
|
// 允许 aiid===0:当第一个用户(aiid==1)登录时,需要一个系统默认的邀请码。
|
||||||
|
return aiid
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return num / (base - alphabet.length) - base
|
return null // null 代表一切非法的regcode
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user