Compare commits
2 Commits
3342f7e40b
...
49ea862829
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
49ea862829 | ||
|
|
d77090d04a |
@@ -6,6 +6,7 @@
|
|||||||
* @module text-encoding@1.0.0
|
* @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 { TextDecoderPolyfill } from './TextDecoderPolyfill';
|
||||||
import { TextEncoderPolyfill } from './TextEncoderPolyfill';
|
import { TextEncoderPolyfill } from './TextEncoderPolyfill';
|
||||||
import type {
|
import type {
|
||||||
@@ -17,6 +18,7 @@ import type {
|
|||||||
|
|
||||||
export class TextEncodingFactory implements ITextEncodingFactory {
|
export class TextEncodingFactory implements ITextEncodingFactory {
|
||||||
private static instance: TextEncodingFactory;
|
private static instance: TextEncodingFactory;
|
||||||
|
private static logger = new LoggerComponent('TextEncodingFactory');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get factory singleton instance
|
* Get factory singleton instance
|
||||||
@@ -40,7 +42,7 @@ export class TextEncodingFactory implements ITextEncodingFactory {
|
|||||||
return new TextEncoder();
|
return new TextEncoder();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
// Fall back to polyfill if native fails
|
// 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);
|
return new TextDecoder(label, options);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
// Fall back to polyfill if native fails
|
// 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
|
* This makes TextEncoder/TextDecoder available everywhere
|
||||||
*/
|
*/
|
||||||
export function installTextEncodingPolyfills(): void {
|
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') {
|
if (typeof global !== 'undefined') {
|
||||||
// @ts-expect-error
|
// @ts-expect-error - TextEncoder may not exist in global scope
|
||||||
if (typeof global.TextEncoder === 'undefined') {
|
if (typeof global.TextEncoder === 'undefined') {
|
||||||
// @ts-expect-error
|
// @ts-expect-error - Adding to global object
|
||||||
global.TextEncoder = TextEncoderPolyfill;
|
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') {
|
if (typeof global.TextDecoder === 'undefined') {
|
||||||
// @ts-expect-error
|
// @ts-expect-error - Adding to global object
|
||||||
global.TextDecoder = TextDecoderPolyfill;
|
global.TextDecoder = TextDecoderPolyfill;
|
||||||
console.info('[TextEncodingFactory] Installed TextDecoder polyfill globally');
|
logger.info('Installed TextDecoder polyfill globally');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user