UNPKG

tetris-fumen

Version:
24 lines (23 loc) 906 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.createCommentParser = void 0; var COMMENT_TABLE = ' !"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~'; var MAX_COMMENT_CHAR_VALUE = COMMENT_TABLE.length + 1; var createCommentParser = function () { return { decode: function (v) { var str = ''; var value = v; for (var count = 0; count < 4; count += 1) { var index = value % MAX_COMMENT_CHAR_VALUE; str += COMMENT_TABLE[index]; value = Math.floor(value / MAX_COMMENT_CHAR_VALUE); } return str; }, encode: function (ch, count) { return COMMENT_TABLE.indexOf(ch) * Math.pow(MAX_COMMENT_CHAR_VALUE, count); }, }; }; exports.createCommentParser = createCommentParser;