@cellaware/utils 8.10.0 → 8.10.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.
- package/dist/util.d.ts +2 -2
- package/dist/util.js +9 -5
- package/package.json +1 -1
package/dist/util.d.ts
CHANGED
|
@@ -38,8 +38,8 @@ export interface QueryRegexMatch {
|
|
|
38
38
|
* Will only return matches that **are not** contained in single quotes,
|
|
39
39
|
* double quotes, single line, or multiline comments.
|
|
40
40
|
*/
|
|
41
|
-
export declare function getQueryMatches(query: string, regex: RegExp): QueryRegexMatch[];
|
|
41
|
+
export declare function getQueryMatches(query: string, regex: RegExp, specificMatchGroup?: number): QueryRegexMatch[];
|
|
42
42
|
export declare function removeQueryMatches(query: string, matches: QueryRegexMatch[]): string;
|
|
43
|
-
export declare function replaceQueryMatches(query: string, matches: QueryRegexMatch[], replacement: string): string;
|
|
43
|
+
export declare function replaceQueryMatches(query: string, matches: QueryRegexMatch[], replacement: string, useMatchAsSuffix?: boolean): string;
|
|
44
44
|
export declare function removeMarkdownIndicators(input: string): string;
|
|
45
45
|
export declare function removePrefixIndicators(input: string, prefixes: string[]): string;
|
package/dist/util.js
CHANGED
|
@@ -126,7 +126,7 @@ export function isDateString(value) {
|
|
|
126
126
|
* Will only return matches that **are not** contained in single quotes,
|
|
127
127
|
* double quotes, single line, or multiline comments.
|
|
128
128
|
*/
|
|
129
|
-
export function getQueryMatches(query, regex) {
|
|
129
|
+
export function getQueryMatches(query, regex, specificMatchGroup) {
|
|
130
130
|
let matches = [];
|
|
131
131
|
// Find quote ranges first.
|
|
132
132
|
let singleQuoteRanges = [];
|
|
@@ -229,7 +229,7 @@ export function getQueryMatches(query, regex) {
|
|
|
229
229
|
}
|
|
230
230
|
}
|
|
231
231
|
if (!contained) {
|
|
232
|
-
matches.push({ word: match[0], startIdx, stopIdx });
|
|
232
|
+
matches.push({ word: match[specificMatchGroup ?? 0], startIdx, stopIdx });
|
|
233
233
|
}
|
|
234
234
|
}
|
|
235
235
|
}
|
|
@@ -246,17 +246,21 @@ export function removeQueryMatches(query, matches) {
|
|
|
246
246
|
}
|
|
247
247
|
return adjQuery;
|
|
248
248
|
}
|
|
249
|
-
export function replaceQueryMatches(query, matches, replacement) {
|
|
249
|
+
export function replaceQueryMatches(query, matches, replacement, useMatchAsSuffix) {
|
|
250
250
|
let adjQuery = query;
|
|
251
251
|
let offset = 0;
|
|
252
252
|
for (const match of matches) {
|
|
253
253
|
const start = match.startIdx - offset;
|
|
254
254
|
const stop = match.stopIdx + 1 - offset;
|
|
255
|
+
let adjReplacement = replacement;
|
|
256
|
+
if (!!useMatchAsSuffix) {
|
|
257
|
+
adjReplacement = replacement + '_' + match.word;
|
|
258
|
+
}
|
|
255
259
|
adjQuery =
|
|
256
260
|
adjQuery.substring(0, start) +
|
|
257
|
-
|
|
261
|
+
adjReplacement +
|
|
258
262
|
adjQuery.substring(stop);
|
|
259
|
-
offset += (match.word.length -
|
|
263
|
+
offset += (match.word.length - adjReplacement.length);
|
|
260
264
|
}
|
|
261
265
|
return adjQuery;
|
|
262
266
|
}
|