@dichioniccolo/odata-filter-parser
Version:
34 lines (33 loc) • 1.01 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.createInstance = exports.getParts = exports.setDeepValue = void 0;
function setDeepValue(obj, [prop, ...path], method, value) {
if (!path.length) {
obj[prop] = {
[method]: value,
};
}
else {
if (!(prop in obj)) {
obj[prop] = {};
}
setDeepValue(obj[prop], path, method, value);
}
return obj;
}
exports.setDeepValue = setDeepValue;
function getParts(value) {
if (!value || value.trim().length === 0) {
return null;
}
if (value.startsWith("(") && value.endsWith(")")) {
value = value.substring(1, value.length - 1);
}
// TODO: Here we might want to include other operators like OR
return value.split(" and ").map((v) => v.trim());
}
exports.getParts = getParts;
function createInstance(instances, className, ...args) {
return new instances[className](...args);
}
exports.createInstance = createInstance;
;