@wgtechlabs/log-engine 2.2.2-pr.886b796 â 2.2.2-pr.cb278e2
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/README.md +203 -3
- package/dist/cjs/formatter/emoji-data.cjs +87 -0
- package/dist/cjs/formatter/emoji-data.d.ts +18 -0
- package/dist/cjs/formatter/emoji-data.d.ts.map +1 -0
- package/dist/cjs/formatter/emoji-data.js.map +1 -0
- package/dist/cjs/formatter/emoji-selector.cjs +216 -0
- package/dist/cjs/formatter/emoji-selector.d.ts +88 -0
- package/dist/cjs/formatter/emoji-selector.d.ts.map +1 -0
- package/dist/cjs/formatter/emoji-selector.js.map +1 -0
- package/dist/cjs/formatter/index.cjs +6 -1
- package/dist/cjs/formatter/index.d.ts +2 -0
- package/dist/cjs/formatter/index.d.ts.map +1 -1
- package/dist/cjs/formatter/index.js.map +1 -1
- package/dist/cjs/formatter/message-formatter.cjs +11 -2
- package/dist/cjs/formatter/message-formatter.d.ts.map +1 -1
- package/dist/cjs/formatter/message-formatter.js.map +1 -1
- package/dist/cjs/index.cjs +5 -1
- package/dist/cjs/index.d.ts +2 -1
- package/dist/cjs/index.d.ts.map +1 -1
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/logger/core.cjs +10 -0
- package/dist/cjs/logger/core.d.ts.map +1 -1
- package/dist/cjs/logger/core.js.map +1 -1
- package/dist/cjs/types/index.d.ts +29 -0
- package/dist/cjs/types/index.d.ts.map +1 -1
- package/dist/esm/formatter/emoji-data.d.ts +18 -0
- package/dist/esm/formatter/emoji-data.d.ts.map +1 -0
- package/dist/esm/formatter/emoji-data.js +84 -0
- package/dist/esm/formatter/emoji-data.js.map +1 -0
- package/dist/esm/formatter/emoji-selector.d.ts +88 -0
- package/dist/esm/formatter/emoji-selector.d.ts.map +1 -0
- package/dist/esm/formatter/emoji-selector.js +212 -0
- package/dist/esm/formatter/emoji-selector.js.map +1 -0
- package/dist/esm/formatter/index.d.ts +2 -0
- package/dist/esm/formatter/index.d.ts.map +1 -1
- package/dist/esm/formatter/index.js +2 -0
- package/dist/esm/formatter/index.js.map +1 -1
- package/dist/esm/formatter/message-formatter.d.ts.map +1 -1
- package/dist/esm/formatter/message-formatter.js +11 -2
- package/dist/esm/formatter/message-formatter.js.map +1 -1
- package/dist/esm/index.d.ts +2 -1
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +1 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/logger/core.d.ts.map +1 -1
- package/dist/esm/logger/core.js +11 -1
- package/dist/esm/logger/core.js.map +1 -1
- package/dist/esm/types/index.d.ts +29 -0
- package/dist/esm/types/index.d.ts.map +1 -1
- package/package.json +2 -3
package/README.md
CHANGED
|
@@ -16,6 +16,7 @@ Log Engine transforms your development experience from chaotic debugging session
|
|
|
16
16
|
|
|
17
17
|
## ⨠Key Features
|
|
18
18
|
|
|
19
|
+
- **đ¨ Context-Aware Emoji (New!)**: Intelligent emoji support that enhances log readability by analyzing content and automatically selecting relevant visual indicators - based on the gitmoji set with 40+ curated mappings and fully customizable.
|
|
19
20
|
- **đ Advanced Data Redaction (Enhanced!)**: Built-in PII protection with **custom regex patterns**, **dynamic field management**, and **environment-based configuration** - the first logging library with comprehensive security-first logging by default.
|
|
20
21
|
- **đ¯ Configurable Output Handlers (New!)**: Revolutionary output routing system supporting **custom destinations**, **multiple simultaneous outputs**, and **production-ready handlers** - redirect logs to files, HTTP endpoints, GUI applications, testing frameworks, or any custom destination with zero configuration complexity.
|
|
21
22
|
- **⥠Custom Redaction Patterns**: Add your own regex patterns for advanced field detection and enterprise-specific data protection requirements.
|
|
@@ -29,7 +30,6 @@ Log Engine transforms your development experience from chaotic debugging session
|
|
|
29
30
|
- **âī¸ Auto-Configuration**: Intelligent environment-based setup using NODE_ENV variables. No config files, initialization scripts, or manual setup - Log Engine works perfectly out of the box.
|
|
30
31
|
- **⨠Enhanced Formatting**: Structured log entries with dual timestamps (ISO + human-readable) and colored level indicators for maximum readability.
|
|
31
32
|
- **đ Zero Dependencies**: No external dependencies for maximum compatibility and security - keeps your bundle clean and your project simple.
|
|
32
|
-
- **đ Size Monitoring**: Automated bundle size checking ensures the package stays under 1MB to maintain its lightweight promise.
|
|
33
33
|
- **đ Easy Integration**: Simple API that works seamlessly with existing Node.js applications. Just `import` and start logging - no middleware, plugins, or configuration required.
|
|
34
34
|
|
|
35
35
|
## â ī¸ Breaking Changes Notice
|
|
@@ -414,6 +414,207 @@ LogEngine.error('Connection failed');
|
|
|
414
414
|
|
|
415
415
|
**Note**: Log levels (`[DEBUG]`, `[INFO]`, `[WARN]`, `[ERROR]`, `[LOG]`) are always included regardless of configuration to maintain log clarity and filtering capabilities.
|
|
416
416
|
|
|
417
|
+
## đ¨ Context-Aware Emoji Support
|
|
418
|
+
|
|
419
|
+
**LogEngine features intelligent emoji support that enhances log readability by adding visual context to each log message.** The emoji engine analyzes your log content (level + message + data) and automatically selects the most relevant emoji, making it easier to visually parse large logs and instantly identify the type of each log line.
|
|
420
|
+
|
|
421
|
+
### Features
|
|
422
|
+
|
|
423
|
+
- **đ¯ Context-Aware Selection**: Automatically analyzes message content and data to select appropriate emoji
|
|
424
|
+
- **đĻ Rich Emoji Set**: Based on [gitmoji](https://gitmoji.dev) with 40+ curated emoji mappings
|
|
425
|
+
- **đ Smart Fallback**: Uses level-specific emoji when no context match is found
|
|
426
|
+
- **đ ī¸ Fully Customizable**: Extend or override emoji mappings and fallback behavior
|
|
427
|
+
- **â
Enabled by Default**: Emoji are automatically included in logs (can be disabled via `includeEmoji: false`)
|
|
428
|
+
|
|
429
|
+
### Quick Start
|
|
430
|
+
|
|
431
|
+
```typescript
|
|
432
|
+
import { LogEngine } from '@wgtechlabs/log-engine';
|
|
433
|
+
|
|
434
|
+
// Emoji are enabled by default - just start logging!
|
|
435
|
+
LogEngine.error('Database connection failed');
|
|
436
|
+
// Output: [2026-02-11T14:00:00.000Z][2:00PM][ERROR][đī¸]: Database connection failed
|
|
437
|
+
|
|
438
|
+
LogEngine.info('Deployed to production successfully');
|
|
439
|
+
// Output: [2026-02-11T14:00:01.000Z][2:00PM][INFO][đ]: Deployed to production successfully
|
|
440
|
+
|
|
441
|
+
LogEngine.warn('Performance degradation detected');
|
|
442
|
+
// Output: [2026-02-11T14:00:02.000Z][2:00PM][WARN][âĄī¸]: Performance degradation detected
|
|
443
|
+
|
|
444
|
+
LogEngine.info('Unknown event happened');
|
|
445
|
+
// Output: [2026-02-11T14:00:03.000Z][2:00PM][INFO][âšī¸]: Unknown event happened (fallback)
|
|
446
|
+
|
|
447
|
+
// Disable emoji if needed
|
|
448
|
+
LogEngine.configure({
|
|
449
|
+
format: {
|
|
450
|
+
includeEmoji: false
|
|
451
|
+
}
|
|
452
|
+
});
|
|
453
|
+
```
|
|
454
|
+
|
|
455
|
+
### Context-Aware Emoji Mappings
|
|
456
|
+
|
|
457
|
+
LogEngine intelligently matches keywords in your log messages to select appropriate emoji:
|
|
458
|
+
|
|
459
|
+
| Context | Keywords | Emoji | Example |
|
|
460
|
+
|---------|----------|-------|---------|
|
|
461
|
+
| **Database** | database, db, sql, query, mongo, postgres | đī¸ | "Database query failed" |
|
|
462
|
+
| **Deployment** | deploy, release, launched, production | đ | "Deployed to production" |
|
|
463
|
+
| **Performance** | performance, speed, optimize, latency | âĄī¸ | "Performance issues detected" |
|
|
464
|
+
| **Security** | security, vulnerability, auth, permission | đī¸ | "Security breach detected" |
|
|
465
|
+
| **Critical** | critical, urgent, emergency, crash | đī¸ | "Critical system failure" |
|
|
466
|
+
| **Bugs** | bug, fix, defect, issue | đ | "Fixed bug in login" |
|
|
467
|
+
| **Network** | network, http, api, endpoint | đ | "API request failed" |
|
|
468
|
+
| **Testing** | tests, testing, validation | â
| "All tests passed" |
|
|
469
|
+
|
|
470
|
+
### Fallback Emoji by Level
|
|
471
|
+
|
|
472
|
+
When no context-specific emoji matches, LogEngine uses these fallback emoji:
|
|
473
|
+
|
|
474
|
+
| Log Level | Emoji | Description |
|
|
475
|
+
|-----------|-------|-------------|
|
|
476
|
+
| `DEBUG` | đ | Debugging information |
|
|
477
|
+
| `INFO` | âšī¸ | General information |
|
|
478
|
+
| `WARN` | â ī¸ | Warning messages |
|
|
479
|
+
| `ERROR` | â | Error messages |
|
|
480
|
+
| `LOG` | â
| Critical log messages |
|
|
481
|
+
|
|
482
|
+
### Custom Emoji Configuration
|
|
483
|
+
|
|
484
|
+
#### Custom Context Mappings
|
|
485
|
+
|
|
486
|
+
Add your own emoji mappings for custom contexts:
|
|
487
|
+
|
|
488
|
+
```typescript
|
|
489
|
+
LogEngine.configure({
|
|
490
|
+
format: {
|
|
491
|
+
emoji: {
|
|
492
|
+
customMappings: [
|
|
493
|
+
{
|
|
494
|
+
emoji: 'đ¯',
|
|
495
|
+
code: ':dart:',
|
|
496
|
+
description: 'Goal achieved',
|
|
497
|
+
keywords: ['goal', 'target', 'achieved', 'milestone']
|
|
498
|
+
},
|
|
499
|
+
{
|
|
500
|
+
emoji: 'đ°',
|
|
501
|
+
code: ':moneybag:',
|
|
502
|
+
description: 'Payment operations',
|
|
503
|
+
keywords: ['payment', 'transaction', 'billing', 'invoice']
|
|
504
|
+
}
|
|
505
|
+
]
|
|
506
|
+
}
|
|
507
|
+
}
|
|
508
|
+
});
|
|
509
|
+
|
|
510
|
+
LogEngine.info('Payment processed successfully');
|
|
511
|
+
// Output: [INFO][đ°]: Payment processed successfully
|
|
512
|
+
|
|
513
|
+
LogEngine.info('Sales target achieved');
|
|
514
|
+
// Output: [INFO][đ¯]: Sales target achieved
|
|
515
|
+
```
|
|
516
|
+
|
|
517
|
+
#### Custom Fallback Emoji
|
|
518
|
+
|
|
519
|
+
Override the default fallback emoji for each log level:
|
|
520
|
+
|
|
521
|
+
```typescript
|
|
522
|
+
LogEngine.configure({
|
|
523
|
+
format: {
|
|
524
|
+
emoji: {
|
|
525
|
+
customFallbacks: {
|
|
526
|
+
DEBUG: 'đ',
|
|
527
|
+
INFO: 'đĸ',
|
|
528
|
+
WARN: 'đ¨',
|
|
529
|
+
ERROR: 'đ',
|
|
530
|
+
LOG: 'đ'
|
|
531
|
+
}
|
|
532
|
+
}
|
|
533
|
+
}
|
|
534
|
+
});
|
|
535
|
+
|
|
536
|
+
LogEngine.info('Generic info message');
|
|
537
|
+
// Output: [INFO][đĸ]: Generic info message
|
|
538
|
+
```
|
|
539
|
+
|
|
540
|
+
#### Use Custom Mappings Exclusively
|
|
541
|
+
|
|
542
|
+
Use only your custom mappings and ignore the built-in set:
|
|
543
|
+
|
|
544
|
+
```typescript
|
|
545
|
+
LogEngine.configure({
|
|
546
|
+
format: {
|
|
547
|
+
emoji: {
|
|
548
|
+
useCustomOnly: true,
|
|
549
|
+
customMappings: [
|
|
550
|
+
// Your custom mappings only
|
|
551
|
+
]
|
|
552
|
+
}
|
|
553
|
+
}
|
|
554
|
+
});
|
|
555
|
+
```
|
|
556
|
+
|
|
557
|
+
### Data Context Analysis
|
|
558
|
+
|
|
559
|
+
The emoji selector also analyzes data objects for context:
|
|
560
|
+
|
|
561
|
+
```typescript
|
|
562
|
+
LogEngine.info('Operation completed', {
|
|
563
|
+
database: 'postgres',
|
|
564
|
+
table: 'users',
|
|
565
|
+
rows: 1000
|
|
566
|
+
});
|
|
567
|
+
// Output: [INFO][đī¸]: Operation completed { database: 'postgres', ... }
|
|
568
|
+
|
|
569
|
+
LogEngine.warn('Issue detected', {
|
|
570
|
+
performance: 'degraded',
|
|
571
|
+
latency: '500ms'
|
|
572
|
+
});
|
|
573
|
+
// Output: [WARN][âĄī¸]: Issue detected { performance: 'degraded', ... }
|
|
574
|
+
```
|
|
575
|
+
|
|
576
|
+
### Programmatic Access
|
|
577
|
+
|
|
578
|
+
Access emoji utilities directly for advanced use cases:
|
|
579
|
+
|
|
580
|
+
```typescript
|
|
581
|
+
import { EmojiSelector, EMOJI_MAPPINGS, FALLBACK_EMOJI } from '@wgtechlabs/log-engine';
|
|
582
|
+
|
|
583
|
+
// Check all available emoji mappings
|
|
584
|
+
console.log(EMOJI_MAPPINGS);
|
|
585
|
+
// [{ emoji: 'đ', code: ':bug:', description: 'Fix a bug', keywords: [...] }, ...]
|
|
586
|
+
|
|
587
|
+
// Check fallback emoji
|
|
588
|
+
console.log(FALLBACK_EMOJI);
|
|
589
|
+
// { DEBUG: 'đ', INFO: 'âšī¸', WARN: 'â ī¸', ERROR: 'â', LOG: 'â
' }
|
|
590
|
+
|
|
591
|
+
// Configure emoji selector directly (for customization)
|
|
592
|
+
EmojiSelector.configure({
|
|
593
|
+
customMappings: [...]
|
|
594
|
+
});
|
|
595
|
+
```
|
|
596
|
+
|
|
597
|
+
### Output Format
|
|
598
|
+
|
|
599
|
+
With emoji (enabled by default), the log format is:
|
|
600
|
+
|
|
601
|
+
```
|
|
602
|
+
[ISO_TIMESTAMP][LOCAL_TIME][LEVEL][EMOJI]: message [data]
|
|
603
|
+
```
|
|
604
|
+
|
|
605
|
+
Example:
|
|
606
|
+
```
|
|
607
|
+
[2026-02-11T14:00:00.000Z][2:00PM][ERROR][đī¸]: Database connection failed
|
|
608
|
+
```
|
|
609
|
+
|
|
610
|
+
### Benefits
|
|
611
|
+
|
|
612
|
+
- **đī¸ Visual Clarity**: Instantly identify log context at a glance
|
|
613
|
+
- **đ¯ Better Debugging**: Quickly locate specific types of logs in large outputs
|
|
614
|
+
- **đ¨ Enhanced UX**: More engaging and pleasant logging experience
|
|
615
|
+
- **đ§ Flexible**: Fully customizable to match your project's needs
|
|
616
|
+
- **đ Compatibility Note**: Enabled by default â existing log output will include emojis; disable or customize emoji behavior via configuration to preserve prior formats
|
|
617
|
+
|
|
417
618
|
## đ Advanced Data Redaction
|
|
418
619
|
|
|
419
620
|
**LogEngine features comprehensive built-in PII protection with advanced customization capabilities that automatically redacts sensitive information from your logs.** This security-first approach prevents accidental exposure of passwords, tokens, emails, and other sensitive data while maintaining full debugging capabilities with enterprise-grade flexibility.
|
|
@@ -902,8 +1103,7 @@ Contributions are welcome, create a pull request to this repo and I will review
|
|
|
902
1103
|
- `pnpm lint:security` - Run security-focused linting
|
|
903
1104
|
- `pnpm secure` - Run comprehensive security checks
|
|
904
1105
|
- `pnpm build` - Build the TypeScript project
|
|
905
|
-
- `pnpm
|
|
906
|
-
- `pnpm validate` - Run full validation (lint + test + build + size check)
|
|
1106
|
+
- `pnpm validate` - Run full validation (lint + test + build)
|
|
907
1107
|
|
|
908
1108
|
Read the project's [contributing guide](./CONTRIBUTING.md) for detailed development setup, testing guidelines, and contribution requirements.
|
|
909
1109
|
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Emoji data for context-aware logging
|
|
4
|
+
* Based on gitmoji.dev emoji set
|
|
5
|
+
* Each entry maps emoji to keywords that help identify when to use it
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.FALLBACK_EMOJI = exports.EMOJI_MAPPINGS = void 0;
|
|
9
|
+
/**
|
|
10
|
+
* Curated emoji mappings for context-aware logging
|
|
11
|
+
* Based on the gitmoji set from https://gitmoji.dev
|
|
12
|
+
* Ordered by specificity - more specific keywords first
|
|
13
|
+
*/
|
|
14
|
+
exports.EMOJI_MAPPINGS = [
|
|
15
|
+
// More specific contexts first
|
|
16
|
+
// Database (specific)
|
|
17
|
+
{ emoji: 'đī¸', code: ':card_file_box:', description: 'Database related', keywords: ['database', 'db', 'sql', 'query', 'table', 'schema', 'migration', 'mongo', 'postgres', 'mysql'] },
|
|
18
|
+
// Deployment and releases (specific)
|
|
19
|
+
{ emoji: 'đ', code: ':rocket:', description: 'Deploy or release', keywords: ['deploy', 'deployed', 'deployment', 'release', 'launched', 'production'] },
|
|
20
|
+
// Performance (specific)
|
|
21
|
+
{ emoji: 'âĄī¸', code: ':zap:', description: 'Improve performance', keywords: ['performance', 'speed', 'optimize', 'fast', 'slow', 'latency', 'throughput'] },
|
|
22
|
+
// Security (specific)
|
|
23
|
+
{ emoji: 'đī¸', code: ':lock:', description: 'Fix security issues', keywords: ['security', 'secure', 'vulnerability', 'exploit', 'auth', 'authentication', 'authorization', 'permission'] },
|
|
24
|
+
// Critical issues (specific)
|
|
25
|
+
{ emoji: 'đī¸', code: ':ambulance:', description: 'Critical hotfix', keywords: ['critical', 'hotfix', 'urgent', 'emergency', 'crash', 'fatal'] },
|
|
26
|
+
// Bugs and fixes (specific)
|
|
27
|
+
{ emoji: 'đ', code: ':bug:', description: 'Fix a bug', keywords: ['bug', 'fix', 'fixed', 'fixing', 'defect', 'issue'] },
|
|
28
|
+
// Less specific/generic contexts last
|
|
29
|
+
// Errors and failures (generic)
|
|
30
|
+
{ emoji: 'â', code: ':x:', description: 'Error or failure', keywords: ['error', 'fail', 'failed', 'failure', 'exception', 'reject'] },
|
|
31
|
+
{ emoji: 'đĨ', code: ':fire:', description: 'Remove code or files', keywords: ['remove', 'delete', 'deprecated', 'obsolete'] },
|
|
32
|
+
{ emoji: 'đ', code: ':snail:', description: 'Slow performance', keywords: ['timeout', 'hang', 'freeze'] },
|
|
33
|
+
{ emoji: 'đī¸', code: ':unlock:', description: 'Unlock or access', keywords: ['unlock', 'access', 'grant', 'allow'] },
|
|
34
|
+
{ emoji: 'đž', code: ':floppy_disk:', description: 'Save or persist data', keywords: ['save', 'saved', 'saving', 'persist', 'write', 'store'] },
|
|
35
|
+
{ emoji: 'đ', code: ':tada:', description: 'Initial commit or milestone', keywords: ['initial', 'milestone', 'celebrate', 'success', 'complete'] },
|
|
36
|
+
// Configuration
|
|
37
|
+
{ emoji: 'đ§', code: ':wrench:', description: 'Configuration changes', keywords: ['config', 'configuration', 'setting', 'settings', 'configure'] },
|
|
38
|
+
{ emoji: 'âī¸', code: ':gear:', description: 'Configuration or settings', keywords: ['setup', 'init', 'initialize'] },
|
|
39
|
+
// API and network
|
|
40
|
+
{ emoji: 'đ', code: ':globe_with_meridians:', description: 'Network or internet', keywords: ['network', 'internet', 'http', 'https', 'request', 'response', 'api', 'endpoint'] },
|
|
41
|
+
{ emoji: 'đ', code: ':electric_plug:', description: 'Connection or plugin', keywords: ['connect', 'connection', 'disconnect', 'plugin', 'integration'] },
|
|
42
|
+
// Testing
|
|
43
|
+
{ emoji: 'â
', code: ':white_check_mark:', description: 'Tests passing', keywords: ['tests', 'testing', 'pass', 'passed', 'validation', 'validate'] },
|
|
44
|
+
{ emoji: 'đ§Ē', code: ':test_tube:', description: 'Running tests', keywords: ['experiment', 'trial', 'spec'] },
|
|
45
|
+
// Documentation
|
|
46
|
+
{ emoji: 'đ', code: ':memo:', description: 'Add or update documentation', keywords: ['document', 'documentation', 'docs', 'readme', 'comment'] },
|
|
47
|
+
{ emoji: 'đĄ', code: ':bulb:', description: 'New idea or insight', keywords: ['idea', 'insight', 'suggestion', 'tip', 'hint'] },
|
|
48
|
+
// Dependencies
|
|
49
|
+
{ emoji: 'â', code: ':heavy_plus_sign:', description: 'Add dependency', keywords: ['add', 'added', 'adding', 'install', 'dependency', 'package'] },
|
|
50
|
+
{ emoji: 'â', code: ':heavy_minus_sign:', description: 'Remove dependency', keywords: ['uninstall', 'removed'] },
|
|
51
|
+
{ emoji: 'âŦī¸', code: ':arrow_up:', description: 'Upgrade dependencies', keywords: ['upgrade', 'update', 'updated'] },
|
|
52
|
+
{ emoji: 'âŦī¸', code: ':arrow_down:', description: 'Downgrade dependencies', keywords: ['downgrade', 'rollback'] },
|
|
53
|
+
// Files and structure
|
|
54
|
+
{ emoji: 'đĻ', code: ':package:', description: 'Update compiled files', keywords: ['package', 'build', 'compile', 'bundle'] },
|
|
55
|
+
{ emoji: 'đ', code: ':truck:', description: 'Move or rename files', keywords: ['move', 'moved', 'rename', 'renamed', 'relocate'] },
|
|
56
|
+
// Work in progress
|
|
57
|
+
{ emoji: 'đ§', code: ':construction:', description: 'Work in progress', keywords: ['wip', 'progress', 'working', 'ongoing', 'incomplete'] },
|
|
58
|
+
// Breaking changes
|
|
59
|
+
{ emoji: 'đĨ', code: ':boom:', description: 'Breaking changes', keywords: ['breaking', 'break', 'incompatible'] },
|
|
60
|
+
// Accessibility
|
|
61
|
+
{ emoji: 'âŋī¸', code: ':wheelchair:', description: 'Improve accessibility', keywords: ['accessibility', 'a11y', 'accessible'] },
|
|
62
|
+
// Internationalization
|
|
63
|
+
{ emoji: 'đ', code: ':earth_africa:', description: 'Internationalization', keywords: ['i18n', 'localization', 'l10n', 'translation', 'language'] },
|
|
64
|
+
// UI and styling
|
|
65
|
+
{ emoji: 'đ', code: ':lipstick:', description: 'Update UI and style', keywords: ['ui', 'style', 'css', 'design', 'interface', 'layout'] },
|
|
66
|
+
{ emoji: 'đ¨', code: ':art:', description: 'Improve structure', keywords: ['refactor', 'refactoring', 'restructure', 'format'] },
|
|
67
|
+
// Logging and monitoring
|
|
68
|
+
{ emoji: 'đ', code: ':loud_sound:', description: 'Add or update logs', keywords: ['logging', 'trace'] },
|
|
69
|
+
{ emoji: 'đ', code: ':mute:', description: 'Remove logs', keywords: ['silent', 'quiet', 'mute'] },
|
|
70
|
+
{ emoji: 'đ', code: ':bar_chart:', description: 'Analytics or metrics', keywords: ['analytics', 'metrics', 'stats', 'statistics', 'monitor', 'monitoring'] },
|
|
71
|
+
// Code review
|
|
72
|
+
{ emoji: 'đ', code: ':ok_hand:', description: 'Code review changes', keywords: ['review', 'approve', 'approved', 'lgtm'] },
|
|
73
|
+
// Catch-all for new features (put last)
|
|
74
|
+
{ emoji: 'â¨', code: ':sparkles:', description: 'New feature', keywords: ['feature', 'new', 'enhancement', 'improve', 'improved'] },
|
|
75
|
+
];
|
|
76
|
+
/**
|
|
77
|
+
* Default fallback emoji for each log level
|
|
78
|
+
* These are used when no context-specific emoji matches
|
|
79
|
+
*/
|
|
80
|
+
exports.FALLBACK_EMOJI = {
|
|
81
|
+
DEBUG: 'đ',
|
|
82
|
+
INFO: 'âšī¸',
|
|
83
|
+
WARN: 'â ī¸',
|
|
84
|
+
ERROR: 'â',
|
|
85
|
+
LOG: 'â
'
|
|
86
|
+
};
|
|
87
|
+
//# sourceMappingURL=emoji-data.js.map
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Emoji data for context-aware logging
|
|
3
|
+
* Based on gitmoji.dev emoji set
|
|
4
|
+
* Each entry maps emoji to keywords that help identify when to use it
|
|
5
|
+
*/
|
|
6
|
+
import { EmojiMapping } from '../types';
|
|
7
|
+
/**
|
|
8
|
+
* Curated emoji mappings for context-aware logging
|
|
9
|
+
* Based on the gitmoji set from https://gitmoji.dev
|
|
10
|
+
* Ordered by specificity - more specific keywords first
|
|
11
|
+
*/
|
|
12
|
+
export declare const EMOJI_MAPPINGS: EmojiMapping[];
|
|
13
|
+
/**
|
|
14
|
+
* Default fallback emoji for each log level
|
|
15
|
+
* These are used when no context-specific emoji matches
|
|
16
|
+
*/
|
|
17
|
+
export declare const FALLBACK_EMOJI: Record<'DEBUG' | 'INFO' | 'WARN' | 'ERROR' | 'LOG', string>;
|
|
18
|
+
//# sourceMappingURL=emoji-data.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"emoji-data.d.ts","sourceRoot":"","sources":["../../../src/formatter/emoji-data.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAExC;;;;GAIG;AACH,eAAO,MAAM,cAAc,EAAE,YAAY,EAsFxC,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,cAAc,EAAE,MAAM,CAAC,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,KAAK,EAAE,MAAM,CAMtF,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"emoji-data.js","sourceRoot":"","sources":["../../../src/formatter/emoji-data.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;;AAIH;;;;GAIG;AACU,QAAA,cAAc,GAAmB;IAC5C,+BAA+B;IAE/B,sBAAsB;IACtB,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,iBA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BAAsB,EAAE,QAAQ,EAAE,CAAC,WAAW,EAAE,SAAS,EAAE,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,YAAY,CAAC,EAAE;IAE7J,cAAc;IACd,EAAE,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE,WAAW,EAAE,WAAW,EAAE,qBAAqB,EAAE,QAAQ,EAAE,CAAC,QAAQ,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,CAAC,EAAE;IAE3H,wCAAwC;IACxC,EAAE,KAAK,EAAE,GAAG,EAAE,IAAI,EAAE,YAAY,EAAE,WAAW,EAAE,aAAa,EAAE,QAAQ,EAAE,CAAC,SAAS,EAAE,KAAK,EAAE,aAAa,EAAE,SAAS,EAAE,UAAU,CAAC,EAAE;CACnI,CAAC;AAEF;;;GAGG;AACU,QAAA,cAAc,GAAgE;IACzF,KAAK,EAAE,IAAI;IACX,IAAI,EAAE,IAAI;IACV,IAAI,EAAE,IAAI;IACV,KAAK,EAAE,GAAG;IACV,GAAG,EAAE,GAAG;CACT,CAAC"}
|
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Emoji selector for context-aware logging
|
|
4
|
+
* Analyzes log messages to select appropriate emoji based on context
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.EmojiSelector = void 0;
|
|
8
|
+
const types_1 = require("../types/index.cjs");
|
|
9
|
+
const emoji_data_1 = require("./emoji-data.cjs");
|
|
10
|
+
/**
|
|
11
|
+
* Emoji selector class
|
|
12
|
+
* Provides context-aware emoji selection for log messages
|
|
13
|
+
*/
|
|
14
|
+
class EmojiSelector {
|
|
15
|
+
/**
|
|
16
|
+
* Configure the emoji selector
|
|
17
|
+
* @param config - Configuration options
|
|
18
|
+
*/
|
|
19
|
+
static configure(config) {
|
|
20
|
+
EmojiSelector.config = {
|
|
21
|
+
...EmojiSelector.config,
|
|
22
|
+
...config
|
|
23
|
+
};
|
|
24
|
+
// Invalidate compiled cache when config changes
|
|
25
|
+
EmojiSelector.compiledMappings = null;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Get current configuration
|
|
29
|
+
* @returns Current emoji configuration
|
|
30
|
+
*/
|
|
31
|
+
static getConfig() {
|
|
32
|
+
const { customMappings = [], customFallbacks = {}, ...rest } = EmojiSelector.config;
|
|
33
|
+
return {
|
|
34
|
+
...rest,
|
|
35
|
+
customMappings: [...customMappings],
|
|
36
|
+
customFallbacks: { ...customFallbacks }
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Reset configuration to defaults
|
|
41
|
+
*/
|
|
42
|
+
static reset() {
|
|
43
|
+
EmojiSelector.config = {
|
|
44
|
+
customMappings: [],
|
|
45
|
+
customFallbacks: {},
|
|
46
|
+
useCustomOnly: false
|
|
47
|
+
};
|
|
48
|
+
// Clear compiled cache
|
|
49
|
+
EmojiSelector.compiledMappings = null;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Get compiled emoji mappings with precompiled regex patterns
|
|
53
|
+
* This is cached to avoid recompiling regex on every log line
|
|
54
|
+
*/
|
|
55
|
+
static getCompiledMappings() {
|
|
56
|
+
if (EmojiSelector.compiledMappings) {
|
|
57
|
+
return EmojiSelector.compiledMappings;
|
|
58
|
+
}
|
|
59
|
+
const { customMappings = [], useCustomOnly } = EmojiSelector.config;
|
|
60
|
+
const mappings = useCustomOnly ? customMappings : [...customMappings, ...emoji_data_1.EMOJI_MAPPINGS];
|
|
61
|
+
EmojiSelector.compiledMappings = mappings.map(mapping => ({
|
|
62
|
+
...mapping,
|
|
63
|
+
regexes: mapping.keywords.map(keyword => {
|
|
64
|
+
// Escape regex metacharacters to prevent ReDoS and invalid patterns
|
|
65
|
+
const escapedKeyword = keyword.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
66
|
+
// Precompile regex for performance
|
|
67
|
+
return new RegExp(`\\b${escapedKeyword}\\b`, 'i');
|
|
68
|
+
})
|
|
69
|
+
}));
|
|
70
|
+
return EmojiSelector.compiledMappings;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Select appropriate emoji based on log level and message content
|
|
74
|
+
* @param level - Log level
|
|
75
|
+
* @param message - Log message
|
|
76
|
+
* @param data - Optional log data
|
|
77
|
+
* @returns Selected emoji or empty string
|
|
78
|
+
*/
|
|
79
|
+
static selectEmoji(level, message, data) {
|
|
80
|
+
// Try to find context-aware emoji
|
|
81
|
+
const contextEmoji = EmojiSelector.findContextEmoji(message, data);
|
|
82
|
+
if (contextEmoji) {
|
|
83
|
+
return contextEmoji;
|
|
84
|
+
}
|
|
85
|
+
// Fall back to level-based emoji
|
|
86
|
+
return EmojiSelector.getFallbackEmoji(level);
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Find emoji based on message and data context
|
|
90
|
+
* @param message - Log message
|
|
91
|
+
* @param data - Optional log data
|
|
92
|
+
* @returns Emoji if match found, null otherwise
|
|
93
|
+
*/
|
|
94
|
+
static findContextEmoji(message, data) {
|
|
95
|
+
const searchText = EmojiSelector.prepareSearchText(message, data);
|
|
96
|
+
const compiledMappings = EmojiSelector.getCompiledMappings();
|
|
97
|
+
// Search through compiled mappings for keyword matches
|
|
98
|
+
for (const mapping of compiledMappings) {
|
|
99
|
+
if (EmojiSelector.matchesWithCompiledRegexes(searchText, mapping.regexes)) {
|
|
100
|
+
return mapping.emoji;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
return null;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Get combined mappings (custom + default or custom only)
|
|
107
|
+
* @returns Array of emoji mappings
|
|
108
|
+
* @deprecated Use getCompiledMappings() for better performance
|
|
109
|
+
*/
|
|
110
|
+
static getMappings() {
|
|
111
|
+
const { customMappings = [], useCustomOnly = false } = EmojiSelector.config;
|
|
112
|
+
if (useCustomOnly) {
|
|
113
|
+
return customMappings;
|
|
114
|
+
}
|
|
115
|
+
// Merge custom mappings first (higher priority) with defaults
|
|
116
|
+
return [...customMappings, ...emoji_data_1.EMOJI_MAPPINGS];
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Prepare text for searching by combining message and data
|
|
120
|
+
* @param message - Log message
|
|
121
|
+
* @param data - Optional log data
|
|
122
|
+
* @returns Lowercase combined text
|
|
123
|
+
*/
|
|
124
|
+
static prepareSearchText(message, data) {
|
|
125
|
+
let text = message.toLowerCase();
|
|
126
|
+
// If data is provided and is an object, include its keys and string values
|
|
127
|
+
if (data && typeof data === 'object') {
|
|
128
|
+
try {
|
|
129
|
+
const dataStr = JSON.stringify(data).toLowerCase();
|
|
130
|
+
text += ' ' + dataStr;
|
|
131
|
+
}
|
|
132
|
+
catch {
|
|
133
|
+
// Ignore circular references or stringify errors
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
else if (data && typeof data === 'string') {
|
|
137
|
+
text += ' ' + data.toLowerCase();
|
|
138
|
+
}
|
|
139
|
+
return text;
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Check if search text matches any of the precompiled regexes
|
|
143
|
+
* @param searchText - Lowercase text to search in
|
|
144
|
+
* @param regexes - Precompiled regex patterns
|
|
145
|
+
* @returns true if any regex matches
|
|
146
|
+
*/
|
|
147
|
+
static matchesWithCompiledRegexes(searchText, regexes) {
|
|
148
|
+
return regexes.some(regex => regex.test(searchText));
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Check if search text matches any of the keywords
|
|
152
|
+
* @param searchText - Lowercase text to search in
|
|
153
|
+
* @param keywords - Keywords to look for
|
|
154
|
+
* @returns true if any keyword matches
|
|
155
|
+
* @deprecated Use matchesWithCompiledRegexes() for better performance
|
|
156
|
+
*/
|
|
157
|
+
static matchesKeywords(searchText, keywords) {
|
|
158
|
+
return keywords.some(keyword => {
|
|
159
|
+
// Escape regex metacharacters to prevent ReDoS and invalid patterns
|
|
160
|
+
const escapedKeyword = keyword.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
161
|
+
// Use word boundary matching for more accurate results
|
|
162
|
+
// Safe: escapedKeyword is sanitized by regex escape above
|
|
163
|
+
// eslint-disable-next-line security/detect-non-literal-regexp
|
|
164
|
+
const regex = new RegExp(`\\b${escapedKeyword}\\b`, 'i');
|
|
165
|
+
return regex.test(searchText);
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Get fallback emoji for a given log level
|
|
170
|
+
* @param level - Log level
|
|
171
|
+
* @returns Fallback emoji for the level
|
|
172
|
+
*/
|
|
173
|
+
static getFallbackEmoji(level) {
|
|
174
|
+
const levelName = EmojiSelector.getLevelName(level);
|
|
175
|
+
// Explicitly handle unknown levels: no emoji by default
|
|
176
|
+
if (levelName === 'UNKNOWN') {
|
|
177
|
+
return '';
|
|
178
|
+
}
|
|
179
|
+
const { customFallbacks = {} } = EmojiSelector.config;
|
|
180
|
+
// Check custom fallbacks first
|
|
181
|
+
// Safe: levelName is constrained to specific log level strings
|
|
182
|
+
// eslint-disable-next-line security/detect-object-injection
|
|
183
|
+
if (levelName in customFallbacks && customFallbacks[levelName]) {
|
|
184
|
+
// eslint-disable-next-line security/detect-object-injection
|
|
185
|
+
return customFallbacks[levelName] || '';
|
|
186
|
+
}
|
|
187
|
+
// Use default fallback
|
|
188
|
+
// Safe: levelName is constrained to specific log level strings
|
|
189
|
+
// eslint-disable-next-line security/detect-object-injection
|
|
190
|
+
return emoji_data_1.FALLBACK_EMOJI[levelName] || '';
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* Convert LogLevel enum to string
|
|
194
|
+
* @param level - Log level
|
|
195
|
+
* @returns Level name as string
|
|
196
|
+
*/
|
|
197
|
+
static getLevelName(level) {
|
|
198
|
+
switch (level) {
|
|
199
|
+
case types_1.LogLevel.DEBUG: return 'DEBUG';
|
|
200
|
+
case types_1.LogLevel.INFO: return 'INFO';
|
|
201
|
+
case types_1.LogLevel.WARN: return 'WARN';
|
|
202
|
+
case types_1.LogLevel.ERROR: return 'ERROR';
|
|
203
|
+
case types_1.LogLevel.LOG: return 'LOG';
|
|
204
|
+
default: return 'UNKNOWN';
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
exports.EmojiSelector = EmojiSelector;
|
|
209
|
+
EmojiSelector.config = {
|
|
210
|
+
customMappings: [],
|
|
211
|
+
customFallbacks: {},
|
|
212
|
+
useCustomOnly: false
|
|
213
|
+
};
|
|
214
|
+
// Cache for precompiled regex patterns
|
|
215
|
+
EmojiSelector.compiledMappings = null;
|
|
216
|
+
//# sourceMappingURL=emoji-selector.js.map
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Emoji selector for context-aware logging
|
|
3
|
+
* Analyzes log messages to select appropriate emoji based on context
|
|
4
|
+
*/
|
|
5
|
+
import { LogLevel, LogData, EmojiConfig } from '../types';
|
|
6
|
+
/**
|
|
7
|
+
* Emoji selector class
|
|
8
|
+
* Provides context-aware emoji selection for log messages
|
|
9
|
+
*/
|
|
10
|
+
export declare class EmojiSelector {
|
|
11
|
+
private static config;
|
|
12
|
+
private static compiledMappings;
|
|
13
|
+
/**
|
|
14
|
+
* Configure the emoji selector
|
|
15
|
+
* @param config - Configuration options
|
|
16
|
+
*/
|
|
17
|
+
static configure(config: Partial<EmojiConfig>): void;
|
|
18
|
+
/**
|
|
19
|
+
* Get current configuration
|
|
20
|
+
* @returns Current emoji configuration
|
|
21
|
+
*/
|
|
22
|
+
static getConfig(): EmojiConfig;
|
|
23
|
+
/**
|
|
24
|
+
* Reset configuration to defaults
|
|
25
|
+
*/
|
|
26
|
+
static reset(): void;
|
|
27
|
+
/**
|
|
28
|
+
* Get compiled emoji mappings with precompiled regex patterns
|
|
29
|
+
* This is cached to avoid recompiling regex on every log line
|
|
30
|
+
*/
|
|
31
|
+
private static getCompiledMappings;
|
|
32
|
+
/**
|
|
33
|
+
* Select appropriate emoji based on log level and message content
|
|
34
|
+
* @param level - Log level
|
|
35
|
+
* @param message - Log message
|
|
36
|
+
* @param data - Optional log data
|
|
37
|
+
* @returns Selected emoji or empty string
|
|
38
|
+
*/
|
|
39
|
+
static selectEmoji(level: LogLevel, message: string, data?: LogData): string;
|
|
40
|
+
/**
|
|
41
|
+
* Find emoji based on message and data context
|
|
42
|
+
* @param message - Log message
|
|
43
|
+
* @param data - Optional log data
|
|
44
|
+
* @returns Emoji if match found, null otherwise
|
|
45
|
+
*/
|
|
46
|
+
private static findContextEmoji;
|
|
47
|
+
/**
|
|
48
|
+
* Get combined mappings (custom + default or custom only)
|
|
49
|
+
* @returns Array of emoji mappings
|
|
50
|
+
* @deprecated Use getCompiledMappings() for better performance
|
|
51
|
+
*/
|
|
52
|
+
private static getMappings;
|
|
53
|
+
/**
|
|
54
|
+
* Prepare text for searching by combining message and data
|
|
55
|
+
* @param message - Log message
|
|
56
|
+
* @param data - Optional log data
|
|
57
|
+
* @returns Lowercase combined text
|
|
58
|
+
*/
|
|
59
|
+
private static prepareSearchText;
|
|
60
|
+
/**
|
|
61
|
+
* Check if search text matches any of the precompiled regexes
|
|
62
|
+
* @param searchText - Lowercase text to search in
|
|
63
|
+
* @param regexes - Precompiled regex patterns
|
|
64
|
+
* @returns true if any regex matches
|
|
65
|
+
*/
|
|
66
|
+
private static matchesWithCompiledRegexes;
|
|
67
|
+
/**
|
|
68
|
+
* Check if search text matches any of the keywords
|
|
69
|
+
* @param searchText - Lowercase text to search in
|
|
70
|
+
* @param keywords - Keywords to look for
|
|
71
|
+
* @returns true if any keyword matches
|
|
72
|
+
* @deprecated Use matchesWithCompiledRegexes() for better performance
|
|
73
|
+
*/
|
|
74
|
+
private static matchesKeywords;
|
|
75
|
+
/**
|
|
76
|
+
* Get fallback emoji for a given log level
|
|
77
|
+
* @param level - Log level
|
|
78
|
+
* @returns Fallback emoji for the level
|
|
79
|
+
*/
|
|
80
|
+
private static getFallbackEmoji;
|
|
81
|
+
/**
|
|
82
|
+
* Convert LogLevel enum to string
|
|
83
|
+
* @param level - Log level
|
|
84
|
+
* @returns Level name as string
|
|
85
|
+
*/
|
|
86
|
+
private static getLevelName;
|
|
87
|
+
}
|
|
88
|
+
//# sourceMappingURL=emoji-selector.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"emoji-selector.d.ts","sourceRoot":"","sources":["../../../src/formatter/emoji-selector.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,WAAW,EAAgB,MAAM,UAAU,CAAC;AAcxE;;;GAGG;AACH,qBAAa,aAAa;IACxB,OAAO,CAAC,MAAM,CAAC,MAAM,CAInB;IAGF,OAAO,CAAC,MAAM,CAAC,gBAAgB,CAAuC;IAEtE;;;OAGG;IACH,MAAM,CAAC,SAAS,CAAC,MAAM,EAAE,OAAO,CAAC,WAAW,CAAC,GAAG,IAAI;IASpD;;;OAGG;IACH,MAAM,CAAC,SAAS,IAAI,WAAW;IAU/B;;OAEG;IACH,MAAM,CAAC,KAAK,IAAI,IAAI;IAUpB;;;OAGG;IACH,OAAO,CAAC,MAAM,CAAC,mBAAmB;IAqBlC;;;;;;OAMG;IACH,MAAM,CAAC,WAAW,CAAC,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,OAAO,GAAG,MAAM;IAW5E;;;;;OAKG;IACH,OAAO,CAAC,MAAM,CAAC,gBAAgB;IAc/B;;;;OAIG;IACH,OAAO,CAAC,MAAM,CAAC,WAAW;IAW1B;;;;;OAKG;IACH,OAAO,CAAC,MAAM,CAAC,iBAAiB;IAkBhC;;;;;OAKG;IACH,OAAO,CAAC,MAAM,CAAC,0BAA0B;IAIzC;;;;;;OAMG;IACH,OAAO,CAAC,MAAM,CAAC,eAAe;IAY9B;;;;OAIG;IACH,OAAO,CAAC,MAAM,CAAC,gBAAgB;IAwB/B;;;;OAIG;IACH,OAAO,CAAC,MAAM,CAAC,YAAY;CAU5B"}
|