@animepaste/bangumi
Version:
54 lines (51 loc) • 1.12 kB
JavaScript
;
const shortcut = [
["bgmId", "i"],
["title", "t"],
["type", "y"],
["titleCN", "c"],
["titleTranslate", "r"],
["lang", "l"],
["officialSite", "o"],
["begin", "b"],
["end", "e"],
["comment", "m"],
["dmhy", "d"],
["bgm", "g"]
];
const trans = new Map(shortcut);
const inverse = new Map(shortcut.map(([value, key]) => [key, value]));
function compress(raw) {
if (!raw.compress) {
return raw;
} else {
return {
compress: true,
bangumis: raw.bangumis.map((bgm) => {
const obj = {};
for (const [key, value] of Object.entries(bgm)) {
obj[trans.get(key)] = value;
}
return obj;
})
};
}
}
function decompress(compressed) {
if (!compressed.compress) {
return compressed;
} else {
return {
compress: true,
bangumis: compressed.bangumis.map((bgm) => {
const obj = {};
for (const [key, value] of Object.entries(bgm)) {
obj[inverse.get(key)] = value;
}
return obj;
})
};
}
}
exports.compress = compress;
exports.decompress = decompress;