@codebit-programando-solucoes/codebit-web 1.1.16 → 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/api/api.d.ts CHANGED
@@ -6,7 +6,7 @@ export interface RequestConfig {
6
6
  headers?: Record<string, string>;
7
7
  /** Request body data */
8
8
  data?: any;
9
- /** Request timeout in milliseconds */
9
+ /** Request timeout in milliseconds (defaults to 30000ms) */
10
10
  timeout?: number;
11
11
  /** AbortSignal for request cancellation */
12
12
  signal?: AbortSignal;
@@ -34,7 +34,7 @@ export interface StreamOptions extends RequestConfig {
34
34
  export interface ApiConfig {
35
35
  /** Base URL for API requests */
36
36
  baseURL?: string;
37
- /** Default timeout in milliseconds */
37
+ /** Default timeout in milliseconds (defaults to 30000ms) */
38
38
  timeout?: number;
39
39
  /** Default headers for all requests */
40
40
  headers?: Record<string, string>;
@@ -104,7 +104,10 @@ export class ApiNetworkError extends Error {
104
104
  constructor(error: Error);
105
105
  }
106
106
 
107
- /** API object that mimics Axios behavior using fetch. */
107
+ /**
108
+ * API object that mimics Axios behavior using fetch. Provides a familiar Axios-like interface while leveraging the modern fetch API under the hood. Includes features like
109
+ * request/response interceptors, automatic JSON parsing, and timeout handling.
110
+ */
108
111
  export declare const Api: {
109
112
  /**
110
113
  * Configures the API client globally with base URL, timeout, and default headers.
@@ -116,7 +119,7 @@ export declare const Api: {
116
119
  * headers: { 'X-App-Version': '1.0.0' },
117
120
  * });
118
121
  *
119
- * @param config - Configuration object
122
+ * @param config - Configuration object (timeout defaults to 30000ms)
120
123
  */
121
124
  configure(config: ApiConfig): void;
122
125
 
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
- fetchImageAsBlob: ()=>fetchImageAsBlob
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);
@@ -339,28 +356,28 @@ class Logger {
339
356
  static setDefaultLevel(level) {
340
357
  Logger._defaultLevel = level;
341
358
  }
342
- constructor(name, level = Logger._defaultLevel){
359
+ constructor(name, level = null){
343
360
  if (!name || 'string' != typeof name) throw new Error('Logger name must be a non-empty string.');
344
361
  this.name = name;
345
362
  this.level = level;
346
363
  }
347
364
  debug(...args) {
348
- if (this.level <= Logger.LOG_LEVELS.DEBUG) this._safeLog('debug', ...args);
365
+ if ((this.level ?? Logger._defaultLevel) <= Logger.LOG_LEVELS.DEBUG) this._safeLog('debug', ...args);
349
366
  }
350
367
  error(...args) {
351
- if (this.level <= Logger.LOG_LEVELS.ERROR) this._safeLog('error', ...args);
368
+ if ((this.level ?? Logger._defaultLevel) <= Logger.LOG_LEVELS.ERROR) this._safeLog('error', ...args);
352
369
  }
353
370
  info(...args) {
354
- if (this.level <= Logger.LOG_LEVELS.INFO) this._safeLog('info', ...args);
371
+ if ((this.level ?? Logger._defaultLevel) <= Logger.LOG_LEVELS.INFO) this._safeLog('info', ...args);
355
372
  }
356
373
  log(...args) {
357
374
  this._safeLog('log', ...args);
358
375
  }
359
376
  warn(...args) {
360
- if (this.level <= Logger.LOG_LEVELS.WARN) this._safeLog('warn', ...args);
377
+ if ((this.level ?? Logger._defaultLevel) <= Logger.LOG_LEVELS.WARN) this._safeLog('warn', ...args);
361
378
  }
362
379
  trace(...args) {
363
- if (this.level <= Logger.LOG_LEVELS.TRACE) this._safeLog('trace', ...args);
380
+ if ((this.level ?? Logger._defaultLevel) <= Logger.LOG_LEVELS.TRACE) this._safeLog('trace', ...args);
364
381
  }
365
382
  _safeLog(method, ...args) {
366
383
  const consoleMethod = console[method] || console.log;
@@ -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;
@@ -1,3 +1,4 @@
1
+ export * from './AdvancedPartialRegex';
1
2
  export * from './Clipboard';
2
3
  export * from './Image';
3
4
  export * from './Logger';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codebit-programando-solucoes/codebit-web",
3
- "version": "1.1.16",
3
+ "version": "1.1.18",
4
4
  "main": "./dist/index.cjs",
5
5
  "type": "module",
6
6
  "types": "./dist/index.d.ts",