mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-10-06 15:57:13 +00:00
Add usage example for LipFuzzTransformer
This commit is contained in:
@@ -362,8 +362,19 @@ class WebSocketSink implements WritableStreamSink {
|
||||
|
||||
type Dictionary<T> = { [key: string]: T }
|
||||
|
||||
declare function fetch(input?: Request | string): Promise<Response>;
|
||||
declare interface FetchEvent {
|
||||
respondWith(promise: Promise<any>): void;
|
||||
readonly request: Request;
|
||||
respondWith(promise: Promise<Response>): void;
|
||||
}
|
||||
declare class Request {
|
||||
readonly url: string;
|
||||
}
|
||||
declare class Response {
|
||||
constructor(body?: ReadableStream<any>);
|
||||
readonly body: ReadableStream<ArrayBufferView>;
|
||||
}
|
||||
declare class TextDecoderStream extends TransformStream<string, ArrayBufferView> {
|
||||
}
|
||||
|
||||
class LipFuzzTransformer implements TransformStreamTransformer<string, string> {
|
||||
@@ -411,3 +422,25 @@ class LipFuzzTransformer implements TransformStreamTransformer<string, string> {
|
||||
return replacement;
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
const userName = "";
|
||||
const displayName = "";
|
||||
const icon = "";
|
||||
const date = "";
|
||||
const fetchEvent = {} as FetchEvent;
|
||||
|
||||
const data = { userName, displayName, icon, date };
|
||||
const ts = new TransformStream(new LipFuzzTransformer(data));
|
||||
|
||||
fetchEvent.respondWith(
|
||||
fetch(fetchEvent.request.url).then(response => {
|
||||
const transformedBody = response.body
|
||||
// Decode the binary-encoded response to string
|
||||
.pipeThrough(new TextDecoderStream())
|
||||
// Apply the LipFuzzTransformer
|
||||
.pipeThrough(ts);
|
||||
return new Response(transformedBody);
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user