precis-js
Version:
A JavaScript implementation of RFC 7564 (The PRECIS Framework).
58 lines (39 loc) • 1.36 kB
JavaScript
// Generated by CoffeeScript 1.10.0
(function() {
var CodepointPropertyReader, bidiBits, bidiMask, bidiShift, bits, log2, precis, precisBits, precisMask, precisShift;
precis = require('../constants');
/* !pragma coverage-skip-next */
log2 = Math.log2 || function(n) {
return Math.log(n) / Math.LN2;
};
bits = function(n) {
return (log2(n) + 1) | 0;
};
precisBits = bits(Object.keys(precis.PRECIS_CATEGORY).length - 1);
bidiBits = bits(Object.keys(precis.BIDI_CLASS).length - 1);
precisShift = bidiBits + 1;
bidiShift = 1;
precisMask = (1 << precisBits) - 1;
bidiMask = (1 << bidiBits) - 1;
module.exports = CodepointPropertyReader = (function() {
function CodepointPropertyReader(trie) {
this.trie = trie;
}
CodepointPropertyReader.prototype.precisCategory = function(codepoint) {
var data;
data = this.trie.get(codepoint);
return (data >> precisShift) & precisMask;
};
CodepointPropertyReader.prototype.bidiClass = function(codepoint) {
var data;
data = this.trie.get(codepoint);
return (data >> bidiShift) & bidiMask;
};
CodepointPropertyReader.prototype.isNonAsciiSpace = function(codepoint) {
var data;
data = this.trie.get(codepoint);
return data & 1;
};
return CodepointPropertyReader;
})();
}).call(this);