@pujansrt/data-genie
Version:
High performant ETL engine written in TypeScript
44 lines (43 loc) • 1.78 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.IsEmpty = exports.Between = exports.LessThan = exports.GreaterThan = exports.PatternMatch = exports.ValueMatch = exports.IsType = exports.IsNotNull = exports.FieldFilter = void 0;
class FieldFilter {
constructor(fieldName) {
this.rules = [];
this.fieldName = fieldName;
}
addRule(rule) {
this.rules.push(rule);
return this;
}
createRecordFilter() {
return (record) => {
const value = record[this.fieldName];
for (const rule of this.rules) {
if (!rule(value)) {
return false;
}
}
return true;
};
}
}
exports.FieldFilter = FieldFilter;
// Individual field rules
const IsNotNull = () => (value) => value !== null && value !== undefined;
exports.IsNotNull = IsNotNull;
const IsType = (type) => (value) => typeof value === type;
exports.IsType = IsType;
const ValueMatch = (...allowedValues) => (value) => allowedValues.includes(value);
exports.ValueMatch = ValueMatch;
const PatternMatch = (pattern) => (value) => new RegExp(pattern).test(value);
exports.PatternMatch = PatternMatch;
// Add other rules: GreaterThan, LessThan, Between, etc.
const GreaterThan = (threshold) => (value) => typeof value === 'number' && value > threshold;
exports.GreaterThan = GreaterThan;
const LessThan = (threshold) => (value) => typeof value === 'number' && value < threshold;
exports.LessThan = LessThan;
const Between = (min, max) => (value) => typeof value === 'number' && value >= min && value <= max;
exports.Between = Between;
const IsEmpty = () => (value) => value === null || value === undefined || value === '';
exports.IsEmpty = IsEmpty;