(s: string)
| 1 | export function isBinaryData(s: string): boolean { |
| 2 | // Remove unicode characters from the string like emojis. |
| 3 | const asciiString = s.replace(/[\u007F-\uFFFF]/g, ""); |
| 4 | |
| 5 | // Create a set of all printable ASCII characters (and some control characters). |
| 6 | const textChars = new Set( |
| 7 | [7, 8, 9, 10, 12, 13, 27].concat( |
| 8 | Array.from({ length: 128 }, (_, i) => i + 32), |
| 9 | ), |
| 10 | ); |
| 11 | |
| 12 | const isBinaryString = (str: string): boolean => { |
| 13 | for (let i = 0; i < str.length; i++) { |
| 14 | if (!textChars.has(str.charCodeAt(i))) { |
| 15 | return true; |
| 16 | } |
| 17 | } |
| 18 | return false; |
| 19 | }; |
| 20 | |
| 21 | return isBinaryString(asciiString); |
| 22 | } |
no test coverage detected