@posx/core 5.5.337 → 5.5.338

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
@@ -2850,16 +2850,284 @@ const stringHelpers = {
2850
2850
  */
2851
2851
  var string_helpers_default = stringHelpers;
2852
2852
 
2853
+ //#endregion
2854
+ //#region src/helpers/comparison.helpers.ts
2855
+ /**
2856
+ * Comparison Helpers for Handlebars
2857
+ * Browser-compatible comparison and logical utilities
2858
+ */
2859
+ const isOptions = (val) => val && typeof val === "object" && typeof val.fn === "function";
2860
+ const getValue = (val, context, options) => {
2861
+ if (isOptions(options)) {
2862
+ if (val) return options.fn ? options.fn(context) : true;
2863
+ return options.inverse ? options.inverse(context) : false;
2864
+ }
2865
+ return val;
2866
+ };
2867
+ /**
2868
+ * Block helper that renders if ALL given values are truthy
2869
+ * {{#and a b c}}...{{else}}...{{/and}}
2870
+ */
2871
+ const and = function(...args) {
2872
+ const options = args.pop();
2873
+ return getValue(args.every((arg) => !!arg), this, options);
2874
+ };
2875
+ /**
2876
+ * Block helper that renders if ANY given value is truthy
2877
+ * {{#or a b c}}...{{else}}...{{/or}}
2878
+ */
2879
+ const or = function(...args) {
2880
+ const options = args.pop();
2881
+ return getValue(args.some((arg) => !!arg), this, options);
2882
+ };
2883
+ /**
2884
+ * Returns true if value is falsey
2885
+ * {{#not val}}...{{/not}}
2886
+ */
2887
+ const not = function(val, options) {
2888
+ return getValue(!val, this, options);
2889
+ };
2890
+ /**
2891
+ * Block helper that renders if a === b (strict equality)
2892
+ * {{#eq a b}}...{{else}}...{{/eq}}
2893
+ */
2894
+ const eq = function(a, b, options) {
2895
+ if (arguments.length === 2) {
2896
+ options = b;
2897
+ b = options?.hash?.compare;
2898
+ }
2899
+ return getValue(a === b, this, options);
2900
+ };
2901
+ /**
2902
+ * Block helper that renders if a == b (loose equality)
2903
+ * {{#is a b}}...{{else}}...{{/is}}
2904
+ */
2905
+ const is = function(a, b, options) {
2906
+ if (arguments.length === 2) {
2907
+ options = b;
2908
+ b = options?.hash?.compare;
2909
+ }
2910
+ return getValue(a == b, this, options);
2911
+ };
2912
+ /**
2913
+ * Block helper that renders if a !== b
2914
+ * {{#neq a b}}...{{else}}...{{/neq}}
2915
+ */
2916
+ const neq = function(a, b, options) {
2917
+ if (arguments.length === 2) {
2918
+ options = b;
2919
+ b = options?.hash?.compare;
2920
+ }
2921
+ return getValue(a !== b, this, options);
2922
+ };
2923
+ /**
2924
+ * Block helper that renders if a != b (loose inequality)
2925
+ * {{#isnt a b}}...{{else}}...{{/isnt}}
2926
+ */
2927
+ const isnt = function(a, b, options) {
2928
+ if (arguments.length === 2) {
2929
+ options = b;
2930
+ b = options?.hash?.compare;
2931
+ }
2932
+ return getValue(a != b, this, options);
2933
+ };
2934
+ /**
2935
+ * Block helper that renders if a > b
2936
+ * {{#gt a b}}...{{else}}...{{/gt}}
2937
+ */
2938
+ const gt = function(a, b, options) {
2939
+ if (arguments.length === 2) {
2940
+ options = b;
2941
+ b = options?.hash?.compare;
2942
+ }
2943
+ return getValue(a > b, this, options);
2944
+ };
2945
+ /**
2946
+ * Block helper that renders if a >= b
2947
+ * {{#gte a b}}...{{else}}...{{/gte}}
2948
+ */
2949
+ const gte = function(a, b, options) {
2950
+ if (arguments.length === 2) {
2951
+ options = b;
2952
+ b = options?.hash?.compare;
2953
+ }
2954
+ return getValue(a >= b, this, options);
2955
+ };
2956
+ /**
2957
+ * Block helper that renders if a < b
2958
+ * {{#lt a b}}...{{else}}...{{/lt}}
2959
+ */
2960
+ const lt = function(a, b, options) {
2961
+ if (arguments.length === 2) {
2962
+ options = b;
2963
+ b = options?.hash?.compare;
2964
+ }
2965
+ return getValue(a < b, this, options);
2966
+ };
2967
+ /**
2968
+ * Block helper that renders if a <= b
2969
+ * {{#lte a b}}...{{else}}...{{/lte}}
2970
+ */
2971
+ const lte = function(a, b, options) {
2972
+ if (arguments.length === 2) {
2973
+ options = b;
2974
+ b = options?.hash?.compare;
2975
+ }
2976
+ return getValue(a <= b, this, options);
2977
+ };
2978
+ /**
2979
+ * Generic compare helper with operator
2980
+ * {{#compare a "===" b}}...{{/compare}}
2981
+ */
2982
+ const compare = function(a, operator, b, options) {
2983
+ if (arguments.length < 4) throw new Error("Helper {{compare}} expects 4 arguments");
2984
+ let result;
2985
+ switch (operator) {
2986
+ case "==":
2987
+ result = a == b;
2988
+ break;
2989
+ case "===":
2990
+ result = a === b;
2991
+ break;
2992
+ case "!=":
2993
+ result = a != b;
2994
+ break;
2995
+ case "!==":
2996
+ result = a !== b;
2997
+ break;
2998
+ case "<":
2999
+ result = a < b;
3000
+ break;
3001
+ case ">":
3002
+ result = a > b;
3003
+ break;
3004
+ case "<=":
3005
+ result = a <= b;
3006
+ break;
3007
+ case ">=":
3008
+ result = a >= b;
3009
+ break;
3010
+ case "typeof":
3011
+ result = typeof a === b;
3012
+ break;
3013
+ default: throw new Error(`Helper {{compare}}: invalid operator: \`${operator}\``);
3014
+ }
3015
+ return getValue(result, this, options);
3016
+ };
3017
+ /**
3018
+ * Block helper that renders if collection contains value
3019
+ * {{#contains array "value"}}...{{else}}...{{/contains}}
3020
+ */
3021
+ const contains = function(collection, value, options) {
3022
+ if (typeof options === "number") options = arguments[3];
3023
+ if (collection == null) return getValue(false, this, options);
3024
+ if (Array.isArray(collection)) return getValue(collection.includes(value), this, options);
3025
+ if (typeof collection === "string") return getValue(collection.includes(value), this, options);
3026
+ if (typeof collection === "object") return getValue(value in collection, this, options);
3027
+ return getValue(false, this, options);
3028
+ };
3029
+ const includes = contains;
3030
+ /**
3031
+ * Block helper that renders if value is in the list
3032
+ * {{#in value "a" "b" "c"}}...{{else}}...{{/in}}
3033
+ */
3034
+ const inArray = function(value, ...args) {
3035
+ const options = args.pop();
3036
+ return getValue(args.includes(value), this, options);
3037
+ };
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
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;
3048
+ };
3049
+ /**
3050
+ * Find object in array by property (block helper version, sets context to found object)
3051
+ * {{#findByBlock items "name" "abc"}}{{this.age}}{{/findByBlock}}
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) : "";
3058
+ };
3059
+ /**
3060
+ * Returns the first truthy value, or default
3061
+ * {{default value "fallback"}}
3062
+ */
3063
+ const defaultValue = function(...args) {
3064
+ for (let i = 0; i < args.length - 1; i++) if (args[i] != null) return args[i];
3065
+ return "";
3066
+ };
3067
+ /**
3068
+ * Block helper that renders if neither a nor b is truthy
3069
+ * {{#neither a b}}...{{else}}...{{/neither}}
3070
+ */
3071
+ const neither = function(a, b, options) {
3072
+ return getValue(!a && !b, this, options);
3073
+ };
3074
+ /**
3075
+ * Block helper that renders if value is even
3076
+ * {{#ifEven value}}...{{else}}...{{/ifEven}}
3077
+ */
3078
+ const ifEven = function(num, options) {
3079
+ return getValue(num % 2 === 0, this, options);
3080
+ };
3081
+ /**
3082
+ * Block helper that renders if value is odd
3083
+ * {{#ifOdd value}}...{{else}}...{{/ifOdd}}
3084
+ */
3085
+ const ifOdd = function(num, options) {
3086
+ return getValue(num % 2 !== 0, this, options);
3087
+ };
3088
+ /**
3089
+ * Block helper that renders if b is divisible by a
3090
+ * {{#ifNth 3 value}}...{{else}}...{{/ifNth}}
3091
+ */
3092
+ const ifNth = function(a, b, options) {
3093
+ return getValue(typeof a === "number" && typeof b === "number" && b % a === 0, this, options);
3094
+ };
3095
+ const comparisonHelpers = {
3096
+ and,
3097
+ or,
3098
+ not,
3099
+ eq,
3100
+ is,
3101
+ neq,
3102
+ isnt,
3103
+ gt,
3104
+ gte,
3105
+ lt,
3106
+ lte,
3107
+ compare,
3108
+ contains,
3109
+ includes,
3110
+ in: inArray,
3111
+ findBy,
3112
+ findByBlock,
3113
+ default: defaultValue,
3114
+ neither,
3115
+ ifEven,
3116
+ ifOdd,
3117
+ ifNth
3118
+ };
3119
+ var comparison_helpers_default = comparisonHelpers;
3120
+
2853
3121
  //#endregion
2854
3122
  //#region src/helpers/helpers.register.ts
2855
3123
  /**
2856
- * String Helpers Registration - Following handlebars-helpers API pattern
3124
+ * Helpers Registration - Following handlebars-helpers API pattern
2857
3125
  *
2858
3126
  * This module follows the same API as the original handlebars-helpers library:
2859
3127
  * helpers({ handlebars: Handlebars })
2860
3128
  */
2861
3129
  /**
2862
- * Register string helpers with Handlebars
3130
+ * Register all helpers with Handlebars
2863
3131
  *
2864
3132
  * @param options - Options object with handlebars instance
2865
3133
  * @returns The registered helpers object
@@ -2867,19 +3135,25 @@ var string_helpers_default = stringHelpers;
2867
3135
  * @example
2868
3136
  * ```typescript
2869
3137
  * import Handlebars from 'handlebars';
2870
- * import helpers from './string-helpers-register';
3138
+ * import helpers from './helpers.register';
2871
3139
  *
2872
- * // Register all string helpers
3140
+ * // Register all helpers
2873
3141
  * helpers({ handlebars: Handlebars });
2874
3142
  *
2875
3143
  * const template = Handlebars.compile('{{camelcase "foo bar baz"}}');
2876
3144
  * console.log(template({})); // 'fooBarBaz'
3145
+ *
3146
+ * const template2 = Handlebars.compile('{{#eq a b}}equal{{else}}not equal{{/eq}}');
3147
+ * console.log(template2({ a: 1, b: 1 })); // 'equal'
2877
3148
  * ```
2878
3149
  */
2879
3150
  function helpers(options) {
2880
3151
  const hbs = options?.handlebars || options?.hbs || __require("handlebars");
2881
- Object.keys(string_helpers_default).forEach((helperName) => {
2882
- hbs.registerHelper(helperName, string_helpers_default[helperName]);
3152
+ Object.keys(string_helpers_default).forEach((name) => {
3153
+ hbs.registerHelper(name, string_helpers_default[name]);
3154
+ });
3155
+ Object.keys(comparison_helpers_default).forEach((name) => {
3156
+ hbs.registerHelper(name, comparison_helpers_default[name]);
2883
3157
  });
2884
3158
  return hbs.helpers;
2885
3159
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@posx/core",
3
- "version": "5.5.337",
3
+ "version": "5.5.338",
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.337",
3
+ "version": "5.5.338",
4
4
  "description": "POSX core libraries",
5
5
  "type": "module",
6
6
  "main": "./build/index.js",