@phensley/cldr-utils
Version:
Utilities for cldr-engine packages
46 lines • 1.64 kB
JavaScript
// =====================================================================
// TODO: the base-100 encoder is deprecated and will be removed once the
// new encoding for @phensley/timezone rules is completed.
Object.defineProperty(exports, "__esModule", { value: true });
// Simple base-100 UTF-8-safe encoding of numbers. With 64-bit bitwise
// operations we could do a variable-length encoding of numbers up to
// Number.MAX_SAFE_INTEGER. Since JavaScript's bitwise operations only
// support 32-bit numbers, we do this compromise.
// The minus symbol is reserved to indicate negative numbers, and period is
// reserved in case of future support of encoding floating point numbers.
exports.ENCODE = '' +
'!#$%&()*+,0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ' +
'[]^_abcdefghijklmnopqrstuvwxyz{|}~¢£¥¦§©«±µ»¼½¾';
var DECODE = exports.ENCODE.split('').reduce(function (o, ch, i) {
o[ch] = i;
return o;
}, {});
exports.base100encode = function (orig) {
if (orig === 0) {
return exports.ENCODE[0];
}
var res = orig < 0 ? '-' : '';
var n = Math.abs(orig);
while (n >= 100) {
var i = n % 100;
res += exports.ENCODE[i];
n = Math.floor(n / 100);
}
return n > 0 ? res + exports.ENCODE[n] : res;
};
exports.base100decode = function (s) {
var len = s.length;
if (len === 0) {
return 0;
}
var lim = s[0] === '-' ? 1 : 0;
var n = 0;
for (var i = s.length - 1; i >= lim; i--) {
var ch = s[i];
n *= 100;
n += DECODE[ch];
}
return lim === 1 ? -n : n;
};
//# sourceMappingURL=base100.js.map
;