xast
Version:
AST parsing library
61 lines • 1.89 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.readHexDigit = exports.read16BitHexCode = exports.MapList = void 0;
class MapList {
constructor() {
this._map = new Map;
}
clear() {
this._map.clear();
}
delete(key) {
return this._map.delete(key);
}
forEachKey(key, callbackfn) {
var _a;
(_a = this._map.get(key)) === null || _a === void 0 ? void 0 : _a.forEach((value, index) => callbackfn(value, index));
}
forEach(callbackfn) {
this._map.forEach((values, key) => {
values.forEach((value, index) => callbackfn(value, key, index));
});
}
get(key) {
return this._map.get(key);
}
has(key) {
return this._map.has(key);
}
set(key, value) {
var _a;
if (!this._map.has(key)) {
this._map.set(key, [value]);
}
else {
(_a = this._map.get(key)) === null || _a === void 0 ? void 0 : _a.push(value);
}
return this;
}
get size() {
return this._map.size;
}
}
exports.MapList = MapList;
const read16BitHexCode = (source, position) => {
return (((0, exports.readHexDigit)(source.charCodeAt(position)) << 12) |
((0, exports.readHexDigit)(source.charCodeAt(position + 1)) << 8) |
((0, exports.readHexDigit)(source.charCodeAt(position + 2)) << 4) |
(0, exports.readHexDigit)(source.charCodeAt(position + 3)));
};
exports.read16BitHexCode = read16BitHexCode;
const readHexDigit = (code) => {
return code >= 0x0030 && code <= 0x0039
? code - 0x0030
: code >= 0x0041 && code <= 0x0046
? code - 0x0037
: code >= 0x0061 && code <= 0x0066
? code - 0x0057
: -1;
};
exports.readHexDigit = readHexDigit;
//# sourceMappingURL=utils.js.map