sigcheck 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (57) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +1081 -0
  3. package/dist/core/file-types/audio.d.ts +12 -0
  4. package/dist/core/file-types/audio.js +93 -0
  5. package/dist/core/file-types/compressed.d.ts +10 -0
  6. package/dist/core/file-types/compressed.js +155 -0
  7. package/dist/core/file-types/image.d.ts +22 -0
  8. package/dist/core/file-types/image.js +248 -0
  9. package/dist/core/file-types/index.d.ts +109 -0
  10. package/dist/core/file-types/index.js +215 -0
  11. package/dist/core/file-types/other.d.ts +21 -0
  12. package/dist/core/file-types/other.js +234 -0
  13. package/dist/core/file-types/video.d.ts +15 -0
  14. package/dist/core/file-types/video.js +153 -0
  15. package/dist/core/index.d.ts +3 -0
  16. package/dist/core/index.js +19 -0
  17. package/dist/core/interfaces/dto/detected-file-info.d.ts +10 -0
  18. package/dist/core/interfaces/dto/detected-file-info.js +2 -0
  19. package/dist/core/interfaces/dto/index.d.ts +1 -0
  20. package/dist/core/interfaces/dto/index.js +17 -0
  21. package/dist/core/interfaces/index.d.ts +2 -0
  22. package/dist/core/interfaces/index.js +18 -0
  23. package/dist/core/interfaces/options/detect-file-options.d.ts +6 -0
  24. package/dist/core/interfaces/options/detect-file-options.js +2 -0
  25. package/dist/core/interfaces/options/file-validator-options.d.ts +6 -0
  26. package/dist/core/interfaces/options/file-validator-options.js +2 -0
  27. package/dist/core/interfaces/options/index.d.ts +4 -0
  28. package/dist/core/interfaces/options/index.js +20 -0
  29. package/dist/core/interfaces/options/validate-file-type-options.d.ts +7 -0
  30. package/dist/core/interfaces/options/validate-file-type-options.js +2 -0
  31. package/dist/core/interfaces/options/zip-validator-options.d.ts +6 -0
  32. package/dist/core/interfaces/options/zip-validator-options.js +2 -0
  33. package/dist/core/types/file-info.d.ts +10 -0
  34. package/dist/core/types/file-info.js +2 -0
  35. package/dist/core/types/file-signature.d.ts +10 -0
  36. package/dist/core/types/file-signature.js +2 -0
  37. package/dist/core/types/index.d.ts +2 -0
  38. package/dist/core/types/index.js +18 -0
  39. package/dist/detection/index.d.ts +10 -0
  40. package/dist/detection/index.js +54 -0
  41. package/dist/index.d.ts +55 -0
  42. package/dist/index.js +28 -0
  43. package/dist/utils/index.d.ts +67 -0
  44. package/dist/utils/index.js +167 -0
  45. package/dist/validation/audio.d.ts +50 -0
  46. package/dist/validation/audio.js +84 -0
  47. package/dist/validation/compressed.d.ts +34 -0
  48. package/dist/validation/compressed.js +54 -0
  49. package/dist/validation/image.d.ts +128 -0
  50. package/dist/validation/image.js +225 -0
  51. package/dist/validation/index.d.ts +16 -0
  52. package/dist/validation/index.js +91 -0
  53. package/dist/validation/other.d.ts +120 -0
  54. package/dist/validation/other.js +185 -0
  55. package/dist/validation/video.d.ts +78 -0
  56. package/dist/validation/video.js +140 -0
  57. package/package.json +97 -0
@@ -0,0 +1,120 @@
1
+ /**
2
+ * Determine if file content contains a valid 'blend' file signature
3
+ *
4
+ * @param file File content represents in Array<number> / ArrayBuffer / Uint8Array
5
+ *
6
+ * @returns {boolean} True if found a signature of type 'blend' in file content, otherwise false
7
+ */
8
+ export declare function isBLEND(file: Array<number> | ArrayBuffer | Uint8Array): boolean;
9
+ /**
10
+ * Determine if file content contains a valid 'elf' file signature
11
+ *
12
+ * @param file File content represents in Array<number> / ArrayBuffer / Uint8Array
13
+ *
14
+ * @returns {boolean} True if found a signature of type 'elf' in file content, otherwise false
15
+ */
16
+ export declare function isELF(file: Array<number> | ArrayBuffer | Uint8Array): boolean;
17
+ /**
18
+ * Determine if file content contains a valid 'exe' file signature
19
+ *
20
+ * @param file File content represents in Array<number> / ArrayBuffer / Uint8Array
21
+ *
22
+ * @returns {boolean} True if found a signature of type 'exe' in file content, otherwise false
23
+ */
24
+ export declare function isEXE(file: Array<number> | ArrayBuffer | Uint8Array): boolean;
25
+ /**
26
+ * Determine if file content contains a valid 'mach-o' file signature
27
+ *
28
+ * @param file File content represents in Array<number> / ArrayBuffer / Uint8Array
29
+ *
30
+ * @returns {boolean} True if found a signature of type 'mach-o' in file content, otherwise false
31
+ */
32
+ export declare function isMACHO(file: Array<number> | ArrayBuffer | Uint8Array): boolean;
33
+ /**
34
+ * Determine if file content contains a valid 'indd' file signature
35
+ *
36
+ * @param file File content represents in Array<number> / ArrayBuffer / Uint8Array
37
+ *
38
+ * @returns {boolean} True if found a signature of type 'indd' in file content, otherwise false
39
+ */
40
+ export declare function isINDD(file: Array<number> | ArrayBuffer | Uint8Array): boolean;
41
+ /**
42
+ * Determine if file content contains a valid 'orc' file signature
43
+ *
44
+ * @param file File content represents in Array<number> / ArrayBuffer / Uint8Array
45
+ *
46
+ * @returns {boolean} True if found a signature of type 'orc' in file content, otherwise false
47
+ */
48
+ export declare function isORC(file: Array<number> | ArrayBuffer | Uint8Array): boolean;
49
+ /**
50
+ * Determine if file content contains a valid 'parquet' file signature
51
+ *
52
+ * @param file File content represents in Array<number> / ArrayBuffer / Uint8Array
53
+ *
54
+ * @returns {boolean} True if found a signature of type 'parquet' in file content, otherwise false
55
+ */
56
+ export declare function isPARQUET(file: Array<number> | ArrayBuffer | Uint8Array): boolean;
57
+ /**
58
+ * Determine if file content contains a valid 'pdf' file signature
59
+ *
60
+ * @param file File content represents in Array<number> / ArrayBuffer / Uint8Array
61
+ *
62
+ * @returns {boolean} True if found a signature of type 'pdf' in file content, otherwise false
63
+ */
64
+ export declare function isPDF(file: Array<number> | ArrayBuffer | Uint8Array): boolean;
65
+ /**
66
+ * Determine if file content contains a valid 'ps' file signature
67
+ *
68
+ * @param file File content represents in Array<number> / ArrayBuffer / Uint8Array
69
+ *
70
+ * @returns {boolean} True if found a signature of type 'ps' in file content, otherwise false
71
+ */
72
+ export declare function isPS(file: Array<number> | ArrayBuffer | Uint8Array): boolean;
73
+ /**
74
+ * Determine if file content contains a valid 'rtf' file signature
75
+ *
76
+ * @param file File content represents in Array<number> / ArrayBuffer / Uint8Array
77
+ *
78
+ * @returns {boolean} True if found a signature of type 'rtf' in file content, otherwise false
79
+ */
80
+ export declare function isRTF(file: Array<number> | ArrayBuffer | Uint8Array): boolean;
81
+ /**
82
+ * Determine if file content contains a valid 'sqlite' file signature
83
+ *
84
+ * @param file File content represents in Array<number> / ArrayBuffer / Uint8Array
85
+ *
86
+ * @returns {boolean} True if found a signature of type 'sqlite' in file content, otherwise false
87
+ */
88
+ export declare function isSQLITE(file: Array<number> | ArrayBuffer | Uint8Array): boolean;
89
+ /**
90
+ * Determine if file content contains a valid 'stl' file signature
91
+ *
92
+ * @param file File content represents in Array<number> / ArrayBuffer / Uint8Array
93
+ *
94
+ * @returns {boolean} True if found a signature of type 'stl' in file content, otherwise false
95
+ */
96
+ export declare function isSTL(file: Array<number> | ArrayBuffer | Uint8Array): boolean;
97
+ /**
98
+ * Determine if file content contains a valid 'ttf' file signature
99
+ *
100
+ * @param file File content represents in Array<number> / ArrayBuffer / Uint8Array
101
+ *
102
+ * @returns {boolean} True if found a signature of type 'ttf' in file content, otherwise false
103
+ */
104
+ export declare function isTTF(file: Array<number> | ArrayBuffer | Uint8Array): boolean;
105
+ /**
106
+ * Determine if file content contains a valid 'doc' file signature
107
+ *
108
+ * @param file File content represents in Array<number> / ArrayBuffer / Uint8Array
109
+ *
110
+ * @returns {boolean} True if found a signature of type 'doc' in file content, otherwise false
111
+ */
112
+ export declare function isDOC(file: Array<number> | ArrayBuffer | Uint8Array): boolean;
113
+ /**
114
+ * Determine if file content contains a valid 'pcap' file signature
115
+ *
116
+ * @param file File content represents in Array<number> / ArrayBuffer / Uint8Array
117
+ *
118
+ * @returns {boolean} True if found a signature of type 'pcap' in file content, otherwise false
119
+ */
120
+ export declare function isPCAP(file: Array<number> | ArrayBuffer | Uint8Array): boolean;
@@ -0,0 +1,185 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isPCAP = exports.isDOC = exports.isTTF = exports.isSTL = exports.isSQLITE = exports.isRTF = exports.isPS = exports.isPDF = exports.isPARQUET = exports.isORC = exports.isINDD = exports.isMACHO = exports.isEXE = exports.isELF = exports.isBLEND = void 0;
4
+ const core_1 = require("../core");
5
+ const utils_1 = require("../utils");
6
+ /**
7
+ * Determine if file content contains a valid 'blend' file signature
8
+ *
9
+ * @param file File content represents in Array<number> / ArrayBuffer / Uint8Array
10
+ *
11
+ * @returns {boolean} True if found a signature of type 'blend' in file content, otherwise false
12
+ */
13
+ function isBLEND(file) {
14
+ const fileChunk = (0, utils_1.getFileChunk)(file);
15
+ return core_1.FileTypes.checkByFileType(fileChunk, "blend");
16
+ }
17
+ exports.isBLEND = isBLEND;
18
+ /**
19
+ * Determine if file content contains a valid 'elf' file signature
20
+ *
21
+ * @param file File content represents in Array<number> / ArrayBuffer / Uint8Array
22
+ *
23
+ * @returns {boolean} True if found a signature of type 'elf' in file content, otherwise false
24
+ */
25
+ function isELF(file) {
26
+ const fileChunk = (0, utils_1.getFileChunk)(file);
27
+ return core_1.FileTypes.checkByFileType(fileChunk, "elf");
28
+ }
29
+ exports.isELF = isELF;
30
+ /**
31
+ * Determine if file content contains a valid 'exe' file signature
32
+ *
33
+ * @param file File content represents in Array<number> / ArrayBuffer / Uint8Array
34
+ *
35
+ * @returns {boolean} True if found a signature of type 'exe' in file content, otherwise false
36
+ */
37
+ function isEXE(file) {
38
+ const fileChunk = (0, utils_1.getFileChunk)(file);
39
+ return core_1.FileTypes.checkByFileType(fileChunk, "exe");
40
+ }
41
+ exports.isEXE = isEXE;
42
+ /**
43
+ * Determine if file content contains a valid 'mach-o' file signature
44
+ *
45
+ * @param file File content represents in Array<number> / ArrayBuffer / Uint8Array
46
+ *
47
+ * @returns {boolean} True if found a signature of type 'mach-o' in file content, otherwise false
48
+ */
49
+ function isMACHO(file) {
50
+ const fileChunk = (0, utils_1.getFileChunk)(file);
51
+ return core_1.FileTypes.checkByFileType(fileChunk, "macho");
52
+ }
53
+ exports.isMACHO = isMACHO;
54
+ /**
55
+ * Determine if file content contains a valid 'indd' file signature
56
+ *
57
+ * @param file File content represents in Array<number> / ArrayBuffer / Uint8Array
58
+ *
59
+ * @returns {boolean} True if found a signature of type 'indd' in file content, otherwise false
60
+ */
61
+ function isINDD(file) {
62
+ const fileChunk = (0, utils_1.getFileChunk)(file);
63
+ return core_1.FileTypes.checkByFileType(fileChunk, "indd");
64
+ }
65
+ exports.isINDD = isINDD;
66
+ /**
67
+ * Determine if file content contains a valid 'orc' file signature
68
+ *
69
+ * @param file File content represents in Array<number> / ArrayBuffer / Uint8Array
70
+ *
71
+ * @returns {boolean} True if found a signature of type 'orc' in file content, otherwise false
72
+ */
73
+ function isORC(file) {
74
+ const fileChunk = (0, utils_1.getFileChunk)(file);
75
+ return core_1.FileTypes.checkByFileType(fileChunk, "orc");
76
+ }
77
+ exports.isORC = isORC;
78
+ /**
79
+ * Determine if file content contains a valid 'parquet' file signature
80
+ *
81
+ * @param file File content represents in Array<number> / ArrayBuffer / Uint8Array
82
+ *
83
+ * @returns {boolean} True if found a signature of type 'parquet' in file content, otherwise false
84
+ */
85
+ function isPARQUET(file) {
86
+ const fileChunk = (0, utils_1.getFileChunk)(file);
87
+ return core_1.FileTypes.checkByFileType(fileChunk, "parquet");
88
+ }
89
+ exports.isPARQUET = isPARQUET;
90
+ /**
91
+ * Determine if file content contains a valid 'pdf' file signature
92
+ *
93
+ * @param file File content represents in Array<number> / ArrayBuffer / Uint8Array
94
+ *
95
+ * @returns {boolean} True if found a signature of type 'pdf' in file content, otherwise false
96
+ */
97
+ function isPDF(file) {
98
+ const fileChunk = (0, utils_1.getFileChunk)(file);
99
+ return core_1.FileTypes.checkByFileType(fileChunk, "pdf");
100
+ }
101
+ exports.isPDF = isPDF;
102
+ /**
103
+ * Determine if file content contains a valid 'ps' file signature
104
+ *
105
+ * @param file File content represents in Array<number> / ArrayBuffer / Uint8Array
106
+ *
107
+ * @returns {boolean} True if found a signature of type 'ps' in file content, otherwise false
108
+ */
109
+ function isPS(file) {
110
+ const fileChunk = (0, utils_1.getFileChunk)(file);
111
+ return core_1.FileTypes.checkByFileType(fileChunk, "ps");
112
+ }
113
+ exports.isPS = isPS;
114
+ /**
115
+ * Determine if file content contains a valid 'rtf' file signature
116
+ *
117
+ * @param file File content represents in Array<number> / ArrayBuffer / Uint8Array
118
+ *
119
+ * @returns {boolean} True if found a signature of type 'rtf' in file content, otherwise false
120
+ */
121
+ function isRTF(file) {
122
+ const fileChunk = (0, utils_1.getFileChunk)(file);
123
+ return core_1.FileTypes.checkByFileType(fileChunk, "rtf");
124
+ }
125
+ exports.isRTF = isRTF;
126
+ /**
127
+ * Determine if file content contains a valid 'sqlite' file signature
128
+ *
129
+ * @param file File content represents in Array<number> / ArrayBuffer / Uint8Array
130
+ *
131
+ * @returns {boolean} True if found a signature of type 'sqlite' in file content, otherwise false
132
+ */
133
+ function isSQLITE(file) {
134
+ const fileChunk = (0, utils_1.getFileChunk)(file);
135
+ return core_1.FileTypes.checkByFileType(fileChunk, "sqlite");
136
+ }
137
+ exports.isSQLITE = isSQLITE;
138
+ /**
139
+ * Determine if file content contains a valid 'stl' file signature
140
+ *
141
+ * @param file File content represents in Array<number> / ArrayBuffer / Uint8Array
142
+ *
143
+ * @returns {boolean} True if found a signature of type 'stl' in file content, otherwise false
144
+ */
145
+ function isSTL(file) {
146
+ const fileChunk = (0, utils_1.getFileChunk)(file);
147
+ return core_1.FileTypes.checkByFileType(fileChunk, "stl");
148
+ }
149
+ exports.isSTL = isSTL;
150
+ /**
151
+ * Determine if file content contains a valid 'ttf' file signature
152
+ *
153
+ * @param file File content represents in Array<number> / ArrayBuffer / Uint8Array
154
+ *
155
+ * @returns {boolean} True if found a signature of type 'ttf' in file content, otherwise false
156
+ */
157
+ function isTTF(file) {
158
+ const fileChunk = (0, utils_1.getFileChunk)(file);
159
+ return core_1.FileTypes.checkByFileType(fileChunk, "ttf");
160
+ }
161
+ exports.isTTF = isTTF;
162
+ /**
163
+ * Determine if file content contains a valid 'doc' file signature
164
+ *
165
+ * @param file File content represents in Array<number> / ArrayBuffer / Uint8Array
166
+ *
167
+ * @returns {boolean} True if found a signature of type 'doc' in file content, otherwise false
168
+ */
169
+ function isDOC(file) {
170
+ const fileChunk = (0, utils_1.getFileChunk)(file);
171
+ return core_1.FileTypes.checkByFileType(fileChunk, "doc");
172
+ }
173
+ exports.isDOC = isDOC;
174
+ /**
175
+ * Determine if file content contains a valid 'pcap' file signature
176
+ *
177
+ * @param file File content represents in Array<number> / ArrayBuffer / Uint8Array
178
+ *
179
+ * @returns {boolean} True if found a signature of type 'pcap' in file content, otherwise false
180
+ */
181
+ function isPCAP(file) {
182
+ const fileChunk = (0, utils_1.getFileChunk)(file);
183
+ return core_1.FileTypes.checkByFileType(fileChunk, "pcap");
184
+ }
185
+ exports.isPCAP = isPCAP;
@@ -0,0 +1,78 @@
1
+ import { FileValidatorOptions } from "../core";
2
+ /**
3
+ * Determine if file content contains a valid 'avi' file signature
4
+ *
5
+ * @param file File content represents in Array<number> / ArrayBuffer / Uint8Array
6
+ *
7
+ * @returns {boolean} True if found a signature of type 'avi' in file content, otherwise false
8
+ */
9
+ export declare function isAVI(file: Array<number> | ArrayBuffer | Uint8Array): boolean;
10
+ /**
11
+ * Determine if file content contains a valid 'flv' file signature.
12
+ * Since 'flv' and 'm4v' share the same signature - additional check required - check if file content contains a "flv" string in the first few bytes of the file
13
+ *
14
+ * @param file File content represents in Array<number> / ArrayBuffer / Uint8Array
15
+ *
16
+ * @returns {boolean} True if found a signature of type 'flv' & "flv" string in file content, otherwise false
17
+ */
18
+ export declare function isFLV(file: Array<number> | ArrayBuffer | Uint8Array): boolean;
19
+ /**
20
+ * Determine if file content contains a valid 'm4v' file signature.
21
+ * Since 'flv' and 'm4v' share the same signature - additional check required - check if file content contains a "ftyp" string in the first few bytes of the file
22
+ *
23
+ * @param file File content represents in Array<number> / ArrayBuffer / Uint8Array
24
+ *
25
+ * @returns {boolean} True if found a signature of type 'm4v' & "ftyp" string in file content, otherwise false
26
+ */
27
+ export declare function isM4V(file: Array<number> | ArrayBuffer | Uint8Array): boolean;
28
+ /**
29
+ * Determine if file content contains a valid 'mkv' file signature.
30
+ * Since 'mkv' and 'webm' share the same signature - additional check required - search for the presence of the "Segment" element in the mkv header
31
+ *
32
+ * @param file File content represents in Array<number> / ArrayBuffer / Uint8Array
33
+ *
34
+ * @returns {boolean} True if found a signature of type 'mkv' & "ftyp" string in file content, otherwise false
35
+ */
36
+ export declare function isMKV(file: Array<number> | ArrayBuffer | Uint8Array): boolean;
37
+ /**
38
+ * Determine if file content contains a valid 'mov' file signature
39
+ *
40
+ * @param file File content represents in Array<number> / ArrayBuffer / Uint8Array
41
+ *
42
+ * @returns {boolean} True if found a signature of type 'mov' in file content, otherwise false
43
+ */
44
+ export declare function isMOV(file: Array<number> | ArrayBuffer | Uint8Array): boolean;
45
+ /**
46
+ * Determine if file content contains a valid 'mp4' file signature.
47
+ *
48
+ * @param file File content represents in Array<number> / ArrayBuffer / Uint8Array
49
+ * @param options parameters for additional actions
50
+ *
51
+ * @returns {boolean} True if found a signature of type 'mp4' in file content, otherwise false
52
+ */
53
+ export declare function isMP4(file: Array<number> | ArrayBuffer | Uint8Array, options?: FileValidatorOptions): boolean;
54
+ /**
55
+ * Determine if file content contains a valid 'ogg' file signature
56
+ *
57
+ * @param file File content represents in Array<number> / ArrayBuffer / Uint8Array
58
+ *
59
+ * @returns {boolean} True if found a signature of type 'ogg' in file content, otherwise false
60
+ */
61
+ export declare function isOGG(file: Array<number> | ArrayBuffer | Uint8Array): boolean;
62
+ /**
63
+ * Determine if file content contains a valid 'swf' file signature
64
+ *
65
+ * @param file File content represents in Array<number> / ArrayBuffer / Uint8Array
66
+ *
67
+ * @returns {boolean} True if found a signature of type 'swf' in file content, otherwise false
68
+ */
69
+ export declare function isSWF(file: Array<number> | ArrayBuffer | Uint8Array): boolean;
70
+ /**
71
+ * Determine if file content contains a valid 'webm' file signature.
72
+ * Since 'mkv' and 'webm' share the same signature - additional check required - search for the presence of the "DocType" element in the webm header
73
+ *
74
+ * @param file File content represents in Array<number> / ArrayBuffer / Uint8Array
75
+ *
76
+ * @returns {boolean} True if found a signature of type 'webm' & "ftyp" string in file content, otherwise false
77
+ */
78
+ export declare function isWEBM(file: Array<number> | ArrayBuffer | Uint8Array): boolean;
@@ -0,0 +1,140 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isWEBM = exports.isSWF = exports.isOGG = exports.isMP4 = exports.isMOV = exports.isMKV = exports.isM4V = exports.isFLV = exports.isAVI = void 0;
4
+ const core_1 = require("../core");
5
+ const utils_1 = require("../utils");
6
+ /**
7
+ * Determine if file content contains a valid 'avi' file signature
8
+ *
9
+ * @param file File content represents in Array<number> / ArrayBuffer / Uint8Array
10
+ *
11
+ * @returns {boolean} True if found a signature of type 'avi' in file content, otherwise false
12
+ */
13
+ function isAVI(file) {
14
+ const fileChunk = (0, utils_1.getFileChunk)(file);
15
+ return core_1.FileTypes.checkByFileType(fileChunk, "avi");
16
+ }
17
+ exports.isAVI = isAVI;
18
+ /**
19
+ * Determine if file content contains a valid 'flv' file signature.
20
+ * Since 'flv' and 'm4v' share the same signature - additional check required - check if file content contains a "flv" string in the first few bytes of the file
21
+ *
22
+ * @param file File content represents in Array<number> / ArrayBuffer / Uint8Array
23
+ *
24
+ * @returns {boolean} True if found a signature of type 'flv' & "flv" string in file content, otherwise false
25
+ */
26
+ function isFLV(file) {
27
+ const fileChunk = (0, utils_1.getFileChunk)(file);
28
+ const isFlvSignature = core_1.FileTypes.checkByFileType(fileChunk, "flv");
29
+ if (!isFlvSignature)
30
+ return false;
31
+ // Check if file content contains a "flv" string
32
+ return (0, utils_1.isFlvStringIncluded)(fileChunk);
33
+ }
34
+ exports.isFLV = isFLV;
35
+ /**
36
+ * Determine if file content contains a valid 'm4v' file signature.
37
+ * Since 'flv' and 'm4v' share the same signature - additional check required - check if file content contains a "ftyp" string in the first few bytes of the file
38
+ *
39
+ * @param file File content represents in Array<number> / ArrayBuffer / Uint8Array
40
+ *
41
+ * @returns {boolean} True if found a signature of type 'm4v' & "ftyp" string in file content, otherwise false
42
+ */
43
+ function isM4V(file) {
44
+ const fileChunk = (0, utils_1.getFileChunk)(file);
45
+ const isM4vSignature = core_1.FileTypes.checkByFileType(fileChunk, "m4v");
46
+ if (!isM4vSignature)
47
+ return false;
48
+ // Check if file content contains a "ftyp" string
49
+ return (0, utils_1.isftypStringIncluded)(fileChunk);
50
+ }
51
+ exports.isM4V = isM4V;
52
+ /**
53
+ * Determine if file content contains a valid 'mkv' file signature.
54
+ * Since 'mkv' and 'webm' share the same signature - additional check required - search for the presence of the "Segment" element in the mkv header
55
+ *
56
+ * @param file File content represents in Array<number> / ArrayBuffer / Uint8Array
57
+ *
58
+ * @returns {boolean} True if found a signature of type 'mkv' & "ftyp" string in file content, otherwise false
59
+ */
60
+ function isMKV(file) {
61
+ const fileChunk = (0, utils_1.getFileChunk)(file, 64); // Check the first 64 bytes of the file
62
+ const isMkvSignature = core_1.FileTypes.checkByFileType(fileChunk, "mkv");
63
+ if (!isMkvSignature)
64
+ return false;
65
+ // Search for the presence of the "Segment" element in the mkv header
66
+ return (0, utils_1.findMatroskaDocTypeElements)(fileChunk) === "mkv";
67
+ }
68
+ exports.isMKV = isMKV;
69
+ /**
70
+ * Determine if file content contains a valid 'mov' file signature
71
+ *
72
+ * @param file File content represents in Array<number> / ArrayBuffer / Uint8Array
73
+ *
74
+ * @returns {boolean} True if found a signature of type 'mov' in file content, otherwise false
75
+ */
76
+ function isMOV(file) {
77
+ const fileChunk = (0, utils_1.getFileChunk)(file);
78
+ return core_1.FileTypes.checkByFileType(fileChunk, "mov");
79
+ }
80
+ exports.isMOV = isMOV;
81
+ /**
82
+ * Determine if file content contains a valid 'mp4' file signature.
83
+ *
84
+ * @param file File content represents in Array<number> / ArrayBuffer / Uint8Array
85
+ * @param options parameters for additional actions
86
+ *
87
+ * @returns {boolean} True if found a signature of type 'mp4' in file content, otherwise false
88
+ */
89
+ function isMP4(file, options) {
90
+ const fileChunk = (0, utils_1.getFileChunk)(file);
91
+ const isMp4 = core_1.FileTypes.checkByFileType(fileChunk, "mp4");
92
+ if (!isMp4) {
93
+ if (options === null || options === void 0 ? void 0 : options.excludeSimilarTypes)
94
+ return false;
95
+ return isM4V(fileChunk); // since 'm4v' is very similar to 'mp4'
96
+ }
97
+ return true;
98
+ }
99
+ exports.isMP4 = isMP4;
100
+ /**
101
+ * Determine if file content contains a valid 'ogg' file signature
102
+ *
103
+ * @param file File content represents in Array<number> / ArrayBuffer / Uint8Array
104
+ *
105
+ * @returns {boolean} True if found a signature of type 'ogg' in file content, otherwise false
106
+ */
107
+ function isOGG(file) {
108
+ const fileChunk = (0, utils_1.getFileChunk)(file);
109
+ return core_1.FileTypes.checkByFileType(fileChunk, "ogg");
110
+ }
111
+ exports.isOGG = isOGG;
112
+ /**
113
+ * Determine if file content contains a valid 'swf' file signature
114
+ *
115
+ * @param file File content represents in Array<number> / ArrayBuffer / Uint8Array
116
+ *
117
+ * @returns {boolean} True if found a signature of type 'swf' in file content, otherwise false
118
+ */
119
+ function isSWF(file) {
120
+ const fileChunk = (0, utils_1.getFileChunk)(file);
121
+ return core_1.FileTypes.checkByFileType(fileChunk, "swf");
122
+ }
123
+ exports.isSWF = isSWF;
124
+ /**
125
+ * Determine if file content contains a valid 'webm' file signature.
126
+ * Since 'mkv' and 'webm' share the same signature - additional check required - search for the presence of the "DocType" element in the webm header
127
+ *
128
+ * @param file File content represents in Array<number> / ArrayBuffer / Uint8Array
129
+ *
130
+ * @returns {boolean} True if found a signature of type 'webm' & "ftyp" string in file content, otherwise false
131
+ */
132
+ function isWEBM(file) {
133
+ const fileChunk = (0, utils_1.getFileChunk)(file, 64); // Check the first 64 bytes of the file
134
+ const isWebmSignature = core_1.FileTypes.checkByFileType(fileChunk, "webm");
135
+ if (!isWebmSignature)
136
+ return false;
137
+ // Search for the presence of the "DocType" element in the webm header
138
+ return (0, utils_1.findMatroskaDocTypeElements)(fileChunk) === "webm";
139
+ }
140
+ exports.isWEBM = isWEBM;
package/package.json ADDED
@@ -0,0 +1,97 @@
1
+ {
2
+ "name": "sigcheck",
3
+ "version": "1.0.1",
4
+ "description": "Detect and validate file types by their signatures (✨magic numbers✨)",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "files": [
8
+ "dist"
9
+ ],
10
+ "scripts": {
11
+ "build": "tsc --declaration",
12
+ "lint": "yarn eslint .",
13
+ "test": "jest --config jest.config.js"
14
+ },
15
+ "repository": {
16
+ "type": "git"
17
+ },
18
+ "keywords": [
19
+ "file",
20
+ "type",
21
+ "checker",
22
+ "signature",
23
+ "magic",
24
+ "numbers",
25
+ "detect",
26
+ "validate",
27
+ "7z",
28
+ "aac",
29
+ "amr",
30
+ "avi",
31
+ "bmp",
32
+ "bpg",
33
+ "blend",
34
+ "cr2",
35
+ "doc",
36
+ "elf",
37
+ "exe",
38
+ "exr",
39
+ "flac",
40
+ "flv",
41
+ "gif",
42
+ "heic",
43
+ "ico",
44
+ "indd",
45
+ "jpeg",
46
+ "lzh",
47
+ "m4a",
48
+ "m4v",
49
+ "mach-o",
50
+ "mkv",
51
+ "mov",
52
+ "mp3",
53
+ "mp4",
54
+ "ogg",
55
+ "orc",
56
+ "parquet",
57
+ "pbm",
58
+ "pcap",
59
+ "pdf",
60
+ "pgm",
61
+ "png",
62
+ "ppm",
63
+ "psd",
64
+ "ps",
65
+ "rar",
66
+ "rtf",
67
+ "sqlite",
68
+ "stl",
69
+ "swf",
70
+ "tiff",
71
+ "ttf",
72
+ "wav",
73
+ "webm",
74
+ "webp",
75
+ "zip"
76
+ ],
77
+ "author": "Anas",
78
+ "license": "MIT",
79
+ "engines": {
80
+ "node": ">=18.0.0"
81
+ },
82
+ "resolutions": {
83
+ "@istanbuljs/schema/js-yaml": "3.14.2",
84
+ "js-yaml": "4.1.1"
85
+ },
86
+ "devDependencies": {
87
+ "@types/jest": "^29.4.0",
88
+ "@types/node": "^18.11.18",
89
+ "@typescript-eslint/eslint-plugin": "^6.2.0",
90
+ "@typescript-eslint/parser": "^6.2.0",
91
+ "eslint": "^8.45.0",
92
+ "eslint-plugin-jest": "^27.2.3",
93
+ "jest": "^29.7.0",
94
+ "ts-jest": "^29.0.5",
95
+ "typescript": "^5.1.6"
96
+ }
97
+ }