@posx/core 5.5.338 → 5.5.340
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/index.js +17 -16
- package/package.json +1 -1
- package/package.publish.json +1 -1
package/build/index.js
CHANGED
|
@@ -3035,26 +3035,27 @@ const inArray = function(value, ...args) {
|
|
|
3035
3035
|
const options = args.pop();
|
|
3036
3036
|
return getValue(args.includes(value), this, options);
|
|
3037
3037
|
};
|
|
3038
|
+
const getByPath = (obj, path) => {
|
|
3039
|
+
if (!obj || !path) return void 0;
|
|
3040
|
+
return path.split(".").reduce((o, k) => o?.[k], obj);
|
|
3041
|
+
};
|
|
3038
3042
|
/**
|
|
3039
|
-
* Find object in array by property
|
|
3040
|
-
* {{findBy
|
|
3041
|
-
* {{findBy
|
|
3043
|
+
* Find first object in array by property (supports nested path like "item.category_uid")
|
|
3044
|
+
* {{findBy modifiers "item.category_uid" "imc_xxx"}} - returns first matching object
|
|
3045
|
+
* {{lookup (findBy modifiers "item.category_uid" "imc_xxx") "item.name"}} - get item.name
|
|
3042
3046
|
*/
|
|
3043
|
-
const findBy = function(collection, prop, value
|
|
3044
|
-
if (!Array.isArray(collection)) return
|
|
3045
|
-
|
|
3046
|
-
if (!found) return "";
|
|
3047
|
-
return returnProp ? found[returnProp] ?? "" : found;
|
|
3047
|
+
const findBy = function(collection, prop, value) {
|
|
3048
|
+
if (!Array.isArray(collection)) return null;
|
|
3049
|
+
return collection.find((item) => getByPath(item, prop) === value) || null;
|
|
3048
3050
|
};
|
|
3049
3051
|
/**
|
|
3050
|
-
*
|
|
3051
|
-
* {{
|
|
3052
|
+
* Filter array by property value (supports nested path), returns array for indexing
|
|
3053
|
+
* {{filterBy modifiers "item.category_uid" "imc_xxx"}} - returns matching array
|
|
3054
|
+
* {{lookup (filterBy modifiers "item.category_uid" "imc_xxx") 0}} - get first match
|
|
3052
3055
|
*/
|
|
3053
|
-
const
|
|
3054
|
-
if (!Array.isArray(collection)) return
|
|
3055
|
-
|
|
3056
|
-
if (found && options.fn) return options.fn(found);
|
|
3057
|
-
return options.inverse ? options.inverse(this) : "";
|
|
3056
|
+
const filterBy = function(collection, prop, value) {
|
|
3057
|
+
if (!Array.isArray(collection)) return [];
|
|
3058
|
+
return collection.filter((item) => getByPath(item, prop) === value);
|
|
3058
3059
|
};
|
|
3059
3060
|
/**
|
|
3060
3061
|
* Returns the first truthy value, or default
|
|
@@ -3109,7 +3110,7 @@ const comparisonHelpers = {
|
|
|
3109
3110
|
includes,
|
|
3110
3111
|
in: inArray,
|
|
3111
3112
|
findBy,
|
|
3112
|
-
|
|
3113
|
+
filterBy,
|
|
3113
3114
|
default: defaultValue,
|
|
3114
3115
|
neither,
|
|
3115
3116
|
ifEven,
|
package/package.json
CHANGED