We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
/** * 生成一个len+1的随机数,包含最后一位交验位 * @param len * @returns {string} */ const randomArray = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; const randomArrayLength = randomArray.length; function rand(len, check = true) { let sum = ''; let index; let count = 0; for (let i = 0; i < len; i++) { index = Math.floor(Math.random() * randomArrayLength); sum += randomArray.charAt(index); count += randomArray.charCodeAt(index); } if(check){ //是否添加校验位 sum += randomArray.charAt(count % randomArrayLength); } return sum; }
The text was updated successfully, but these errors were encountered:
id2url(id, version) { if (!version) version = 1; if (typeof id === 'string' && id.length === 24) { return id; } if (id instanceof Array) { for (let i = 0; i < id.length; i++) { const value = id[i]; id[i] = this.id2url(value); } return id; } else if (parseInt(id, 10) > 0) { let url; switch (version) { case 1: url = version + parseInt(`${id * 2 + 56}`, 10 | 0).toString(36 | 0); break; default: url = false; break; } return url; } return id; }
url2id(url, check) { if (!check) check = false; if (url.length === 24 && url.match(/^[0-9a-f]+$/)) return url; //兼容MongoId if (url instanceof Array) { for (var i = 0; i < url.length; i++) { var value = url[i]; url[i] = this.url2id(value); } return url; } else if (url.indexOf(',') > 0) { url = url.split(','); for (var i = 0; i < url.length; i++) { var value = url[i]; if (!value) { delete url[i]; continue; } url[i] = this.url2id(value); } return url.join(','); } else { if (check && url.match(/^(null|undefined)$/i)) { return false; } const version = parseInt(url.substr(0, 1)); let id = 0; switch (version) { case 1: //id = (parseInt(base_convert(url.substr(1), 36, 10)) - 56) / 2; id = (parseInt( parseInt(url.substr(1) + '', 36 | 0).toString(10 | 0)) - 56) / 2; break; case 2: //防止扫用户; case 3: case 4: case 5: case 6: case 7: case 8: case 9: id = 0; break; default: id = url; break; } return 0 < id ? parseInt(id) : 0; } }
Sorry, something went wrong.
No branches or pull requests
The text was updated successfully, but these errors were encountered: