Compare commits

...

2 Commits

Author SHA1 Message Date
Chris Daßler
49ea862829 Fix TypeScript warnings: add explanatory comments to @ts-expect-error directives
🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-08-29 15:02:08 +02:00
Chris Daßler
d77090d04a Add logger dependency and replace console logging
- Import LoggerComponent from ior:gitea:gitea.metatrom.net:universal-components/logger@1.0.0
- Replace console.warn and console.info with appropriate logger methods
- Use warn level for fallback scenarios when native implementations fail
- Use info level for polyfill installation notifications

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-08-29 15:01:40 +02:00

View File

@@ -6,6 +6,7 @@
* @module text-encoding@1.0.0
*/
import { LoggerComponent } from 'ior:gitea:gitea.metatrom.net:universal-components/logger@1.0.0';
import { TextDecoderPolyfill } from './TextDecoderPolyfill';
import { TextEncoderPolyfill } from './TextEncoderPolyfill';
import type {
@@ -17,6 +18,7 @@ import type {
export class TextEncodingFactory implements ITextEncodingFactory {
private static instance: TextEncodingFactory;
private static logger = new LoggerComponent('TextEncodingFactory');
/**
* Get factory singleton instance
@@ -40,7 +42,7 @@ export class TextEncodingFactory implements ITextEncodingFactory {
return new TextEncoder();
} catch (e) {
// Fall back to polyfill if native fails
console.warn('[TextEncodingFactory] Native TextEncoder failed, using polyfill:', e);
TextEncodingFactory.logger.warn('Native TextEncoder failed, using polyfill:', e);
}
}
@@ -59,7 +61,7 @@ export class TextEncodingFactory implements ITextEncodingFactory {
return new TextDecoder(label, options);
} catch (e) {
// Fall back to polyfill if native fails
console.warn('[TextEncodingFactory] Native TextDecoder failed, using polyfill:', e);
TextEncodingFactory.logger.warn('Native TextDecoder failed, using polyfill:', e);
}
}
@@ -113,20 +115,22 @@ export function createTextDecoder(label?: string, options?: TextDecoderOptions):
* This makes TextEncoder/TextDecoder available everywhere
*/
export function installTextEncodingPolyfills(): void {
// @ts-expect-error
const logger = new LoggerComponent('TextEncodingPolyfills');
// @ts-expect-error - global object access in React Native/Node environment
if (typeof global !== 'undefined') {
// @ts-expect-error
// @ts-expect-error - TextEncoder may not exist in global scope
if (typeof global.TextEncoder === 'undefined') {
// @ts-expect-error
// @ts-expect-error - Adding to global object
global.TextEncoder = TextEncoderPolyfill;
console.info('[TextEncodingFactory] Installed TextEncoder polyfill globally');
logger.info('Installed TextEncoder polyfill globally');
}
// @ts-expect-error
// @ts-expect-error - TextDecoder may not exist in global scope
if (typeof global.TextDecoder === 'undefined') {
// @ts-expect-error
// @ts-expect-error - Adding to global object
global.TextDecoder = TextDecoderPolyfill;
console.info('[TextEncodingFactory] Installed TextDecoder polyfill globally');
logger.info('Installed TextDecoder polyfill globally');
}
}
}