refactor(text): share unpaired surrogate checks (#15770)

This commit is contained in:
Vincent Koc authored and GitHub committed 2026-12-02 03:59:29 +00:00
1 parent c19f474453
commit 8f8a8539fc
6 files changed
+16 -52

No files matched your search

+1 -4
View File
@@ -1,3 +1,4 @@
import { hasUnpairedSurrogate } from "../kernel/hasUnpairedSurrogate.js";
/*
* The TOON, JSON, YAML and JSON Lines encodings and the Markdown layout are
* adapted from Incur's Formatter.
@@ -41,10 +42,6 @@ export interface CliDelimitedOutputOptions {
type DelimitedScalar = string | number | boolean | null | undefined;
/** UTF-8 cannot encode a lone UTF-16 surrogate without replacing it. */
export const hasUnpairedSurrogate = (value: string): boolean =>
/[\ud800-\udfff]/u.test(value);
/** Check selected output, including keys, before using a non-JSON text format. */
export const containsUnpairedSurrogate = (value: unknown): boolean => {
return containsText(value, hasUnpairedSurrogate);