@cellaware/utils 7.2.2 → 7.2.4

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/dist/llm/cost.js CHANGED
@@ -3,6 +3,10 @@ export function getLLMCostPerToken(modelName) {
3
3
  let inputCost = 0.0;
4
4
  let outputCost = 0.0;
5
5
  switch (modelName) {
6
+ case 'gpt-5.1':
7
+ inputCost = 1.25;
8
+ outputCost = 10.00;
9
+ break;
6
10
  case 'gpt-5':
7
11
  inputCost = 1.25;
8
12
  outputCost = 10.00;
@@ -1,4 +1,4 @@
1
- export type ModelName = 'gpt-5' | 'gpt-5-mini' | 'gpt-5-nano' | 'gpt-4.1' | 'gpt-4.1-mini' | 'gpt-4.1-nano' | 'gpt-4o' | 'gpt-4o-mini' | 'o1' | 'o1-mini' | 'o3' | 'o3-mini' | 'o4-mini';
1
+ export type ModelName = 'gpt-5.1' | 'gpt-5' | 'gpt-5-mini' | 'gpt-5-nano' | 'gpt-4.1' | 'gpt-4.1-mini' | 'gpt-4.1-nano' | 'gpt-4o' | 'gpt-4o-mini' | 'o1' | 'o1-mini' | 'o3' | 'o3-mini' | 'o4-mini';
2
2
  export type ReasoningEffort = 'minimal' | 'low' | 'medium' | 'high';
3
3
  export type Verbosity = 'low' | 'medium' | 'high';
4
4
  export interface OpenAIModelOptions {
package/dist/util.d.ts CHANGED
@@ -10,3 +10,27 @@ export declare function getCurrentDayInMonth(timeZone?: string): number;
10
10
  export declare function getDaysInYear(timeZone?: string): 366 | 365;
11
11
  export declare function getCurrentMonth(timeZone?: string): number;
12
12
  export declare function getCurrentYear(timeZone?: string): number;
13
+ /**
14
+ * NOTE: `stopIdx` represents last character index of word
15
+ * ex: ABC -> `startIdx`: 0 `stopIdx`: 2
16
+ */
17
+ export interface QueryRegexMatch {
18
+ word: string;
19
+ startIdx: number;
20
+ stopIdx: number;
21
+ }
22
+ /**
23
+ * Will only **return** matches that **are not** contained in single quotes,
24
+ * double quotes, single line, or multiline comments.
25
+ */
26
+ export declare function getQueryMatches(query: string, regex: RegExp): QueryRegexMatch[];
27
+ /**
28
+ * Will only **remove** matches that **are not** contained in single quotes,
29
+ * double quotes, single line, or multiline comments.
30
+ */
31
+ export declare function removeQueryMatches(query: string, matches: QueryRegexMatch[]): string;
32
+ /**
33
+ * Will only **replace** matches that **are not** contained in single quotes,
34
+ * double quotes, single line, or multiline comments.
35
+ */
36
+ export declare function replaceQueryMatches(query: string, matches: QueryRegexMatch[], replacement: string): string;
package/dist/util.js CHANGED
@@ -1,3 +1,4 @@
1
+ // Miscellaneous --------------------------------------------------------------------------
1
2
  export async function sleep(ms) {
2
3
  return new Promise(resolve => setTimeout(resolve, ms));
3
4
  }
@@ -22,6 +23,7 @@ export function removePrefixIndicators(input, prefixes) {
22
23
  }
23
24
  return output;
24
25
  }
26
+ // Dates --------------------------------------------------------------------------
25
27
  export function initDate(timeZone) {
26
28
  const date = new Date();
27
29
  if (!!timeZone) {
@@ -70,3 +72,149 @@ export function getCurrentYear(timeZone) {
70
72
  let date = initDate(timeZone);
71
73
  return date.getFullYear();
72
74
  }
75
+ /**
76
+ * Will only **return** matches that **are not** contained in single quotes,
77
+ * double quotes, single line, or multiline comments.
78
+ */
79
+ export function getQueryMatches(query, regex) {
80
+ let matches = [];
81
+ // Find quote ranges first.
82
+ let singleQuoteRanges = [];
83
+ {
84
+ let open = false;
85
+ let startIdx = -1;
86
+ for (let i = 0; i < query.length; i++) {
87
+ if (query[i] === "'") {
88
+ if (open) {
89
+ singleQuoteRanges.push({ startIdx, stopIdx: i });
90
+ }
91
+ else {
92
+ startIdx = i;
93
+ }
94
+ open = !open;
95
+ }
96
+ }
97
+ }
98
+ let doubleQuoteRanges = [];
99
+ {
100
+ let open = false;
101
+ let startIdx = -1;
102
+ for (let i = 0; i < query.length; i++) {
103
+ if (query[i] === '"') {
104
+ if (open) {
105
+ doubleQuoteRanges.push({ startIdx, stopIdx: i });
106
+ }
107
+ else {
108
+ startIdx = i;
109
+ }
110
+ open = !open;
111
+ }
112
+ }
113
+ }
114
+ let singleLineCommentRanges = [];
115
+ {
116
+ let open = false;
117
+ let startIdx = -1;
118
+ for (let i = 0; i < query.length; i++) {
119
+ if (!open && query[i] === '-' && (i < query.length - 1 && query[i + 1] === '-')) {
120
+ open = true;
121
+ startIdx = i;
122
+ }
123
+ else if (open && (query[i] === '\n' || query[i] === '\r')) {
124
+ open = false;
125
+ singleLineCommentRanges.push({ startIdx, stopIdx: i });
126
+ }
127
+ }
128
+ }
129
+ let multilineCommentRanges = [];
130
+ {
131
+ let open = false;
132
+ let startIdx = -1;
133
+ for (let i = 0; i < query.length; i++) {
134
+ if (!open && query[i] === '/' && (i < query.length - 1 && query[i + 1] === '*')) {
135
+ open = true;
136
+ startIdx = i;
137
+ }
138
+ else if (open && query[i] === '/' && (i > 0 && query[i - 1] === '*')) {
139
+ open = false;
140
+ multilineCommentRanges.push({ startIdx, stopIdx: i });
141
+ }
142
+ }
143
+ }
144
+ // Now find matches and filter out the ones that are contained in quotes.
145
+ {
146
+ let match;
147
+ while ((match = regex.exec(query)) != null) {
148
+ let startIdx = match.index;
149
+ let stopIdx = match.index + match[0].length - 1;
150
+ let contained = false;
151
+ for (const quoteRange of singleQuoteRanges) {
152
+ if (quoteRange.startIdx <= startIdx && quoteRange.stopIdx >= stopIdx) {
153
+ contained = true;
154
+ break;
155
+ }
156
+ }
157
+ if (!contained) {
158
+ for (const quoteRange of doubleQuoteRanges) {
159
+ if (quoteRange.startIdx <= startIdx && quoteRange.stopIdx >= stopIdx) {
160
+ contained = true;
161
+ break;
162
+ }
163
+ }
164
+ }
165
+ if (!contained) {
166
+ for (const singleLineCommentRange of singleLineCommentRanges) {
167
+ if (singleLineCommentRange.startIdx <= startIdx && singleLineCommentRange.stopIdx >= stopIdx) {
168
+ contained = true;
169
+ break;
170
+ }
171
+ }
172
+ }
173
+ if (!contained) {
174
+ for (const multilineCommentRange of multilineCommentRanges) {
175
+ if (multilineCommentRange.startIdx <= startIdx && multilineCommentRange.stopIdx >= stopIdx) {
176
+ contained = true;
177
+ break;
178
+ }
179
+ }
180
+ }
181
+ if (!contained) {
182
+ matches.push({ word: match[0], startIdx, stopIdx });
183
+ }
184
+ }
185
+ }
186
+ return matches;
187
+ }
188
+ /**
189
+ * Will only **remove** matches that **are not** contained in single quotes,
190
+ * double quotes, single line, or multiline comments.
191
+ */
192
+ export function removeQueryMatches(query, matches) {
193
+ let adjQuery = query;
194
+ let offset = 0;
195
+ for (const match of matches) {
196
+ const start = match.startIdx - offset;
197
+ const stop = match.stopIdx + 1 - offset;
198
+ adjQuery = adjQuery.substring(0, start) + adjQuery.substring(stop);
199
+ offset += match.word.length;
200
+ }
201
+ return adjQuery;
202
+ }
203
+ /**
204
+ * Will only **replace** matches that **are not** contained in single quotes,
205
+ * double quotes, single line, or multiline comments.
206
+ */
207
+ export function replaceQueryMatches(query, matches, replacement) {
208
+ let adjQuery = query;
209
+ let offset = 0;
210
+ for (const match of matches) {
211
+ const start = match.startIdx - offset;
212
+ const stop = match.stopIdx + 1 - offset;
213
+ adjQuery =
214
+ adjQuery.substring(0, start) +
215
+ replacement +
216
+ adjQuery.substring(stop);
217
+ offset += (match.word.length - replacement.length);
218
+ }
219
+ return adjQuery;
220
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cellaware/utils",
3
- "version": "7.2.2",
3
+ "version": "7.2.4",
4
4
  "description": "Cellaware Utilities for Node.js",
5
5
  "author": "Cellaware Technologies",
6
6
  "type": "module",
File without changes
@@ -1 +0,0 @@
1
- "use strict";
File without changes
@@ -1 +0,0 @@
1
- "use strict";
File without changes
@@ -1 +0,0 @@
1
- "use strict";