12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455 |
- "use strict";
- Object.defineProperty(exports, "__esModule", { value: true });
- exports.yeast = exports.decode = exports.encode = void 0;
- const alphabet = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-_".split(""), length = 64, map = {};
- let seed = 0, i = 0, prev;
- function encode(num) {
- let encoded = "";
- do {
- encoded = alphabet[num % length] + encoded;
- num = Math.floor(num / length);
- } while (num > 0);
- return encoded;
- }
- exports.encode = encode;
- function decode(str) {
- let decoded = 0;
- for (i = 0; i < str.length; i++) {
- decoded = decoded * length + map[str.charAt(i)];
- }
- return decoded;
- }
- exports.decode = decode;
- function yeast() {
- const now = encode(+new Date());
- if (now !== prev)
- return (seed = 0), (prev = now);
- return now + "." + encode(seed++);
- }
- exports.yeast = yeast;
- for (; i < length; i++)
- map[alphabet[i]] = i;
|