@cellaware/utils 8.11.19 → 8.11.20

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.
Files changed (63) hide show
  1. package/dist/azure/cosmos.d.ts +112 -0
  2. package/dist/azure/cosmos.js +305 -0
  3. package/dist/azure/email.d.ts +3 -0
  4. package/dist/azure/email.js +20 -0
  5. package/dist/azure/function.d.ts +14 -0
  6. package/dist/azure/function.js +124 -0
  7. package/dist/azure/slot.d.ts +1 -0
  8. package/dist/azure/slot.js +4 -0
  9. package/dist/azure/storage.d.ts +14 -0
  10. package/dist/azure/storage.js +81 -0
  11. package/dist/chatwms/alert.d.ts +97 -0
  12. package/dist/chatwms/alert.js +74 -0
  13. package/dist/chatwms/azure/cosmos.d.ts +25 -0
  14. package/dist/chatwms/azure/cosmos.js +43 -0
  15. package/dist/chatwms/azure/function.d.ts +21 -0
  16. package/dist/chatwms/azure/function.js +29 -0
  17. package/dist/chatwms/azure/storage.d.ts +15 -0
  18. package/dist/chatwms/azure/storage.js +27 -0
  19. package/dist/chatwms/client.d.ts +18 -0
  20. package/dist/chatwms/client.js +48 -0
  21. package/dist/chatwms/cosmos.d.ts +24 -0
  22. package/dist/chatwms/cosmos.js +532 -0
  23. package/dist/chatwms/dashboard.d.ts +80 -0
  24. package/dist/chatwms/dashboard.js +17 -0
  25. package/dist/chatwms/datagrid.d.ts +215 -0
  26. package/dist/chatwms/datagrid.js +1454 -0
  27. package/dist/chatwms/developer.d.ts +27 -0
  28. package/dist/chatwms/developer.js +12 -0
  29. package/dist/chatwms/github/issue.d.ts +1 -0
  30. package/dist/chatwms/github/issue.js +4 -0
  31. package/dist/chatwms/instance.d.ts +16 -0
  32. package/dist/chatwms/instance.js +18 -0
  33. package/dist/chatwms/integration.d.ts +24 -0
  34. package/dist/chatwms/integration.js +19 -0
  35. package/dist/chatwms/pdf.d.ts +95 -0
  36. package/dist/chatwms/pdf.js +147 -0
  37. package/dist/chatwms/report.d.ts +126 -0
  38. package/dist/chatwms/report.js +55 -0
  39. package/dist/chatwms/response.d.ts +18 -0
  40. package/dist/chatwms/response.js +25 -0
  41. package/dist/chatwms/search.d.ts +12 -0
  42. package/dist/chatwms/search.js +9 -0
  43. package/dist/chatwms/teams.d.ts +237 -0
  44. package/dist/chatwms/teams.js +205 -0
  45. package/dist/chatwms/user.d.ts +31 -0
  46. package/dist/chatwms/user.js +42 -0
  47. package/dist/chatwms/warehouse.d.ts +3 -0
  48. package/dist/chatwms/warehouse.js +3 -0
  49. package/dist/github/issue.d.ts +1 -0
  50. package/dist/github/issue.js +23 -0
  51. package/dist/llm/chain-store.d.ts +49 -0
  52. package/dist/llm/chain-store.js +284 -0
  53. package/dist/llm/cost.d.ts +3 -0
  54. package/dist/llm/cost.js +42 -0
  55. package/dist/llm/model.d.ts +12 -0
  56. package/dist/llm/model.js +1 -0
  57. package/dist/stopwatch.d.ts +8 -0
  58. package/dist/stopwatch.js +36 -0
  59. package/dist/util.d.ts +45 -0
  60. package/dist/util.js +288 -0
  61. package/dist/version.d.ts +4 -0
  62. package/dist/version.js +12 -0
  63. package/package.json +1 -1
package/dist/util.js ADDED
@@ -0,0 +1,288 @@
1
+ // Miscellaneous --------------------------------------------------------------------------
2
+ export async function sleep(ms) {
3
+ return new Promise(resolve => setTimeout(resolve, ms));
4
+ }
5
+ export function reverse(str) {
6
+ return str.split('').reverse().join('');
7
+ }
8
+ export function base64Encode(str) {
9
+ return Buffer.from(str, 'utf-8').toString('base64');
10
+ }
11
+ export function base64Decode(str) {
12
+ return Buffer.from(str, 'base64').toString('utf-8');
13
+ }
14
+ export function isArrayLike(obj) {
15
+ return (Array.isArray(obj) ||
16
+ (!!obj &&
17
+ obj.hasOwnProperty("length") &&
18
+ typeof obj.length === "number"));
19
+ }
20
+ /**
21
+ * Default `idx` is 100.
22
+ */
23
+ export function truncateValue(value, idx) {
24
+ if (!value || typeof value !== 'string') {
25
+ return value;
26
+ }
27
+ let truncValue = truncateValuePreserveNewLines(value, idx);
28
+ if (truncValue.includes('\n')) {
29
+ truncValue = value.slice(0, truncValue.indexOf('\n')) + '...';
30
+ }
31
+ return truncValue;
32
+ }
33
+ /**
34
+ * Default `idx` is 100.
35
+ */
36
+ export function truncateValuePreserveNewLines(value, idx) {
37
+ idx = idx ?? 100;
38
+ let truncValue = value.length > idx ? value.slice(0, idx) + '...' : value;
39
+ return truncValue;
40
+ }
41
+ // Dates --------------------------------------------------------------------------
42
+ export function initDate(timeZone) {
43
+ const date = new Date();
44
+ if (!!timeZone) {
45
+ return new Date(date.toLocaleString('en-US', { timeZone }));
46
+ }
47
+ else {
48
+ return date;
49
+ }
50
+ }
51
+ export function convertDateTimeZone(date, timeZone) {
52
+ if (!!timeZone) {
53
+ return new Date(date.toLocaleString('en-US', { timeZone }));
54
+ }
55
+ else {
56
+ return date;
57
+ }
58
+ }
59
+ export function isDaylightSavingTime(timeZone) {
60
+ const date = initDate(timeZone);
61
+ const jan = new Date(date.getFullYear(), 0, 1);
62
+ const jul = new Date(date.getFullYear(), 6, 1);
63
+ return date.getTimezoneOffset() < Math.max(jan.getTimezoneOffset(), jul.getTimezoneOffset());
64
+ }
65
+ export function isLeapYear(timeZone) {
66
+ let year = initDate(timeZone).getFullYear();
67
+ return ((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0);
68
+ }
69
+ export function getDaysInMonth(timeZone) {
70
+ let date = initDate(timeZone);
71
+ // NOTE: month is 0-based.
72
+ return new Date(date.getFullYear(), date.getMonth() + 1, 0).getDate();
73
+ }
74
+ export function getCurrentDayInMonth(timeZone) {
75
+ let date = initDate(timeZone);
76
+ return date.getDate();
77
+ }
78
+ export function getDaysInYear(timeZone) {
79
+ return isLeapYear(timeZone) ? 366 : 365;
80
+ }
81
+ export function getCurrentMonth(timeZone) {
82
+ let date = initDate(timeZone);
83
+ // NOTE: month is 0-based.
84
+ return date.getMonth() + 1;
85
+ }
86
+ export function getCurrentYear(timeZone) {
87
+ let date = initDate(timeZone);
88
+ return date.getFullYear();
89
+ }
90
+ export function isDateString(value) {
91
+ if (typeof value !== 'string')
92
+ return false;
93
+ const str = value.trim();
94
+ /* To be considered a date string, the string:
95
+ - Must contain at least one digit
96
+ - Must include a common date separator (e.g. '-', '/', ':', '.', or 'T')
97
+ - Must not contain any letters other than 'T' or 'Z'
98
+ - Must successfully parse
99
+
100
+ NOTE: We are not worried about month/day names or AM/PM. If these exist,
101
+ the user has clearly elected to format the date in the query itself. */
102
+ if (/[^TZ0-9\s:./-]/i.test(str))
103
+ return false;
104
+ /* Handle some edge cases:
105
+ - If 2 separators, should be at least 6 total characters
106
+ - Every part separated by '-' or '/' must be 1, 2, or >=4 chars long */
107
+ if (str.includes('-')) {
108
+ const dashes = str.split('-');
109
+ if (dashes.length > 1 && str.length < 6) {
110
+ return false;
111
+ }
112
+ }
113
+ else if (str.includes('/')) {
114
+ const slashes = str.split('/');
115
+ if (slashes.length > 1 && str.length < 6) {
116
+ return false;
117
+ }
118
+ }
119
+ const sections = str.split(/[-/]+/).filter(Boolean);
120
+ if (sections.some(s => !(s.length === 1 || s.length === 2 || s.length >= 4))) {
121
+ return false;
122
+ }
123
+ return !isNaN(Date.parse(str));
124
+ }
125
+ /**
126
+ * Will only return matches that **are not** contained in single quotes,
127
+ * double quotes, single line, or multiline comments.
128
+ */
129
+ export function getQueryMatches(query, regex, specificMatchGroup) {
130
+ let matches = [];
131
+ // Find quote ranges first.
132
+ let singleQuoteRanges = [];
133
+ {
134
+ let open = false;
135
+ let startIdx = -1;
136
+ for (let i = 0; i < query.length; i++) {
137
+ if (query[i] === "'") {
138
+ if (open) {
139
+ singleQuoteRanges.push({ startIdx, stopIdx: i });
140
+ }
141
+ else {
142
+ startIdx = i;
143
+ }
144
+ open = !open;
145
+ }
146
+ }
147
+ }
148
+ let doubleQuoteRanges = [];
149
+ {
150
+ let open = false;
151
+ let startIdx = -1;
152
+ for (let i = 0; i < query.length; i++) {
153
+ if (query[i] === '"') {
154
+ if (open) {
155
+ doubleQuoteRanges.push({ startIdx, stopIdx: i });
156
+ }
157
+ else {
158
+ startIdx = i;
159
+ }
160
+ open = !open;
161
+ }
162
+ }
163
+ }
164
+ let singleLineCommentRanges = [];
165
+ {
166
+ let open = false;
167
+ let startIdx = -1;
168
+ for (let i = 0; i < query.length; i++) {
169
+ if (!open && query[i] === '-' && (i < query.length - 1 && query[i + 1] === '-')) {
170
+ open = true;
171
+ startIdx = i;
172
+ }
173
+ else if (open && (query[i] === '\n' || query[i] === '\r')) {
174
+ open = false;
175
+ singleLineCommentRanges.push({ startIdx, stopIdx: i });
176
+ }
177
+ }
178
+ }
179
+ let multilineCommentRanges = [];
180
+ {
181
+ let open = false;
182
+ let startIdx = -1;
183
+ for (let i = 0; i < query.length; i++) {
184
+ if (!open && query[i] === '/' && (i < query.length - 1 && query[i + 1] === '*')) {
185
+ open = true;
186
+ startIdx = i;
187
+ }
188
+ else if (open && query[i] === '/' && (i > 0 && query[i - 1] === '*')) {
189
+ open = false;
190
+ multilineCommentRanges.push({ startIdx, stopIdx: i });
191
+ }
192
+ }
193
+ }
194
+ // Now find matches and filter out the ones that are contained in quotes.
195
+ {
196
+ let match;
197
+ while ((match = regex.exec(query)) != null) {
198
+ let startIdx = match.index;
199
+ let stopIdx = match.index + match[0].length - 1;
200
+ let contained = false;
201
+ for (const quoteRange of singleQuoteRanges) {
202
+ if (quoteRange.startIdx <= startIdx && quoteRange.stopIdx >= stopIdx) {
203
+ contained = true;
204
+ break;
205
+ }
206
+ }
207
+ if (!contained) {
208
+ for (const quoteRange of doubleQuoteRanges) {
209
+ if (quoteRange.startIdx <= startIdx && quoteRange.stopIdx >= stopIdx) {
210
+ contained = true;
211
+ break;
212
+ }
213
+ }
214
+ }
215
+ if (!contained) {
216
+ for (const singleLineCommentRange of singleLineCommentRanges) {
217
+ if (singleLineCommentRange.startIdx <= startIdx && singleLineCommentRange.stopIdx >= stopIdx) {
218
+ contained = true;
219
+ break;
220
+ }
221
+ }
222
+ }
223
+ if (!contained) {
224
+ for (const multilineCommentRange of multilineCommentRanges) {
225
+ if (multilineCommentRange.startIdx <= startIdx && multilineCommentRange.stopIdx >= stopIdx) {
226
+ contained = true;
227
+ break;
228
+ }
229
+ }
230
+ }
231
+ if (!contained) {
232
+ matches.push({ word: match[specificMatchGroup ?? 0], startIdx, stopIdx });
233
+ }
234
+ }
235
+ }
236
+ return matches;
237
+ }
238
+ export function removeQueryMatches(query, matches) {
239
+ let adjQuery = query;
240
+ let offset = 0;
241
+ for (const match of matches) {
242
+ const start = match.startIdx - offset;
243
+ const stop = match.stopIdx + 1 - offset;
244
+ adjQuery = adjQuery.substring(0, start) + adjQuery.substring(stop);
245
+ offset += match.word.length;
246
+ }
247
+ return adjQuery;
248
+ }
249
+ export function replaceQueryMatches(query, matches, replacement, useMatchAsSuffix) {
250
+ let adjQuery = query;
251
+ let offset = 0;
252
+ for (const match of matches) {
253
+ const start = match.startIdx - offset;
254
+ const stop = match.stopIdx + 1 - offset;
255
+ let adjReplacement = replacement;
256
+ if (!!useMatchAsSuffix) {
257
+ adjReplacement = replacement + '_' + match.word;
258
+ }
259
+ adjQuery =
260
+ adjQuery.substring(0, start) +
261
+ adjReplacement +
262
+ adjQuery.substring(stop);
263
+ offset += (match.word.length - adjReplacement.length);
264
+ }
265
+ return adjQuery;
266
+ }
267
+ // LLMs --------------------------------------------------------------------------
268
+ export function removeMarkdownIndicators(input) {
269
+ let output = input;
270
+ // Make sure markdown indicator exists.
271
+ if (output.includes('```')) {
272
+ // Remove first markdown indicator.
273
+ output = output.substring(output.indexOf('```'));
274
+ output = output.substring(output.indexOf('\n'));
275
+ // First markdown indicator removed, now do the last.
276
+ output = output.substring(0, output.indexOf('```')).trim();
277
+ }
278
+ return output;
279
+ }
280
+ export function removePrefixIndicators(input, prefixes) {
281
+ let output = input;
282
+ for (const prefix of prefixes) {
283
+ if (output.includes(prefix)) {
284
+ output = output.substring(output.indexOf(prefix) + prefix.length);
285
+ }
286
+ }
287
+ return output;
288
+ }
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Extracts `version` from `package.json`.
3
+ */
4
+ export declare function getVersion(): string;
@@ -0,0 +1,12 @@
1
+ import fs from 'fs';
2
+ /**
3
+ * Extracts `version` from `package.json`.
4
+ */
5
+ export function getVersion() {
6
+ const path = 'package.json';
7
+ if (!fs.existsSync(path)) {
8
+ throw new Error(`VERSION: '${path}' not found`);
9
+ }
10
+ const content = JSON.parse(fs.readFileSync(path, 'utf8'));
11
+ return content.version ?? '';
12
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cellaware/utils",
3
- "version": "8.11.19",
3
+ "version": "8.11.20",
4
4
  "description": "Cellaware Utilities for Node.js",
5
5
  "author": "Cellaware Technologies",
6
6
  "type": "module",