@posx/core 5.5.339 → 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 CHANGED
@@ -3035,24 +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 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
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
3047
  const findBy = function(collection, prop, value) {
3044
3048
  if (!Array.isArray(collection)) return null;
3045
- return collection.find((item) => item && item[prop] === value) || null;
3049
+ return collection.find((item) => getByPath(item, prop) === value) || null;
3046
3050
  };
3047
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
+ * 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
3056
  const filterBy = function(collection, prop, value) {
3054
3057
  if (!Array.isArray(collection)) return [];
3055
- return collection.filter((item) => item && item[prop] === value);
3058
+ return collection.filter((item) => getByPath(item, prop) === value);
3056
3059
  };
3057
3060
  /**
3058
3061
  * Returns the first truthy value, or default
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@posx/core",
3
- "version": "5.5.339",
3
+ "version": "5.5.340",
4
4
  "description": "POSX core libraries",
5
5
  "main": "./build/index.js",
6
6
  "author": "Steven Lee",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@posx/core",
3
- "version": "5.5.339",
3
+ "version": "5.5.340",
4
4
  "description": "POSX core libraries",
5
5
  "type": "module",
6
6
  "main": "./build/index.js",