inibase 1.0.0-rc.80 → 1.0.0-rc.81

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.
@@ -62,36 +62,36 @@ export declare const hashString: (str: string) => string;
62
62
  *
63
63
  * @param operator - The comparison operator (e.g., '=', '!=', '>', '<', '>=', '<=', '[]', '![]', '*', '!*').
64
64
  * @param originalValue - The value to compare, can be a single value or an array of values.
65
- * @param comparedAtValue - The value or values to compare against.
65
+ * @param comparedValue - The value or values to compare against.
66
66
  * @param fieldType - Optional type of the field to guide comparison (e.g., 'password', 'boolean').
67
67
  * @param fieldChildrenType - Optional type for child elements in array inputs.
68
68
  * @returns boolean - Result of the comparison operation.
69
69
  *
70
70
  * Note: Handles various data types and comparison logic, including special handling for passwords and regex patterns.
71
71
  */
72
- export declare const compare: (operator: ComparisonOperator, originalValue: string | number | boolean | null | (string | number | boolean | null)[], comparedAtValue: string | number | boolean | null | (string | number | boolean | null)[], fieldType?: FieldType | FieldType[], fieldChildrenType?: FieldType | FieldType[]) => boolean;
72
+ export declare const compare: (operator: ComparisonOperator, originalValue: string | number | boolean | null | (string | number | boolean | null)[], comparedValue: string | number | boolean | null | (string | number | boolean | null)[], fieldType?: FieldType | FieldType[], fieldChildrenType?: FieldType | FieldType[]) => boolean;
73
73
  /**
74
74
  * Helper function to check equality based on the field type.
75
75
  *
76
76
  * @param originalValue - The original value.
77
- * @param comparedAtValue - The value to compare against.
77
+ * @param comparedValue - The value to compare against.
78
78
  * @param fieldType - Type of the field.
79
79
  * @returns boolean - Result of the equality check.
80
80
  */
81
- export declare const isEqual: (originalValue: string | number | boolean | null | (string | number | boolean | null)[], comparedAtValue: string | number | boolean | null | (string | number | boolean | null)[], fieldType?: FieldType | FieldType[]) => boolean;
81
+ export declare const isEqual: (originalValue: string | number | boolean | null | (string | number | boolean | null)[], comparedValue: string | number | boolean | null | (string | number | boolean | null)[], fieldType?: FieldType) => boolean;
82
82
  /**
83
83
  * Helper function to check array equality.
84
84
  *
85
85
  * @param originalValue - The original value.
86
- * @param comparedAtValue - The value to compare against.
86
+ * @param comparedValue - The value to compare against.
87
87
  * @returns boolean - Result of the array equality check.
88
88
  */
89
- export declare const isArrayEqual: (originalValue: string | number | boolean | null | (string | number | boolean | null)[], comparedAtValue: string | number | boolean | null | (string | number | boolean | null)[]) => boolean;
89
+ export declare const isArrayEqual: (originalValue: string | number | boolean | null | (string | number | boolean | null)[], comparedValue: string | number | boolean | null | (string | number | boolean | null)[]) => boolean;
90
90
  /**
91
91
  * Helper function to check wildcard pattern matching using regex.
92
92
  *
93
93
  * @param originalValue - The original value.
94
- * @param comparedAtValue - The value with wildcard pattern.
94
+ * @param comparedValue - The value with wildcard pattern.
95
95
  * @returns boolean - Result of the wildcard pattern matching.
96
96
  */
97
- export declare const isWildcardMatch: (originalValue: string | number | boolean | null | (string | number | boolean | null)[], comparedAtValue: string | number | boolean | null | (string | number | boolean | null)[]) => boolean;
97
+ export declare const isWildcardMatch: (originalValue: string | number | boolean | null | (string | number | boolean | null)[], comparedValue: string | number | boolean | null | (string | number | boolean | null)[]) => boolean;
@@ -139,122 +139,120 @@ export const hashString = (str) => createHash("sha256").update(str).digest("hex"
139
139
  *
140
140
  * @param operator - The comparison operator (e.g., '=', '!=', '>', '<', '>=', '<=', '[]', '![]', '*', '!*').
141
141
  * @param originalValue - The value to compare, can be a single value or an array of values.
142
- * @param comparedAtValue - The value or values to compare against.
142
+ * @param comparedValue - The value or values to compare against.
143
143
  * @param fieldType - Optional type of the field to guide comparison (e.g., 'password', 'boolean').
144
144
  * @param fieldChildrenType - Optional type for child elements in array inputs.
145
145
  * @returns boolean - Result of the comparison operation.
146
146
  *
147
147
  * Note: Handles various data types and comparison logic, including special handling for passwords and regex patterns.
148
148
  */
149
- export const compare = (operator, originalValue, comparedAtValue, fieldType, fieldChildrenType) => {
149
+ export const compare = (operator, originalValue, comparedValue, fieldType, fieldChildrenType) => {
150
150
  // Determine the field type if it's an array of potential types.
151
151
  if (Array.isArray(fieldType)) {
152
152
  fieldType = detectFieldType(String(originalValue), fieldType);
153
153
  }
154
154
  // Handle comparisons involving arrays.
155
- if (Array.isArray(comparedAtValue) && !["[]", "![]"].includes(operator)) {
156
- return comparedAtValue.some((comparedAtValueSingle) => compare(operator, originalValue, comparedAtValueSingle, fieldType));
155
+ if (Array.isArray(comparedValue) && !["[]", "![]"].includes(operator)) {
156
+ return comparedValue.some((value) => compare(operator, originalValue, value, fieldType));
157
157
  }
158
158
  // Switch statement for different comparison operators.
159
159
  switch (operator) {
160
160
  // Equal (Case Insensitive for strings, specific handling for passwords and booleans).
161
161
  case "=":
162
- return isEqual(originalValue, comparedAtValue, fieldType);
162
+ return isEqual(originalValue, comparedValue, fieldType);
163
163
  // Not Equal.
164
164
  case "!=":
165
- return !isEqual(originalValue, comparedAtValue, fieldType);
165
+ return !isEqual(originalValue, comparedValue, fieldType);
166
166
  // Greater Than.
167
167
  case ">":
168
- return (originalValue !== null &&
169
- comparedAtValue !== null &&
170
- originalValue > comparedAtValue);
168
+ return compareNonNullValues(originalValue, comparedValue, (a, b) => a > b);
171
169
  // Less Than.
172
170
  case "<":
173
- return (originalValue !== null &&
174
- comparedAtValue !== null &&
175
- originalValue < comparedAtValue);
171
+ return compareNonNullValues(originalValue, comparedValue, (a, b) => a < b);
176
172
  // Greater Than or Equal.
177
173
  case ">=":
178
- return (originalValue !== null &&
179
- comparedAtValue !== null &&
180
- originalValue >= comparedAtValue);
174
+ return compareNonNullValues(originalValue, comparedValue, (a, b) => a >= b);
181
175
  // Less Than or Equal.
182
176
  case "<=":
183
- return (originalValue !== null &&
184
- comparedAtValue !== null &&
185
- originalValue <= comparedAtValue);
177
+ return compareNonNullValues(originalValue, comparedValue, (a, b) => a <= b);
186
178
  // Array Contains (equality check for arrays).
187
179
  case "[]":
188
- return isArrayEqual(originalValue, comparedAtValue);
180
+ return isArrayEqual(originalValue, comparedValue);
189
181
  // Array Does Not Contain.
190
182
  case "![]":
191
- return !isArrayEqual(originalValue, comparedAtValue);
183
+ return !isArrayEqual(originalValue, comparedValue);
192
184
  // Wildcard Match (using regex pattern).
193
185
  case "*":
194
- return isWildcardMatch(originalValue, comparedAtValue);
186
+ return isWildcardMatch(originalValue, comparedValue);
195
187
  // Not Wildcard Match.
196
188
  case "!*":
197
- return !isWildcardMatch(originalValue, comparedAtValue);
189
+ return !isWildcardMatch(originalValue, comparedValue);
198
190
  // Unsupported operator.
199
191
  default:
200
192
  throw new Error(`Unsupported operator: ${operator}`);
201
193
  }
202
194
  };
195
+ /**
196
+ * Helper function to handle non-null comparisons.
197
+ */
198
+ const compareNonNullValues = (originalValue, comparedValue, comparator) => {
199
+ return (originalValue !== null &&
200
+ comparedValue !== null &&
201
+ comparator(originalValue, comparedValue));
202
+ };
203
203
  /**
204
204
  * Helper function to check equality based on the field type.
205
205
  *
206
206
  * @param originalValue - The original value.
207
- * @param comparedAtValue - The value to compare against.
207
+ * @param comparedValue - The value to compare against.
208
208
  * @param fieldType - Type of the field.
209
209
  * @returns boolean - Result of the equality check.
210
210
  */
211
- export const isEqual = (originalValue, comparedAtValue, fieldType) => {
212
- // Switch based on the field type for specific handling.
211
+ export const isEqual = (originalValue, comparedValue, fieldType) => {
213
212
  switch (fieldType) {
214
- // Password comparison.
215
213
  case "password":
216
- return isPassword(originalValue) && typeof comparedAtValue === "string"
217
- ? comparePassword(originalValue, comparedAtValue)
214
+ return isPassword(originalValue) && typeof comparedValue === "string"
215
+ ? comparePassword(originalValue, comparedValue)
218
216
  : false;
219
- // Boolean comparison.
220
217
  case "boolean":
221
- return Number(originalValue) === Number(comparedAtValue);
222
- // Default comparison.
218
+ return Number(originalValue) === Number(comparedValue);
223
219
  default:
224
- return originalValue == comparedAtValue;
220
+ return originalValue == comparedValue;
225
221
  }
226
222
  };
227
223
  /**
228
224
  * Helper function to check array equality.
229
225
  *
230
226
  * @param originalValue - The original value.
231
- * @param comparedAtValue - The value to compare against.
227
+ * @param comparedValue - The value to compare against.
232
228
  * @returns boolean - Result of the array equality check.
233
229
  */
234
- export const isArrayEqual = (originalValue, comparedAtValue) => {
235
- return ((Array.isArray(originalValue) &&
236
- Array.isArray(comparedAtValue) &&
237
- originalValue.some((v) => comparedAtValue.includes(v))) ||
238
- (Array.isArray(originalValue) &&
239
- !Array.isArray(comparedAtValue) &&
240
- originalValue.includes(comparedAtValue)) ||
241
- (!Array.isArray(originalValue) &&
242
- Array.isArray(comparedAtValue) &&
243
- comparedAtValue.includes(originalValue)) ||
244
- (!Array.isArray(originalValue) &&
245
- !Array.isArray(comparedAtValue) &&
246
- comparedAtValue === originalValue));
230
+ export const isArrayEqual = (originalValue, comparedValue) => {
231
+ if (Array.isArray(originalValue) && Array.isArray(comparedValue)) {
232
+ return originalValue.some((v) => comparedValue.includes(v));
233
+ }
234
+ if (Array.isArray(originalValue)) {
235
+ return originalValue.includes(comparedValue);
236
+ }
237
+ if (Array.isArray(comparedValue)) {
238
+ return comparedValue.includes(originalValue);
239
+ }
240
+ return originalValue === comparedValue;
247
241
  };
248
242
  /**
249
243
  * Helper function to check wildcard pattern matching using regex.
250
244
  *
251
245
  * @param originalValue - The original value.
252
- * @param comparedAtValue - The value with wildcard pattern.
246
+ * @param comparedValue - The value with wildcard pattern.
253
247
  * @returns boolean - Result of the wildcard pattern matching.
254
248
  */
255
- export const isWildcardMatch = (originalValue, comparedAtValue) => {
256
- const wildcardPattern = `^${(String(comparedAtValue).includes("%")
257
- ? String(comparedAtValue)
258
- : `%${String(comparedAtValue)}%`).replace(/%/g, ".*")}$`;
259
- return new RegExp(wildcardPattern, "i").test(String(originalValue));
249
+ export const isWildcardMatch = (originalValue, comparedValue) => {
250
+ const comparedValueStr = String(comparedValue);
251
+ const originalValueStr = String(originalValue);
252
+ if (!comparedValueStr.includes("%") &&
253
+ (comparedValueStr === originalValueStr ||
254
+ comparedValueStr.toLowerCase() === originalValueStr.toLowerCase()))
255
+ return true;
256
+ const wildcardPattern = `^${(comparedValueStr.includes("%") ? comparedValueStr : `%${comparedValueStr}%`).replace(/%/g, ".*")}$`;
257
+ return new RegExp(wildcardPattern, "i").test(originalValueStr);
260
258
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "inibase",
3
- "version": "1.0.0-rc.80",
3
+ "version": "1.0.0-rc.81",
4
4
  "type": "module",
5
5
  "author": {
6
6
  "name": "Karim Amahtil",