@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 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 and return its value
3040
- * {{findBy items "name" "abc" "age"}} - returns age of item where name="abc"
3041
- * {{findBy users "id" 123 "email"}} - returns email of user where id=123
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, returnProp) {
3044
- if (!Array.isArray(collection)) return "";
3045
- const found = collection.find((item) => item && item[prop] === value);
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
- * Find object in array by property (block helper version, sets context to found object)
3051
- * {{#findByBlock items "name" "abc"}}{{this.age}}{{/findByBlock}}
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 findByBlock = function(collection, prop, value, options) {
3054
- if (!Array.isArray(collection)) return options.inverse ? options.inverse(this) : "";
3055
- const found = collection.find((item) => item && item[prop] === value);
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
- findByBlock,
3113
+ filterBy,
3113
3114
  default: defaultValue,
3114
3115
  neither,
3115
3116
  ifEven,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@posx/core",
3
- "version": "5.5.338",
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.338",
3
+ "version": "5.5.340",
4
4
  "description": "POSX core libraries",
5
5
  "type": "module",
6
6
  "main": "./build/index.js",