Replace deep-map, fix _and filter parsing

This commit is contained in:
rijkvanzanten
2020-11-12 16:09:51 -05:00
parent 8d32eb3629
commit e8f0d70322
4 changed files with 46 additions and 8 deletions

View File

@@ -1,9 +1,29 @@
import { transform, isPlainObject } from 'lodash';
export function deepMap(
object: Record<string, any>,
iterator: (value: any, key: string | number) => any,
context?: any
): any {
if (Array.isArray(object)) {
return object.map(function (val, key) {
return typeof val === 'object'
? deepMap(val, iterator, context)
: iterator.call(context, val, key);
});
} else if (typeof object === 'object') {
const res: Record<string, any> = {};
export function deepMap(obj: Record<string, any>, iterator: Function, context?: Function) {
return transform(obj, function (result: any, val, key) {
result[key] = isPlainObject(val)
? deepMap(val, iterator, context)
: iterator.call(context, val, key, obj);
});
for (var key in object) {
var val = object[key];
if (typeof val === 'object') {
res[key] = deepMap(val, iterator, context);
} else {
res[key] = iterator.call(context, val, key);
}
}
return res;
} else {
return object;
}
}

View File

@@ -3,7 +3,7 @@ import { deepMap } from './deep-map';
import { toArray } from '../utils/to-array';
export function parseFilter(filter: Filter, accountability: Accountability | null) {
return deepMap(filter, (val: any, key: string) => {
return deepMap(filter, (val, key) => {
if (val === 'true') return true;
if (val === 'false') return false;