@posx/core 5.5.338 → 5.5.339
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 +14 -16
- package/package.json +1 -1
- package/package.publish.json +1 -1
package/build/index.js
CHANGED
|
@@ -3036,25 +3036,23 @@ const inArray = function(value, ...args) {
|
|
|
3036
3036
|
return getValue(args.includes(value), this, options);
|
|
3037
3037
|
};
|
|
3038
3038
|
/**
|
|
3039
|
-
* Find object in array by property
|
|
3040
|
-
* {{findBy
|
|
3041
|
-
* {{findBy
|
|
3039
|
+
* Find first object in array by property, returns the object for chaining
|
|
3040
|
+
* {{findBy modifiers "category_uid" "imc_xxx"}} - returns first matching object
|
|
3041
|
+
* {{lookup (findBy modifiers "category_uid" "imc_xxx") "name"}} - get name of found object
|
|
3042
3042
|
*/
|
|
3043
|
-
const findBy = function(collection, prop, value
|
|
3044
|
-
if (!Array.isArray(collection)) return
|
|
3045
|
-
|
|
3046
|
-
if (!found) return "";
|
|
3047
|
-
return returnProp ? found[returnProp] ?? "" : found;
|
|
3043
|
+
const findBy = function(collection, prop, value) {
|
|
3044
|
+
if (!Array.isArray(collection)) return null;
|
|
3045
|
+
return collection.find((item) => item && item[prop] === value) || null;
|
|
3048
3046
|
};
|
|
3049
3047
|
/**
|
|
3050
|
-
*
|
|
3051
|
-
* {{
|
|
3048
|
+
* Filter array by property value, returns array for indexing
|
|
3049
|
+
* {{filterBy modifiers "category_uid" "imc_xxx"}} - returns matching array
|
|
3050
|
+
* {{lookup (filterBy modifiers "category_uid" "imc_xxx") 0}} - get first match
|
|
3051
|
+
* {{lookup (lookup (filterBy modifiers "category_uid" "imc_xxx") 0) "name"}} - get name of first match
|
|
3052
3052
|
*/
|
|
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) : "";
|
|
3053
|
+
const filterBy = function(collection, prop, value) {
|
|
3054
|
+
if (!Array.isArray(collection)) return [];
|
|
3055
|
+
return collection.filter((item) => item && item[prop] === value);
|
|
3058
3056
|
};
|
|
3059
3057
|
/**
|
|
3060
3058
|
* Returns the first truthy value, or default
|
|
@@ -3109,7 +3107,7 @@ const comparisonHelpers = {
|
|
|
3109
3107
|
includes,
|
|
3110
3108
|
in: inArray,
|
|
3111
3109
|
findBy,
|
|
3112
|
-
|
|
3110
|
+
filterBy,
|
|
3113
3111
|
default: defaultValue,
|
|
3114
3112
|
neither,
|
|
3115
3113
|
ifEven,
|
package/package.json
CHANGED