Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
[ci skip]
  • Loading branch information
addievo committed Nov 2, 2023
1 parent c2a1736 commit 59bc3e7
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions src/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,16 @@ async function* arrayToAsyncIterable<T>(array: T[]): AsyncIterable<T> {
}
}

function encodeNonPrintable(str) {
return str.replace(/[\x00-\x1F\x7F-\x9F]/g, (char) => {
// Skip encoding for space (U+0020)
if (char === ' ') return char;

// Return the Unicode escape sequence
return `\\u${char.charCodeAt(0).toString(16).padStart(4, '0')}`;
});
}

// Function to handle 'table' type output
const outputTableFormatter = async (
rowStream: TableRow[] | AsyncIterable<TableRow>,
Expand Down Expand Up @@ -175,12 +185,8 @@ function outputFormatter(
value = '';
}

// Only trim starting and ending quotes if value is a string
if (typeof value === 'string') {
value = JSON.stringify(value).replace(/^"|"$/g, '');
} else {
value = JSON.stringify(value);
}
value = JSON.stringify(value);
value = encodeNonPrintable(value);

// Re-introduce value.replace logic from old code
value = value.replace(/(?:\r\n|\n)$/, '');
Expand Down

0 comments on commit 59bc3e7

Please sign in to comment.