@codebit-programando-solucoes/codebit-web 1.1.17 → 1.1.18
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/index.cjs +20 -1
- package/dist/util/AdvancedPartialRegex.d.ts +48 -0
- package/dist/util/index.d.ts +1 -0
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -24,6 +24,7 @@ var __webpack_require__ = {};
|
|
|
24
24
|
var __webpack_exports__ = {};
|
|
25
25
|
__webpack_require__.r(__webpack_exports__);
|
|
26
26
|
__webpack_require__.d(__webpack_exports__, {
|
|
27
|
+
fetchImageAsBlob: ()=>fetchImageAsBlob,
|
|
27
28
|
loadImage: ()=>loadImage,
|
|
28
29
|
markdownItBrEmptyLines: ()=>markdownItBrEmptyLines,
|
|
29
30
|
ErrorCode: ()=>ErrorCode,
|
|
@@ -32,7 +33,7 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
32
33
|
copyToClipboard: ()=>copyToClipboard,
|
|
33
34
|
Api: ()=>Api,
|
|
34
35
|
ApiError: ()=>ApiError,
|
|
35
|
-
|
|
36
|
+
createAdvancedPartialRegex: ()=>createAdvancedPartialRegex
|
|
36
37
|
});
|
|
37
38
|
class ApiError extends Error {
|
|
38
39
|
constructor(response, request = null){
|
|
@@ -287,6 +288,22 @@ const Api = {
|
|
|
287
288
|
}
|
|
288
289
|
}
|
|
289
290
|
};
|
|
291
|
+
function createAdvancedPartialRegex(target, options = {}) {
|
|
292
|
+
const { matchFromEnd = true, caseInsensitive = false, allowMultipleSpaces = false } = options;
|
|
293
|
+
const escapeRegex = (char)=>char.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
294
|
+
let pattern = '';
|
|
295
|
+
for(let i = target.length - 1; i >= 0; i--){
|
|
296
|
+
const char = target[i];
|
|
297
|
+
if (' ' === char && allowMultipleSpaces) pattern = '' === pattern ? '\\s+' : '\\s+(?:' + pattern + ')?';
|
|
298
|
+
else {
|
|
299
|
+
const escapedChar = escapeRegex(char);
|
|
300
|
+
pattern = '' === pattern ? escapedChar + '?' : escapedChar + '(?:' + pattern + ')?';
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
if (matchFromEnd) pattern += '\\s*$';
|
|
304
|
+
const flags = caseInsensitive ? 'i' : '';
|
|
305
|
+
return new RegExp(pattern, flags);
|
|
306
|
+
}
|
|
290
307
|
async function copyToClipboard(text) {
|
|
291
308
|
if (navigator?.clipboard && globalThis.isSecureContext) {
|
|
292
309
|
await navigator.clipboard.writeText(text);
|
|
@@ -396,6 +413,7 @@ exports.ApiNetworkError = __webpack_exports__.ApiNetworkError;
|
|
|
396
413
|
exports.ErrorCode = __webpack_exports__.ErrorCode;
|
|
397
414
|
exports.Logger = __webpack_exports__.Logger;
|
|
398
415
|
exports.copyToClipboard = __webpack_exports__.copyToClipboard;
|
|
416
|
+
exports.createAdvancedPartialRegex = __webpack_exports__.createAdvancedPartialRegex;
|
|
399
417
|
exports.fetchImageAsBlob = __webpack_exports__.fetchImageAsBlob;
|
|
400
418
|
exports.loadImage = __webpack_exports__.loadImage;
|
|
401
419
|
exports.markdownItBrEmptyLines = __webpack_exports__.markdownItBrEmptyLines;
|
|
@@ -406,6 +424,7 @@ for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
|
406
424
|
"ErrorCode",
|
|
407
425
|
"Logger",
|
|
408
426
|
"copyToClipboard",
|
|
427
|
+
"createAdvancedPartialRegex",
|
|
409
428
|
"fetchImageAsBlob",
|
|
410
429
|
"loadImage",
|
|
411
430
|
"markdownItBrEmptyLines"
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Options for creating an advanced partial regex pattern
|
|
3
|
+
*/
|
|
4
|
+
export interface AdvancedPartialRegexOptions {
|
|
5
|
+
/**
|
|
6
|
+
* Whether to match from the end of the string (default: true)
|
|
7
|
+
*/
|
|
8
|
+
matchFromEnd?: boolean;
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Whether to perform case-insensitive matching (default: false)
|
|
12
|
+
*/
|
|
13
|
+
caseInsensitive?: boolean;
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Whether to allow multiple spaces to match a single space (default: false)
|
|
17
|
+
*/
|
|
18
|
+
allowMultipleSpaces?: boolean;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Creates an advanced partial regex pattern that can match partial strings with flexible spacing.
|
|
23
|
+
*
|
|
24
|
+
* This function generates a regex pattern that can match partial strings with options for:
|
|
25
|
+
* - Matching from the end of the string
|
|
26
|
+
* - Case-insensitive matching
|
|
27
|
+
* - Allowing multiple spaces to match single spaces
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* ```ts
|
|
31
|
+
* // Create a regex that matches "hello world" with flexible spacing
|
|
32
|
+
* const regex = createAdvancedPartialRegex('hello world', { allowMultipleSpaces: true });
|
|
33
|
+
* console.log(regex.test('hello world')); // true
|
|
34
|
+
* console.log(regex.test('hello world')); // true
|
|
35
|
+
*
|
|
36
|
+
* // Create a case-insensitive regex
|
|
37
|
+
* const regex2 = createAdvancedPartialRegex('Hello', { caseInsensitive: true });
|
|
38
|
+
* console.log(regex2.test('hello')); // true
|
|
39
|
+
* ```
|
|
40
|
+
*
|
|
41
|
+
* @param target - The target string to create a partial regex for
|
|
42
|
+
* @param options - Configuration options for the regex generation
|
|
43
|
+
* @returns A RegExp object that matches partial strings according to the specified options
|
|
44
|
+
*/
|
|
45
|
+
export function createAdvancedPartialRegex(
|
|
46
|
+
target: string,
|
|
47
|
+
options?: AdvancedPartialRegexOptions
|
|
48
|
+
): RegExp;
|
package/dist/util/index.d.ts
CHANGED