MCPcopy Create free account
hub / github.com/coder/coder / isBinaryData

Function isBinaryData

site/src/modules/templates/TemplateFiles/isBinaryData.ts:1–22  ·  view source on GitHub ↗
(s: string)

Source from the content-addressed store, hash-verified

1export 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}

Callers 2

getTemplateVersionFilesFunction · 0.90
TemplateVersionEditorFunction · 0.90

Calls 1

isBinaryStringFunction · 0.85

Tested by

no test coverage detected