Skip to content
This repository has been archived by the owner on Jul 5, 2024. It is now read-only.

Commit

Permalink
Merge remote-tracking branch 'origin/main' into nodejs-streams
Browse files Browse the repository at this point in the history
# Conflicts:
#	src/internals/esque.ts
  • Loading branch information
KATT committed Oct 26, 2023
2 parents d70025a + 44488a6 commit 94751a1
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 2 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@


# [0.22.0](https://github.com/trpc/tupleson/compare/0.21.0...0.22.0) (2023-10-26)


### Features

* configurable `TextDecoder` instance ([#80](https://github.com/trpc/tupleson/issues/80)) ([f4b3630](https://github.com/trpc/tupleson/commit/f4b3630e7390cf04983b01d89d05affb81ff2e4c))

# [0.21.0](https://github.com/trpc/tupleson/compare/0.20.4...0.21.0) (2023-10-20)


Expand Down
1 change: 1 addition & 0 deletions cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"contributorsrc",
"conventionalcommits",
"deferreds",
"esque",
"gzipped",
"Iterarable",
"KATT",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "tupleson",
"version": "0.21.0",
"version": "0.22.0",
"description": "A hackable JSON serializer/deserializer",
"repository": {
"type": "git",
Expand Down
6 changes: 6 additions & 0 deletions src/async/asyncTypes.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { TextDecoderEsque } from "../internals/esque.js";
import {
TsonBranded,
TsonType,
Expand Down Expand Up @@ -66,6 +67,11 @@ export interface TsonAsyncOptions {
* @default `${crypto.randomUUID} if available, otherwise a random string generated by Math.random`
*/
nonce?: () => number | string;
/**
* Customize a text decoder if your runtime doesn't support the `TextDecoder` API
* @default TextDecoder
*/
textDecoder?: TextDecoderEsque;

/**
* The list of types to use
Expand Down
3 changes: 2 additions & 1 deletion src/async/deserializeAsync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -344,10 +344,11 @@ export function createTsonParseEventSource(opts: TsonAsyncOptions) {
export function createTsonParseJsonStreamResponse(opts: TsonAsyncOptions) {
const instance = createTsonParseAsync(opts);

const textDecoder = opts.textDecoder ?? new TextDecoder();

return async <TValue = unknown>(response: Response) => {
assert(response.body, "Response body is empty");

const textDecoder = new TextDecoder();
const stringIterator = mapIterable(
readableStreamToAsyncIterable(response.body),
(v) => textDecoder.decode(v),
Expand Down

0 comments on commit 94751a1

Please sign in to comment.