-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
66 lines (66 loc) · 2.85 KB
/
index.js
File metadata and controls
66 lines (66 loc) · 2.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
(function (factory) {
if (typeof module === "object" && typeof module.exports === "object") {
var v = factory(require, exports);
if (v !== undefined) module.exports = v;
}
else if (typeof define === "function" && define.amd) {
define(["require", "exports"], factory);
}
})(function (require, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.arrayQL = void 0;
function isObject(item) {
return Object.prototype.toString.call(item).includes("Object");
}
function isArray(item) {
return Array.isArray(item);
}
function isArrayOrObject(item) {
return isArray(item) || isObject(item);
}
function objectQL(object, booleanKeys) {
var selectedObjectKeys = Object.keys(booleanKeys);
return selectedObjectKeys.reduce(function (mappedObject, key) {
var _a;
var selectedPropValue = object[key];
var isSelectedPropValueArray = isArray(selectedPropValue);
var isSelectedPropValueObject = !isSelectedPropValueArray && isObject(selectedPropValue);
var isSelectedPropValueArrayAndItsItemsPrimitive = isSelectedPropValueArray && !isArrayOrObject(selectedPropValue[0]);
var booleanKeysOrQueryOptions = booleanKeys[key];
var value = isSelectedPropValueObject
? objectQL(selectedPropValue, booleanKeysOrQueryOptions)
: isSelectedPropValueArray
? isSelectedPropValueArrayAndItsItemsPrimitive
? selectedPropValue
: arrayQL(selectedPropValue, booleanKeysOrQueryOptions)
: selectedPropValue;
return __assign(__assign({}, mappedObject), (_a = {}, _a[key] = value, _a));
}, {});
}
function arrayQL(array, queryOptions) {
var _a;
var mappedArray = [];
for (var _i = 0, array_1 = array; _i < array_1.length; _i++) {
var object = array_1[_i];
var options = typeof queryOptions === "function" ? queryOptions(object) : queryOptions;
(_a = options.where) !== null && _a !== void 0 ? _a : (options.where = function () { return true; });
if (!options.where(object))
continue;
mappedArray.push(objectQL(object, options.keys));
}
return mappedArray;
}
exports.arrayQL = arrayQL;
});