@cellaware/utils 8.1.0 → 8.1.2

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.
@@ -69,19 +69,19 @@ export declare function getCosmosTimestampSecond(timeZone?: string): string;
69
69
  *
70
70
  * NOTE: default time zone is UTC
71
71
  */
72
- export declare function getCosmosCurrentDayWhereClause(timeZone?: string): string;
72
+ export declare function getCosmosCurrentDayClause(timeZone?: string): string;
73
73
  /**
74
74
  * Returns a `WHERE` clause condition to retrieve records with a `_ts` of this month
75
75
  *
76
76
  * NOTE: default time zone is UTC
77
77
  */
78
- export declare function getCosmosCurrentMonthWhereClause(timeZone?: string): string;
78
+ export declare function getCosmosCurrentMonthClause(timeZone?: string): string;
79
79
  /**
80
80
  * Returns a `WHERE` clause condition to retrieve records with a `_ts` of this year
81
81
  *
82
82
  * NOTE: default time zone is UTC
83
83
  */
84
- export declare function getCosmosCurrentYearWhereClause(timeZone?: string): string;
84
+ export declare function getCosmosCurrentYearClause(timeZone?: string): string;
85
85
  export declare function cosmosSelect(databaseId: string, collectionId: string, partitionKey: string, query: string): Promise<any[]>;
86
86
  export declare function cosmosInsert(databaseId: string, collectionId: string, partitionKey: string, data: any): Promise<boolean>;
87
87
  /**
@@ -141,7 +141,7 @@ export function getCosmosTimestampSecond(timeZone) {
141
141
  *
142
142
  * NOTE: default time zone is UTC
143
143
  */
144
- export function getCosmosCurrentDayWhereClause(timeZone) {
144
+ export function getCosmosCurrentDayClause(timeZone) {
145
145
  return `DateTimeDiff('dd', ${getCosmosTimestampDateTime(timeZone)}, ${getCosmosCurrentDateTime(timeZone)}) = 0`;
146
146
  }
147
147
  /**
@@ -149,7 +149,7 @@ export function getCosmosCurrentDayWhereClause(timeZone) {
149
149
  *
150
150
  * NOTE: default time zone is UTC
151
151
  */
152
- export function getCosmosCurrentMonthWhereClause(timeZone) {
152
+ export function getCosmosCurrentMonthClause(timeZone) {
153
153
  return `DateTimeDiff('mm', ${getCosmosTimestampDateTime(timeZone)}, ${getCosmosCurrentDateTime(timeZone)}) = 0`;
154
154
  }
155
155
  /**
@@ -157,7 +157,7 @@ export function getCosmosCurrentMonthWhereClause(timeZone) {
157
157
  *
158
158
  * NOTE: default time zone is UTC
159
159
  */
160
- export function getCosmosCurrentYearWhereClause(timeZone) {
160
+ export function getCosmosCurrentYearClause(timeZone) {
161
161
  return `DateTimeDiff('yyyy', ${getCosmosTimestampDateTime(timeZone)}, ${getCosmosCurrentDateTime(timeZone)}) = 0`;
162
162
  }
163
163
  export async function cosmosSelect(databaseId, collectionId, partitionKey, query) {
@@ -105,6 +105,7 @@ export interface ConditionalFormat {
105
105
  style: string;
106
106
  row: boolean;
107
107
  }
108
+ export declare function evaluateConditionalFormat(condFmt: ConditionalFormat, dataType: string, value: any): boolean;
108
109
  export interface DatagridCondition {
109
110
  columnName: string;
110
111
  /** `text` | `number` | `date` | `boolean` */
@@ -116,5 +117,11 @@ export interface DatagridCondition {
116
117
  export declare function initDatagridCondition(): DatagridCondition;
117
118
  export declare function summarizeCondition(condition: DatagridCondition, localeMessageFn: (language: string, messageId: string) => Promise<string>): Promise<string>;
118
119
  export declare function codifyCondition(condition: DatagridCondition): string;
120
+ /**
121
+ * Equivalent of `parseNumeric` in front end
122
+ *
123
+ * https://github.com/cellaware/chatwms-az-swa-ng/blob/development/src/app/utils/data.ts#L126
124
+ */
125
+ export declare function stripNumericValueFormat(value: string | number | undefined): any;
119
126
  export declare function transformDatagrid(rows: any[], datagridState: DatagridStateBase, locale: string, condition?: DatagridCondition): DatagridState;
120
127
  export {};
@@ -230,6 +230,33 @@ export const CONDITIONAL_FORMAT_RULES_BOOLEAN = [
230
230
  ConditionalFormatRule.BLANK,
231
231
  ConditionalFormatRule.NOT_BLANK
232
232
  ];
233
+ export function evaluateConditionalFormat(condFmt, dataType, value) {
234
+ const isBlank = (v) => v === null || v === undefined || (dataType !== 'number' && dataType !== 'boolean' && v === '');
235
+ const v1 = condFmt.value;
236
+ const v2 = condFmt.value2;
237
+ const ruleHandlers = {
238
+ [ConditionalFormatRule.EQUALS]: () => value == v1,
239
+ [ConditionalFormatRule.DOES_NOT_EQUAL]: () => value != v1,
240
+ [ConditionalFormatRule.GREATER_THAN]: () => value > v1,
241
+ [ConditionalFormatRule.GREATER_THAN_OR_EQUAL_TO]: () => value >= v1,
242
+ [ConditionalFormatRule.LESS_THAN]: () => value < v1,
243
+ [ConditionalFormatRule.LESS_THAN_OR_EQUAL_TO]: () => value <= v1,
244
+ [ConditionalFormatRule.BETWEEN]: () => value >= v1 && value <= (v2 ?? 0),
245
+ [ConditionalFormatRule.CONTAINS]: () => String(value).includes(v1),
246
+ [ConditionalFormatRule.DOES_NOT_CONTAIN]: () => !String(value).includes(v1),
247
+ [ConditionalFormatRule.BEGINS_WITH]: () => String(value).startsWith(v1),
248
+ [ConditionalFormatRule.ENDS_WITH]: () => String(value).endsWith(v1),
249
+ [ConditionalFormatRule.BLANK]: () => isBlank(value),
250
+ [ConditionalFormatRule.NOT_BLANK]: () => !isBlank(value)
251
+ };
252
+ try {
253
+ const fn = ruleHandlers[condFmt.rule];
254
+ return fn ? fn() : false;
255
+ }
256
+ catch {
257
+ return false;
258
+ }
259
+ }
233
260
  export function initDatagridCondition() {
234
261
  return {
235
262
  columnName: '',
@@ -350,7 +377,7 @@ export function codifyCondition(condition) {
350
377
  *
351
378
  * https://github.com/cellaware/chatwms-az-swa-ng/blob/development/src/app/utils/data.ts#L126
352
379
  */
353
- function stripNumericValueFormat(value) {
380
+ export function stripNumericValueFormat(value) {
354
381
  if (value === undefined)
355
382
  return null;
356
383
  if (typeof value === 'number')
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cellaware/utils",
3
- "version": "8.1.0",
3
+ "version": "8.1.2",
4
4
  "description": "Cellaware Utilities for Node.js",
5
5
  "author": "Cellaware Technologies",
6
6
  "type": "module",