precis-js
Version:
A JavaScript implementation of RFC 7564 (The PRECIS Framework).
33 lines (27 loc) • 757 B
JavaScript
// Generated by CoffeeScript 1.10.0
(function() {
var WidthMapper;
module.exports = WidthMapper = (function() {
function WidthMapper(data) {
var codepoint, i, j, len;
this._index = {};
for (i = j = 0, len = data.length; j < len; i = j += 2) {
codepoint = data[i];
this._index[codepoint] = data[i + 1];
}
}
WidthMapper.prototype.map = function(codepoints) {
var i, results;
i = codepoints.length - 1;
results = [];
while (i >= 0) {
if (this._index.hasOwnProperty(codepoints[i])) {
codepoints.splice(i, 1, this._index[codepoints[i]]);
}
results.push(--i);
}
return results;
};
return WidthMapper;
})();
}).call(this);