mirror of
https://github.com/directus/directus.git
synced 2026-02-01 07:24:57 -05:00
Replace deep-map, fix _and filter parsing
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user