const BASE64_KEYS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
const BASE64_VALUES = new Array(123);
for (let i = 0; i < 123; ++i) {
BASE64_VALUES[i] = 64;
}
for (let i = 0; i < 64; ++i) {
BASE64_VALUES[BASE64_KEYS.charCodeAt(i)] = i;
}
const HexChars = '0123456789abcdef'.split('');
let _t = ['', '', '', ''];
let UuidTemplate = _t.concat(_t, '-', _t, '-', _t, '-', _t, '-', _t, _t, _t);
let Indices = UuidTemplate.map(function (x, i) {
return x === '-' ? NaN : i;
}).filter(isFinite);
// fcmR3XADNLgJ1ByKhqcC5Z -> fc991dd7-0033-4b80-9d41-c8a86a702e59
//49sjfkvnVPJJ8AhKbbuZbj
/**
* base64 解码为 uuid
* @param {String} base64
* @returns
* @example
* let test = base64ToUuid('fcmR3XADNLgJ1ByKhqcC5Z')
* console.log(test) //fc991dd7-0033-4b80-9d41-c8a86a702e59
*/
function base64ToUuid(base64) {
if (base64.length !== 22) {
return base64;
}
UuidTemplate[0] = base64[0];
UuidTemplate[1] = base64[1];
for (let i = 2, j = 2; i < 22; i += 2) {
let lhs = BASE64_VALUES[base64.charCodeAt(i)];
let rhs = BASE64_VALUES[base64.charCodeAt(i + 1)];
UuidTemplate[Indices[j++]] = HexChars[lhs >> 2];
UuidTemplate[Indices[j++]] = HexChars[((lhs & 3) << 2) | rhs >> 4];
UuidTemplate[Indices[j++]] = HexChars[rhs & 0xF];
}
return UuidTemplate.join('');
}
let test = base64ToUuid('fcmR3XADNLgJ1ByKhqcC5Z')
console.log(test)
/**
* uuid 解码为 base64
* @param {String} uuid
* @returns
* * @example
* let test = uuidToBase64('fc991dd7-0033-4b80-9d41-c8a86a702e59')
* console.log(test) //fcmR3XADNLgJ1ByKhqcC5Z
*/
function uuidToBase64(uuid) {
}
1
msg7086 2021-03-12 18:14:51 +08:00 via Android
这不就是保留前 2 位不变,剩下的编码到 base64 ?
自己写写不行吗。 |
2
newmlp 2021-03-12 18:25:36 +08:00
给我半天工资给你写
|
3
microBlock OP @msg7086 好的 我试试哈
|
4
microBlock OP @newmlp 嘿嘿,下次一定
|
5
TanMusong 2021-03-13 10:15:07 +08:00
解决了吗?看了下 CocosCreator 用的这个,之前 Nodejs 检查资源写了个 uuidToBase64,一会儿我找找
|
6
microBlock OP @TanMusong 哈哈 还没有 我也是在搞这个呢
|
7
TanMusong 2021-03-13 15:30:32 +08:00
@microBlock 我晚上回家找一下
|