@amplitude/ampli
Version:
Amplitude CLI
35 lines (34 loc) • 1.02 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.State = exports.StateFactory = void 0;
class StateFactory {
constructor(source, prefix, postfix) {
this.source = source;
this.prefix = [...prefix];
this.postfix = [...postfix];
}
test(fromIndex) {
return this.isPrefix(this.prefix, fromIndex) ? this.prefix.length : 0;
}
isPrefix(prefix, fromIndex) {
return isPrefix(this.source, prefix, fromIndex);
}
}
exports.StateFactory = StateFactory;
class State {
constructor(segmentType, source, length) {
this.segmentType = segmentType;
this.source = source;
this.length = length;
}
isPrefix(prefix, fromIndex) {
return isPrefix(this.source, prefix, fromIndex);
}
}
exports.State = State;
function isPrefix(data, prefix, fromIndex) {
if (data.length < fromIndex + prefix.length) {
return false;
}
return prefix.every((char, i) => data[fromIndex + i] === char);
}