From 7630326b4c5ed32377f34a6668beac626d5156ac Mon Sep 17 00:00:00 2001 From: Garrone Joseph Date: Wed, 20 May 2020 16:35:51 +0200 Subject: [PATCH] feat(std/node) Export TextDecoder and TextEncoder from util (#5663) --- std/node/_utils.ts | 6 ++++++ std/node/util.ts | 10 ++++++++++ std/node/util_test.ts | 18 ++++++++++++++++++ 3 files changed, 34 insertions(+) diff --git a/std/node/_utils.ts b/std/node/_utils.ts index ec89d11a8e..352179f4ab 100644 --- a/std/node/_utils.ts +++ b/std/node/_utils.ts @@ -3,6 +3,12 @@ export function notImplemented(msg?: string): never { throw new Error(message); } +export type _TextDecoder = typeof TextDecoder.prototype; +export const _TextDecoder = TextDecoder; + +export type _TextEncoder = typeof TextEncoder.prototype; +export const _TextEncoder = TextEncoder; + // API helpers export type MaybeNull = T | null; diff --git a/std/node/util.ts b/std/node/util.ts index a61dc30b2a..8c3fdabe87 100644 --- a/std/node/util.ts +++ b/std/node/util.ts @@ -70,3 +70,13 @@ export function validateIntegerRange( ); } } + +import { _TextDecoder, _TextEncoder } from "./_utils.ts"; + +/** The global TextDecoder */ +export type TextDecoder = import("./_utils.ts")._TextDecoder; +export const TextDecoder = _TextDecoder; + +/** The global TextEncoder */ +export type TextEncoder = import("./_utils.ts")._TextEncoder; +export const TextEncoder = _TextEncoder; diff --git a/std/node/util_test.ts b/std/node/util_test.ts index b4e6ea41f3..7036368b62 100644 --- a/std/node/util_test.ts +++ b/std/node/util_test.ts @@ -148,3 +148,21 @@ test({ assert(!util.isPrimitive(objectType)); }, }); + +test({ + name: "[util] TextDecoder", + fn() { + assert(util.TextDecoder === TextDecoder); + const td: util.TextDecoder = new util.TextDecoder(); + assert(td instanceof TextDecoder); + }, +}); + +test({ + name: "[util] TextEncoder", + fn() { + assert(util.TextEncoder === TextEncoder); + const te: util.TextEncoder = new util.TextEncoder(); + assert(te instanceof TextEncoder); + }, +});