@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 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 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
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, 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;
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
- * Find object in array by property (block helper version, sets context to found object)
3051
- * {{#findByBlock items "name" "abc"}}{{this.age}}{{/findByBlock}}
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 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) : "";
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
- findByBlock,
3110
+ filterBy,
3113
3111
  default: defaultValue,
3114
3112
  neither,
3115
3113
  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.339",
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.339",
4
4
  "description": "POSX core libraries",
5
5
  "type": "module",
6
6
  "main": "./build/index.js",