MCPcopy
hub / github.com/victorporof/Sublime-HTMLPrettify / isJSON

Function isJSON

src/js/utils/fileUtils.js:94–116  ·  view source on GitHub ↗
(bufferContents)

Source from the content-addressed store, hash-verified

92};
93
94export const isJSON = (bufferContents) => {
95 const isSavedFile = ORIGINAL_FILE_PATH !== '?';
96 const useEditorFileSyntaxForDeterminingFileType = EDITOR_FILE_SYNTAX !== '?';
97
98 const isAllowedExtension = hasAllowedFileExtension('json', ORIGINAL_FILE_PATH);
99 const isAllowedSyntax = hasAllowedFileSyntax('json', EDITOR_FILE_SYNTAX);
100 const isDisallowedFilePattern = hasDisallowedFilePathPattern('json', ORIGINAL_FILE_PATH);
101 const isMaybeJson = bufferContents.match(/^\s*[{[]/);
102
103 if (!isSavedFile) {
104 return useEditorFileSyntaxForDeterminingFileType
105 ? isAllowedSyntax || isMaybeJson
106 : isMaybeJson;
107 }
108
109 if (isDisallowedFilePattern) {
110 return false;
111 }
112
113 return useEditorFileSyntaxForDeterminingFileType
114 ? isAllowedSyntax || isAllowedExtension
115 : isAllowedExtension;
116};
117
118export const isJS = (bufferContents) => {
119 const isSavedFile = ORIGINAL_FILE_PATH !== '?';

Callers

nothing calls this directly

Calls 3

hasAllowedFileExtensionFunction · 0.85
hasAllowedFileSyntaxFunction · 0.85

Tested by

no test coverage detected