22 lines
951 B
TypeScript
22 lines
951 B
TypeScript
/**
|
|
* Removes unpaired Unicode surrogate characters from a string.
|
|
*
|
|
* Unpaired surrogates (high surrogates 0xD800-0xDBFF without matching low surrogates 0xDC00-0xDFFF,
|
|
* or vice versa) cause JSON serialization errors in many API providers.
|
|
*
|
|
* Valid emoji and other characters outside the Basic Multilingual Plane use properly paired
|
|
* surrogates and will NOT be affected by this function.
|
|
*
|
|
* @param text - The text to sanitize
|
|
* @returns The sanitized text with unpaired surrogates removed
|
|
*
|
|
* @example
|
|
* // Valid emoji (properly paired surrogates) are preserved
|
|
* sanitizeSurrogates("Hello 🙈 World") // => "Hello 🙈 World"
|
|
*
|
|
* // Unpaired high surrogate is removed
|
|
* const unpaired = String.fromCharCode(0xD83D); // high surrogate without low
|
|
* sanitizeSurrogates(`Text ${unpaired} here`) // => "Text here"
|
|
*/
|
|
export declare function sanitizeSurrogates(text: string): string;
|
|
//# sourceMappingURL=sanitize-unicode.d.ts.map
|