diff --git a/index.js b/index.js index ce30832..2bdf213 100644 --- a/index.js +++ b/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) { - const alphabet = 'e5fcdg3hqa4b1n0pij2rstuv67mwx89klyz' - const base = 16367 - let len = code.length - let num = 0 - for (let i = 0; i < len; i++) { - num += alphabet.indexOf(code[i]) * Math.pow(alphabet.length, i) + 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) + } + 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 } /**