@react-fabric/utilities 1.0.0-beta.8 → 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 (168) hide show
  1. package/dist/cjs/css/boundingBox.js +72 -0
  2. package/dist/cjs/css/cn.js +39 -0
  3. package/dist/cjs/css/imageColorset.js +96 -0
  4. package/dist/cjs/data/countries.js +98 -0
  5. package/dist/cjs/{_fileType.js → data/fileType.js} +37 -19
  6. package/dist/cjs/data/format.js +136 -0
  7. package/dist/cjs/helpers/debounce.js +63 -0
  8. package/dist/cjs/{useLogger.js → helpers/getLogger.js} +96 -96
  9. package/dist/cjs/helpers/lonlat.js +99 -0
  10. package/dist/cjs/index.js +99 -76
  11. package/dist/cjs/lists/dedupe.js +54 -0
  12. package/dist/cjs/lists/flatten.js +66 -0
  13. package/dist/cjs/{_getByPath.js → lists/getByPath.js} +58 -37
  14. package/dist/cjs/lists/groupBy.js +49 -0
  15. package/dist/cjs/matchers/compare.js +70 -0
  16. package/dist/cjs/matchers/isEmpty.js +34 -0
  17. package/dist/cjs/matchers/isEqual.js +82 -0
  18. package/dist/cjs/matchers/nullChecks.js +61 -0
  19. package/dist/cjs/matchers/typeChecks.js +127 -0
  20. package/dist/cjs/strings/ascii.js +105 -0
  21. package/dist/cjs/strings/hash.js +75 -0
  22. package/dist/cjs/strings/interpolate.js +47 -0
  23. package/dist/cjs/strings/matchString.js +54 -0
  24. package/dist/cjs/strings/template.js +48 -0
  25. package/dist/cjs/strings/tokenize.js +83 -0
  26. package/dist/cjs/utils/mergeRefs.js +56 -0
  27. package/dist/esm/css/boundingBox.js +71 -0
  28. package/dist/esm/css/cn.js +39 -0
  29. package/dist/esm/css/imageColorset.js +96 -0
  30. package/dist/esm/data/countries.js +98 -0
  31. package/dist/esm/{_fileType.js → data/fileType.js} +37 -19
  32. package/dist/esm/data/format.js +138 -0
  33. package/dist/esm/helpers/debounce.js +63 -0
  34. package/dist/esm/{useLogger.js → helpers/getLogger.js} +96 -96
  35. package/dist/esm/helpers/lonlat.js +97 -0
  36. package/dist/esm/index.js +54 -36
  37. package/dist/esm/lists/dedupe.js +54 -0
  38. package/dist/esm/lists/flatten.js +65 -0
  39. package/dist/esm/{_getByPath.js → lists/getByPath.js} +50 -29
  40. package/dist/esm/lists/groupBy.js +49 -0
  41. package/dist/esm/matchers/compare.js +70 -0
  42. package/dist/esm/matchers/isEmpty.js +34 -0
  43. package/dist/esm/matchers/isEqual.js +82 -0
  44. package/dist/esm/matchers/nullChecks.js +58 -0
  45. package/dist/esm/matchers/typeChecks.js +119 -0
  46. package/dist/esm/strings/ascii.js +105 -0
  47. package/dist/esm/strings/hash.js +73 -0
  48. package/dist/esm/strings/interpolate.js +47 -0
  49. package/dist/esm/strings/matchString.js +54 -0
  50. package/dist/esm/strings/template.js +48 -0
  51. package/dist/esm/strings/tokenize.js +82 -0
  52. package/dist/esm/utils/mergeRefs.js +56 -0
  53. package/dist/types/css/boundingBox.d.ts +46 -0
  54. package/dist/types/css/cn.d.ts +26 -0
  55. package/dist/types/css/imageColorset.d.ts +37 -0
  56. package/dist/types/data/countries.d.ts +136 -0
  57. package/dist/types/{_fileType.d.ts → data/fileType.d.ts} +41 -1
  58. package/dist/types/data/format.d.ts +122 -0
  59. package/dist/types/helpers/debounce.d.ts +38 -0
  60. package/dist/types/helpers/getLogger.d.ts +49 -0
  61. package/dist/types/helpers/lonlat.d.ts +48 -0
  62. package/dist/types/index.d.ts +54 -20
  63. package/dist/types/lists/dedupe.d.ts +36 -0
  64. package/dist/types/lists/flatten.d.ts +47 -0
  65. package/dist/types/lists/getByPath.d.ts +45 -0
  66. package/dist/types/lists/groupBy.d.ts +36 -0
  67. package/dist/types/matchers/compare.d.ts +38 -0
  68. package/dist/types/matchers/isEmpty.d.ts +38 -0
  69. package/dist/types/matchers/isEqual.d.ts +39 -0
  70. package/dist/types/matchers/nullChecks.d.ts +43 -0
  71. package/dist/types/matchers/typeChecks.d.ts +107 -0
  72. package/dist/types/strings/ascii.d.ts +34 -0
  73. package/dist/types/strings/hash.d.ts +46 -0
  74. package/dist/types/strings/interpolate.d.ts +34 -0
  75. package/dist/types/strings/matchString.d.ts +41 -0
  76. package/dist/types/strings/template.d.ts +35 -0
  77. package/dist/types/strings/tokenize.d.ts +44 -0
  78. package/dist/types/utils/mergeRefs.d.ts +36 -0
  79. package/package.json +13 -11
  80. package/src/css/boundingBox.ts +80 -0
  81. package/src/css/cn.ts +32 -0
  82. package/src/css/imageColorset.ts +97 -0
  83. package/src/data/countries.ts +126 -0
  84. package/src/{_fileType.ts → data/fileType.ts} +72 -89
  85. package/src/data/format.ts +192 -0
  86. package/src/helpers/debounce.ts +49 -0
  87. package/src/{useLogger.ts → helpers/getLogger.ts} +52 -101
  88. package/src/helpers/lonlat.ts +124 -0
  89. package/src/index.ts +57 -37
  90. package/src/lists/dedupe.ts +46 -0
  91. package/src/lists/flatten.ts +56 -0
  92. package/src/lists/getByPath.ts +122 -0
  93. package/src/lists/groupBy.ts +47 -0
  94. package/src/matchers/compare.ts +64 -0
  95. package/src/matchers/isEmpty.ts +54 -0
  96. package/src/matchers/isEqual.ts +71 -0
  97. package/src/matchers/nullChecks.ts +55 -0
  98. package/src/matchers/typeChecks.ts +146 -0
  99. package/src/strings/ascii.ts +100 -0
  100. package/src/strings/hash.ts +68 -0
  101. package/src/strings/interpolate.ts +42 -0
  102. package/src/strings/matchString.ts +49 -0
  103. package/src/strings/template.ts +43 -0
  104. package/src/strings/tokenize.ts +77 -0
  105. package/src/utils/mergeRefs.ts +47 -0
  106. package/src/{yup.ts → utils/yup.ts} +3 -3
  107. package/dist/cjs/_ascii.js +0 -76
  108. package/dist/cjs/_boundingBox.js +0 -59
  109. package/dist/cjs/_countries.js +0 -2805
  110. package/dist/cjs/_debounce.js +0 -53
  111. package/dist/cjs/_dedupe.js +0 -63
  112. package/dist/cjs/_fetch.js +0 -128
  113. package/dist/cjs/_format.js +0 -118
  114. package/dist/cjs/_hash.js +0 -67
  115. package/dist/cjs/_interpolate.js +0 -47
  116. package/dist/cjs/_isEqual.js +0 -108
  117. package/dist/cjs/_isType.js +0 -98
  118. package/dist/cjs/_mergeRefs.js +0 -40
  119. package/dist/cjs/_tokenize.js +0 -67
  120. package/dist/cjs/getImageColorset.js +0 -70
  121. package/dist/esm/_ascii.js +0 -76
  122. package/dist/esm/_boundingBox.js +0 -58
  123. package/dist/esm/_countries.js +0 -2805
  124. package/dist/esm/_debounce.js +0 -53
  125. package/dist/esm/_dedupe.js +0 -60
  126. package/dist/esm/_fetch.js +0 -128
  127. package/dist/esm/_format.js +0 -120
  128. package/dist/esm/_hash.js +0 -65
  129. package/dist/esm/_interpolate.js +0 -46
  130. package/dist/esm/_isEqual.js +0 -106
  131. package/dist/esm/_isType.js +0 -85
  132. package/dist/esm/_mergeRefs.js +0 -40
  133. package/dist/esm/_tokenize.js +0 -66
  134. package/dist/esm/getImageColorset.js +0 -70
  135. package/dist/types/_ascii.d.ts +0 -5
  136. package/dist/types/_boundingBox.d.ts +0 -10
  137. package/dist/types/_countries.d.ts +0 -85
  138. package/dist/types/_debounce.d.ts +0 -8
  139. package/dist/types/_dedupe.d.ts +0 -4
  140. package/dist/types/_fetch.d.ts +0 -23
  141. package/dist/types/_format.d.ts +0 -27
  142. package/dist/types/_getByPath.d.ts +0 -10
  143. package/dist/types/_hash.d.ts +0 -16
  144. package/dist/types/_interpolate.d.ts +0 -6
  145. package/dist/types/_isEqual.d.ts +0 -15
  146. package/dist/types/_isType.d.ts +0 -14
  147. package/dist/types/_mergeRefs.d.ts +0 -1
  148. package/dist/types/_tokenize.d.ts +0 -8
  149. package/dist/types/getImageColorset.d.ts +0 -1
  150. package/dist/types/useLogger.d.ts +0 -25
  151. package/src/_ascii.ts +0 -93
  152. package/src/_boundingBox.ts +0 -72
  153. package/src/_countries.ts +0 -3046
  154. package/src/_debounce.ts +0 -42
  155. package/src/_dedupe.ts +0 -56
  156. package/src/_fetch.ts +0 -109
  157. package/src/_format.ts +0 -141
  158. package/src/_getByPath.ts +0 -108
  159. package/src/_hash.ts +0 -62
  160. package/src/_interpolate.ts +0 -42
  161. package/src/_isEqual.ts +0 -102
  162. package/src/_isType.ts +0 -105
  163. package/src/_mergeRefs.ts +0 -33
  164. package/src/_tokenize.ts +0 -69
  165. package/src/getImageColorset.ts +0 -81
  166. /package/dist/cjs/{yup.js → utils/yup.js} +0 -0
  167. /package/dist/esm/{yup.js → utils/yup.js} +0 -0
  168. /package/dist/types/{yup.d.ts → utils/yup.d.ts} +0 -0
@@ -0,0 +1,97 @@
1
+ /**
2
+ * React Fabric
3
+ * @version 1.0.0
4
+ * @license MIT
5
+ * @copyright 2024 Adarsh Pastakia
6
+ *
7
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ * of this software and associated documentation files (the "Software"), to deal
9
+ * in the Software without restriction, including without limitation the rights
10
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ * copies of the Software, and to permit persons to whom the Software is
12
+ * furnished to do so, subject to the following conditions:
13
+ *
14
+ * The above copyright notice and this permission notice shall be included in all
15
+ * copies or substantial portions of the Software.
16
+ *
17
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
+ * SOFTWARE.
24
+ */
25
+
26
+ /* istanbul ignore file */
27
+ /* eslint-disable @typescript-eslint/no-unused-expressions */
28
+
29
+ import chroma from "chroma-js";
30
+
31
+ /**
32
+ * Get the color set of an image element.
33
+ * This function analyzes the pixel data of an image to determine if it is predominantly light or dark.
34
+ * It returns "light", "dark", or "light_transparent"/"dark_transparent" based on the pixel analysis.
35
+ * It uses a canvas to draw the image and extract pixel data for analysis.
36
+ * * The function calculates the brightness of each pixel using the formula:
37
+ * brightness = 0.2126 * R + 0.7152 * G + 0.0722 * B
38
+ * * It counts the number of light and dark pixels, and determines the overall color set based on the ratio of light to dark pixels.
39
+ * * If the image has transparent pixels, it appends "_transparent" to the result.
40
+ * * This function is useful for determining the color scheme of an image, which can be helpful for UI design,
41
+ * theming, and accessibility considerations.
42
+ */
43
+ export function getImageColorset(el: HTMLImageElement, transparentOnly = false) {
44
+ // create canvas
45
+ const canvas = document.createElement("canvas");
46
+ canvas.width = Math.min(500, el.naturalWidth);
47
+ canvas.height = Math.min(500, el.naturalHeight);
48
+
49
+ const ctx = canvas.getContext("2d");
50
+ if (ctx != null) {
51
+ ctx.drawImage(el, 0, 0, el.naturalWidth, el.naturalHeight, 0, 0, canvas.width, canvas.height);
52
+
53
+ const imageData = ctx.getImageData(0, 0, canvas.width, canvas.height);
54
+ const data = imageData.data;
55
+ let r, g, b;
56
+ let dark = 0;
57
+ let light = 0;
58
+ let totalPixels = 0;
59
+ let transparent = data?.[3] === 0;
60
+
61
+ for (let x = 0, len = data.length; x < len; x += 4) {
62
+ if (transparentOnly && data[x + 3] / 255 > 0.9) {
63
+ continue;
64
+ }
65
+ if (data[x + 3] === 0) {
66
+ transparent = true;
67
+ continue;
68
+ }
69
+ if (data[x + 3] < 255) {
70
+ transparent = true;
71
+ }
72
+ r = data[x];
73
+ g = data[x + 1];
74
+ b = data[x + 2];
75
+ const l = chroma([r, g, b]).lab()[0];
76
+ if (transparentOnly) {
77
+ l < 35 && (dark++, totalPixels++);
78
+ l > 65 && (light++, totalPixels++);
79
+ } else {
80
+ l < 50 && (dark++, totalPixels++);
81
+ l >= 50 && (light++, totalPixels++);
82
+ }
83
+ }
84
+ if (totalPixels === 0) return "auto";
85
+ const diff = light / totalPixels - dark / totalPixels;
86
+ let ret = diff > 0 ? "light" : "dark";
87
+ if (!transparentOnly && transparent) {
88
+ ret += "_transparent";
89
+ }
90
+ return ret;
91
+ }
92
+ return "light";
93
+ }
94
+
95
+ if (typeof window !== "undefined")
96
+ // @ts-expect-error ignore
97
+ window.getImageColorset = getImageColorset;
@@ -0,0 +1,126 @@
1
+ /**
2
+ * React Fabric
3
+ * @version 1.0.0
4
+ * @license MIT
5
+ * @copyright 2024 Adarsh Pastakia
6
+ *
7
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ * of this software and associated documentation files (the "Software"), to deal
9
+ * in the Software without restriction, including without limitation the rights
10
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ * copies of the Software, and to permit persons to whom the Software is
12
+ * furnished to do so, subject to the following conditions:
13
+ *
14
+ * The above copyright notice and this permission notice shall be included in all
15
+ * copies or substantial portions of the Software.
16
+ *
17
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
+ * SOFTWARE.
24
+ */
25
+
26
+ /* istanbul ignore file */
27
+
28
+ import worldCountries, { type Country as _Ctry } from "world-countries";
29
+
30
+ export type Country = _Ctry & {
31
+ alpha: string;
32
+ phone: string;
33
+ iconCode: string;
34
+ currency: { code: string; name?: string; symbol?: string };
35
+ };
36
+
37
+ /**
38
+ * Country list with helper functions
39
+ * This is a list of all countries with their details.
40
+ * It includes information such as continent, ISO codes, name, full name, capital, top-level domain (TLD), currency, phone code, and emoji.
41
+ * This list can be used to retrieve country information based on various codes or names.
42
+ * @type {Country[]}
43
+ */
44
+ export default {
45
+ /**
46
+ * Get ISO2 country code
47
+ *
48
+ * @param code - The country code to search for. It can be an ISO2 code, ISO3 code, or an alternative code.
49
+ * @return {string | undefined} - Returns the ISO2 country code if found, otherwise undefined.
50
+ */
51
+ toIso2(code: string): string | undefined {
52
+ const ctry = this.find(code);
53
+ return ctry != null ? ctry.cca2 : undefined;
54
+ },
55
+ /**
56
+ * Get ISO3 country code
57
+ *
58
+ * @param code - The country code to search for. It can be an ISO2 code, ISO3 code, or an alternative code.
59
+ * @return {string | undefined} - Returns the ISO3 country code if found, otherwise undefined.
60
+ */
61
+ toIso3(code: string): string | undefined {
62
+ const ctry = this.find(code);
63
+ return ctry != null ? ctry.cca3 : undefined;
64
+ },
65
+ /**
66
+ * Get country emoji
67
+ *
68
+ * @param code - The country code to search for. It can be an ISO2 code, ISO3 code, or an alternative code.
69
+ * @return {string} - Returns the emoji representation of the country if found, otherwise returns a default flag emoji.
70
+ */
71
+ emoji(code: string): string {
72
+ const ctry = this.find(code);
73
+ return ctry != null ? ctry.flag : "🏳️";
74
+ },
75
+ /**
76
+ * Get country name
77
+ *
78
+ * @param code - The country code to search for. It can be an ISO2 code, ISO3 code, or an alternative code.
79
+ * @return {string} - Returns the name of the country if found, otherwise returns the code itself.
80
+ */
81
+ name: function (code: string): string {
82
+ const ctry = this.find(code);
83
+ return ctry != null ? ctry.name.common : code;
84
+ },
85
+ /**
86
+ * This function searches for a country in the list by its code.
87
+ * It supports various formats:
88
+ * - ISO2 code (e.g., "US")
89
+ * - ISO3 code (e.g., "USA")
90
+ * - Alternative code (e.g., "US", "USA", "United States")
91
+ * It returns the first matching country object or undefined if not found.
92
+ * This function is useful for retrieving country details based on different code formats.
93
+ *
94
+ * @param code - The country code to search for. It can be an ISO2 code, ISO3 code, or an alternative code.
95
+ * @return {Country | undefined} - Returns the country object if found, otherwise undefined.
96
+ */
97
+ find(code: string): Country | undefined {
98
+ return this.list.find(
99
+ (ct) =>
100
+ (ct.cioc ?? "__").toLowerCase() === code.toLowerCase() ||
101
+ ct.cca2.toLowerCase() === code.toLowerCase() ||
102
+ ct.cca3.toLowerCase() === code.toLowerCase(),
103
+ );
104
+ },
105
+ /**
106
+ * Country list
107
+ * This is a list of all countries with their details.
108
+ * It includes information such as continent, ISO codes, name, full name, capital, top-level domain (TLD), currency, phone code, and emoji.
109
+ * This list can be used to retrieve country information based on various codes or names.
110
+ *
111
+ * @type {Country[]}
112
+ */
113
+ list: worldCountries.map((ct) => ({
114
+ ...ct,
115
+ iconCode: ct.cca2.toLowerCase(),
116
+ alpha: ct.name.common.charAt(0),
117
+ phone: `${ct.idd.root}${ct.idd.suffixes?.[0] ?? ""}`,
118
+ region: ct.region === "Americas" ? ct.subregion : ct.region,
119
+ currency: ct.currencies
120
+ ? {
121
+ ...Object.entries(ct.currencies).pop()?.[1],
122
+ code: `${Object.entries(ct.currencies).pop()?.[0]}`,
123
+ }
124
+ : { code: "UNK" },
125
+ })),
126
+ };
@@ -1,37 +1,55 @@
1
- /*
1
+ /**
2
2
  * React Fabric
3
- * @version: 1.0.0
3
+ * @version 1.0.0
4
+ * @license MIT
5
+ * @copyright 2024 Adarsh Pastakia
4
6
  *
7
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ * of this software and associated documentation files (the "Software"), to deal
9
+ * in the Software without restriction, including without limitation the rights
10
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ * copies of the Software, and to permit persons to whom the Software is
12
+ * furnished to do so, subject to the following conditions:
5
13
  *
6
- * The MIT License (MIT)
7
- * Copyright (c) 2024 Adarsh Pastakia
14
+ * The above copyright notice and this permission notice shall be included in all
15
+ * copies or substantial portions of the Software.
8
16
  *
9
- * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
10
- * and associated documentation files (the "Software"), to deal in the Software without restriction,
11
- * including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
12
- * and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
13
- * subject to the following conditions:
14
- *
15
- * The above copyright notice and this permission notice shall be included in all copies or substantial
16
- * portions of the Software.
17
- *
18
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
19
- * TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20
- * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21
- * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
17
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
+ * SOFTWARE.
22
24
  */
23
25
 
24
26
  /* istanbul ignore file */
25
27
 
28
+ /**
29
+ * File type utility to get the file type from a MIME type.
30
+ * This utility provides a mapping of common MIME types to their human-readable names.
31
+ * It can be used to display file types in a user-friendly manner.
32
+ */
26
33
  export default {
27
- mime(mime: string = "") {
28
- const ret = (this.mimeList as KeyValue)[mime.split(";")[0]];
34
+ /**
35
+ * Get the human-readable file type from a MIME type.
36
+ * This method looks up the MIME type in a predefined list
37
+ * and returns a user-friendly name.
38
+ *
39
+ * @param mime MIME type string, e.g. "application/pdf"
40
+ * @returns {string} - The human-readable file type.
41
+ */
42
+ mime(mime: string = ""): string {
43
+ const ret = (this.mimeList as KeyValue)[mime.split(";")[0]] as string;
29
44
  if (!ret && !!mime) {
30
45
  const [t, e] = mime.split("/");
31
46
  return `${t} (${e})`;
32
47
  }
33
48
  return ret || "Unknown type";
34
49
  },
50
+ /**
51
+ * List of common MIME types and their human-readable names.
52
+ */
35
53
  mimeList: {
36
54
  "application/x-tika-msoffice": "Microsft Office File",
37
55
  "application/x-tika-ooxml": "Open Office File",
@@ -143,8 +161,7 @@ export default {
143
161
  "application/vnd.comicbook-rar": "Comic Book Archive",
144
162
  "application/vnd.cups-raster": "CUPS Raster",
145
163
  "application/vnd.debian.binary-package": "Deb",
146
- "application/vnd.etsi.asic-e+zip":
147
- "Extended Associated Signature Container",
164
+ "application/vnd.etsi.asic-e+zip": "Extended Associated Signature Container",
148
165
  "application/vnd.etsi.asic-s+zip": "Simple Associated Signature Container",
149
166
  "application/vnd.fdf": "FDF",
150
167
  "application/vnd.font-fontforge-sfd": "Spline Font Database",
@@ -187,31 +204,20 @@ export default {
187
204
  "application/vnd.ms-outlook-pst": "Outlook Personal Folders File Format",
188
205
  "application/vnd.ms-package.3dmanufacturing-3dmodel+xml": "3MF",
189
206
  "application/vnd.ms-powerpoint": "Powerpoint Presentation",
190
- "application/vnd.ms-powerpoint.addin.macroenabled.12":
191
- "Microsoft PowerPoint",
192
- "application/vnd.ms-powerpoint.presentation.macroenabled.12":
193
- "Microsoft PowerPoint",
194
- "application/vnd.ms-powerpoint.slide.macroenabled.12":
195
- "Microsoft PowerPoint",
196
- "application/vnd.ms-powerpoint.slideshow.macroenabled.12":
197
- "Microsoft PowerPoint",
198
- "application/vnd.ms-powerpoint.template.macroenabled.12":
199
- "Microsoft PowerPoint",
207
+ "application/vnd.ms-powerpoint.addin.macroenabled.12": "Microsoft PowerPoint",
208
+ "application/vnd.ms-powerpoint.presentation.macroenabled.12": "Microsoft PowerPoint",
209
+ "application/vnd.ms-powerpoint.slide.macroenabled.12": "Microsoft PowerPoint",
210
+ "application/vnd.ms-powerpoint.slideshow.macroenabled.12": "Microsoft PowerPoint",
211
+ "application/vnd.ms-powerpoint.template.macroenabled.12": "Microsoft PowerPoint",
200
212
  "application/vnd.ms-printing.printticket+xml": "3MF",
201
213
  "application/vnd.ms-tnef": "Transport Neutral Encapsulation Format",
202
214
  "application/vnd.ms-visio": "Microsoft Visio Diagram",
203
- "application/vnd.ms-visio.drawing":
204
- "Office Open XML Visio Drawing (macro-free)",
205
- "application/vnd.ms-visio.drawing.macroenabled.12":
206
- "Office Open XML Visio Drawing (macro-enabled)",
207
- "application/vnd.ms-visio.stencil":
208
- "Office Open XML Visio Stencil (macro-free)",
209
- "application/vnd.ms-visio.stencil.macroenabled.12":
210
- "Office Open XML Visio Stencil (macro-enabled)",
211
- "application/vnd.ms-visio.template":
212
- "Office Open XML Visio Template (macro-free)",
213
- "application/vnd.ms-visio.template.macroenabled.12":
214
- "Office Open XML Visio Template (macro-enabled)",
215
+ "application/vnd.ms-visio.drawing": "Office Open XML Visio Drawing (macro-free)",
216
+ "application/vnd.ms-visio.drawing.macroenabled.12": "Office Open XML Visio Drawing (macro-enabled)",
217
+ "application/vnd.ms-visio.stencil": "Office Open XML Visio Stencil (macro-free)",
218
+ "application/vnd.ms-visio.stencil.macroenabled.12": "Office Open XML Visio Stencil (macro-enabled)",
219
+ "application/vnd.ms-visio.template": "Office Open XML Visio Template (macro-free)",
220
+ "application/vnd.ms-visio.template.macroenabled.12": "Office Open XML Visio Template (macro-enabled)",
215
221
  "application/vnd.ms-word": "Word Document",
216
222
  "application/vnd.ms-word.document.macroenabled.12": "Microsoft Word",
217
223
  "application/vnd.ms-word.template.macroenabled.12": "Microsoft Word",
@@ -228,8 +234,7 @@ export default {
228
234
  "application/vnd.oasis.opendocument.image": "OD Image",
229
235
  "application/vnd.oasis.opendocument.image-template": "OD Image template",
230
236
  "application/vnd.oasis.opendocument.presentation": "OD Presentation",
231
- "application/vnd.oasis.opendocument.presentation-template":
232
- "OD Presentation Template",
237
+ "application/vnd.oasis.opendocument.presentation-template": "OD Presentation Template",
233
238
  "application/vnd.oasis.opendocument.spreadsheet": "OD Spreadsheet",
234
239
  "application/vnd.oasis.opendocument.spreadsheet-template": "OD Spreadsheet",
235
240
  "application/vnd.oasis.opendocument.text": "OD Text",
@@ -238,22 +243,14 @@ export default {
238
243
  "application/vnd.oasis.opendocument.text-web": "OD Text",
239
244
  "application/vnd.openxmlformats-officedocument.presentationml.document":
240
245
  "OOXML Format Family -- ISO/IEC 29500 and ECMA 376",
241
- "application/vnd.openxmlformats-officedocument.presentationml.presentation":
242
- "Powerpoint Presentation",
243
- "application/vnd.openxmlformats-officedocument.presentationml.slideshow":
244
- "Microsoft PowerPoint",
245
- "application/vnd.openxmlformats-officedocument.presentationml.template":
246
- "Microsoft PowerPoint",
247
- "application/vnd.openxmlformats-officedocument.spreadsheetml.document":
248
- "OOXML Format Family -- ISO/IEC 29500 and ECMA 376",
249
- "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet":
250
- "Excel Spreadsheet",
251
- "application/vnd.openxmlformats-officedocument.spreadsheetml.template":
252
- "Microsoft Excel",
253
- "application/vnd.openxmlformats-officedocument.wordprocessingml.document":
254
- "Word Document",
255
- "application/vnd.openxmlformats-officedocument.wordprocessingml.template":
256
- "Microsoft Word",
246
+ "application/vnd.openxmlformats-officedocument.presentationml.presentation": "Powerpoint Presentation",
247
+ "application/vnd.openxmlformats-officedocument.presentationml.slideshow": "Microsoft PowerPoint",
248
+ "application/vnd.openxmlformats-officedocument.presentationml.template": "Microsoft PowerPoint",
249
+ "application/vnd.openxmlformats-officedocument.spreadsheetml.document": "OOXML Format Family -- ISO/IEC 29500 and ECMA 376",
250
+ "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet": "Excel Spreadsheet",
251
+ "application/vnd.openxmlformats-officedocument.spreadsheetml.template": "Microsoft Excel",
252
+ "application/vnd.openxmlformats-officedocument.wordprocessingml.document": "Word Document",
253
+ "application/vnd.openxmlformats-officedocument.wordprocessingml.template": "Microsoft Word",
257
254
  "application/vnd.pagemaker": "Pagemaker Document (Generic)",
258
255
  "application/vnd.palm": "Palm OS Database",
259
256
  "application/vnd.pdf": "PDF Family",
@@ -296,10 +293,8 @@ export default {
296
293
  "application/warc": "WARC",
297
294
  "application/warc-fields": "WARC",
298
295
  "application/x--iworks-protected": "Password Protected iWorks File",
299
- "application/x--msoffice-embedded;format=comp_obj":
300
- "CompObj OLE2 Embedded Document",
301
- "application/x--msoffice-embedded;format=ole10_native":
302
- "OLE10 Native Embedded Document",
296
+ "application/x--msoffice-embedded;format=comp_obj": "CompObj OLE2 Embedded Document",
297
+ "application/x--msoffice-embedded;format=ole10_native": "OLE10 Native Embedded Document",
303
298
  "application/x--old-excel": "Pre-OLE2 (Old) Microsoft Excel Worksheets",
304
299
  "application/x--ooxml-protected": "Password Protected OOXML File",
305
300
  "application/x--visio-ooxml": "Visio OOXML File",
@@ -308,8 +303,7 @@ export default {
308
303
  "application/x-7z-compressed": "7z Archive",
309
304
  "application/x-acad": "DWG",
310
305
  "application/x-adobe-indesign": "Adobe InDesign document",
311
- "application/x-adobe-indesign-interchange":
312
- "Adobe InDesign Interchange format",
306
+ "application/x-adobe-indesign-interchange": "Adobe InDesign Interchange format",
313
307
  "application/x-apple-diskimage": "Apple Disk Image",
314
308
  "application/x-aspx": "ASP.NET",
315
309
  "application/x-astrotite-afa": "Astrotite",
@@ -365,8 +359,7 @@ export default {
365
359
  "application/x-gca-compressed": "GCA",
366
360
  "application/x-glulx": "Glulx",
367
361
  "application/x-gnumeric": "Gnumeric",
368
- "application/x-grib":
369
- "General Regularly-distributed Information in Binary form",
362
+ "application/x-grib": "General Regularly-distributed Information in Binary form",
370
363
  "application/x-gtar": "GNU Archive",
371
364
  "application/x-gunzip": "Gzip Compressed Archive",
372
365
  "application/x-gzip": "Gzip",
@@ -415,8 +408,7 @@ export default {
415
408
  "application/x-msi": "Microsoft Windows Installer",
416
409
  "application/x-msmetafile": "Windows Metafile",
417
410
  "application/x-mso": "ActiveMime",
418
- "application/x-mysql-misam-compressed-index":
419
- "MySQL MISAM Compressed Index",
411
+ "application/x-mysql-misam-compressed-index": "MySQL MISAM Compressed Index",
420
412
  "application/x-mysql-misam-data": "MySQL MISAM Data",
421
413
  "application/x-mysql-misam-index": "MySQL MISAM Index",
422
414
  "application/x-mysql-table-definition": "MySQL Table Definition (Format)",
@@ -471,14 +463,10 @@ export default {
471
463
  "application/x-tex": "TeX",
472
464
  "application/x-tif": "TIFF",
473
465
  "application/x-tiff": "TIFF",
474
- "application/x-troff":
475
- "Roff/nroff/troff/groff Unformatted Manual Page (UNIX)",
476
- "application/x-troff-man":
477
- "Roff/nroff/troff/groff Unformatted Manual Page (UNIX)",
478
- "application/x-troff-me":
479
- "Roff/nroff/troff/groff Unformatted Manual Page (UNIX)",
480
- "application/x-troff-ms":
481
- "Roff/nroff/troff/groff Unformatted Manual Page (UNIX)",
466
+ "application/x-troff": "Roff/nroff/troff/groff Unformatted Manual Page (UNIX)",
467
+ "application/x-troff-man": "Roff/nroff/troff/groff Unformatted Manual Page (UNIX)",
468
+ "application/x-troff-me": "Roff/nroff/troff/groff Unformatted Manual Page (UNIX)",
469
+ "application/x-troff-ms": "Roff/nroff/troff/groff Unformatted Manual Page (UNIX)",
482
470
  "application/x-troff-msvideo": "AVI (Audio Video Interleaved) File Format",
483
471
  "application/x-url": "Internet Shortcut",
484
472
  "application/x-vhd": "Virtual PC Virtual Hard Disk",
@@ -488,19 +476,15 @@ export default {
488
476
  "application/x-vnd.oasis.opendocument.chart": "OD Chart",
489
477
  "application/x-vnd.oasis.opendocument.chart-template": "OD Chart Template",
490
478
  "application/x-vnd.oasis.opendocument.formula": "OD Formula document",
491
- "application/x-vnd.oasis.opendocument.formula-template":
492
- "OD Formula Template",
479
+ "application/x-vnd.oasis.opendocument.formula-template": "OD Formula Template",
493
480
  "application/x-vnd.oasis.opendocument.graphics": "OD Graphics (Drawing)",
494
- "application/x-vnd.oasis.opendocument.graphics-template":
495
- "OD Graphics Template",
481
+ "application/x-vnd.oasis.opendocument.graphics-template": "OD Graphics Template",
496
482
  "application/x-vnd.oasis.opendocument.image": "OD Image",
497
483
  "application/x-vnd.oasis.opendocument.image-template": "OD Image Template",
498
484
  "application/x-vnd.oasis.opendocument.presentation": "OD Presentation",
499
- "application/x-vnd.oasis.opendocument.presentation-template":
500
- "OD Presentation Template",
485
+ "application/x-vnd.oasis.opendocument.presentation-template": "OD Presentation Template",
501
486
  "application/x-vnd.oasis.opendocument.spreadsheet": "OD Spreadsheet",
502
- "application/x-vnd.oasis.opendocument.spreadsheet-template":
503
- "OD Spreadsheet Template",
487
+ "application/x-vnd.oasis.opendocument.spreadsheet-template": "OD Spreadsheet Template",
504
488
  "application/x-vnd.oasis.opendocument.text": "OD Text",
505
489
  "application/x-vnd.oasis.opendocument.text-master": "OD Global Text",
506
490
  "application/x-vnd.oasis.opendocument.text-template": "OD Text Template",
@@ -797,8 +781,7 @@ export default {
797
781
  "text/vbscript": "VBScript",
798
782
  "text/vcard": "VCard",
799
783
  "text/vnd.ascii-art": "ASCII Art",
800
- "text/vnd.iptc.anpa":
801
- "American Newspaper Publishers Association Wire Feeds",
784
+ "text/vnd.iptc.anpa": "American Newspaper Publishers Association Wire Feeds",
802
785
  "text/vnd.iptc.nitf": "News Industry Text Format",
803
786
  "text/vnd.wap.wmlscript": "WML Script",
804
787
  "text/vtt": "WebVTT",