tiny-essentials 1.0.0

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 (302) hide show
  1. package/.github/FUNDING.yml +4 -0
  2. package/.github/workflows/node.js.yml +31 -0
  3. package/LICENSE +674 -0
  4. package/README.md +67 -0
  5. package/dist/TinyEssentials.min.js +1 -0
  6. package/dist/_virtual/_commonjsHelpers.cjs +7 -0
  7. package/dist/_virtual/common.cjs +5 -0
  8. package/dist/_virtual/index.cjs +9 -0
  9. package/dist/_virtual/index2.cjs +5 -0
  10. package/dist/_virtual/trace.cjs +5 -0
  11. package/dist/legacy/crypto/decrypt.cjs +57 -0
  12. package/dist/legacy/crypto/decrypt.d.mts +18 -0
  13. package/dist/legacy/crypto/decrypt.mjs +47 -0
  14. package/dist/legacy/crypto/default.cjs +23 -0
  15. package/dist/legacy/crypto/default.d.mts +35 -0
  16. package/dist/legacy/crypto/default.mjs +19 -0
  17. package/dist/legacy/crypto/encrypt.cjs +54 -0
  18. package/dist/legacy/crypto/encrypt.d.mts +19 -0
  19. package/dist/legacy/crypto/encrypt.mjs +46 -0
  20. package/dist/legacy/crypto/index.cjs +11 -0
  21. package/dist/legacy/crypto/index.d.mts +4 -0
  22. package/dist/legacy/crypto/index.mjs +6 -0
  23. package/dist/legacy/firebase/cookieSession.cjs +121 -0
  24. package/dist/legacy/firebase/cookieSession.d.mts +56 -0
  25. package/dist/legacy/firebase/cookieSession.mjs +114 -0
  26. package/dist/legacy/firebase/database/index.cjs +11 -0
  27. package/dist/legacy/firebase/database/index.d.mts +7 -0
  28. package/dist/legacy/firebase/database/index.mjs +7 -0
  29. package/dist/legacy/firebase/database/presence.cjs +131 -0
  30. package/dist/legacy/firebase/database/presence.d.mts +9 -0
  31. package/dist/legacy/firebase/database/presence.mjs +111 -0
  32. package/dist/legacy/firebase/database/saveAsync.cjs +147 -0
  33. package/dist/legacy/firebase/database/saveAsync.d.mts +54 -0
  34. package/dist/legacy/firebase/database/saveAsync.mjs +147 -0
  35. package/dist/legacy/firebase/databaseEscape.cjs +42 -0
  36. package/dist/legacy/firebase/databaseEscape.d.mts +11 -0
  37. package/dist/legacy/firebase/databaseEscape.mjs +37 -0
  38. package/dist/legacy/firebase/databaseLogger.cjs +258 -0
  39. package/dist/legacy/firebase/databaseLogger.d.mts +7 -0
  40. package/dist/legacy/firebase/databaseLogger.mjs +234 -0
  41. package/dist/legacy/firebase/discord/api/addGuildMember.cjs +71 -0
  42. package/dist/legacy/firebase/discord/api/addGuildMember.d.mts +38 -0
  43. package/dist/legacy/firebase/discord/api/addGuildMember.mjs +64 -0
  44. package/dist/legacy/firebase/discord/api/getGuildWidget.cjs +47 -0
  45. package/dist/legacy/firebase/discord/api/getGuildWidget.d.mts +17 -0
  46. package/dist/legacy/firebase/discord/api/getGuildWidget.mjs +43 -0
  47. package/dist/legacy/firebase/discord/api/getToken.cjs +67 -0
  48. package/dist/legacy/firebase/discord/api/getToken.d.mts +35 -0
  49. package/dist/legacy/firebase/discord/api/getToken.mjs +63 -0
  50. package/dist/legacy/firebase/discord/api/getUser.cjs +58 -0
  51. package/dist/legacy/firebase/discord/api/getUser.d.mts +27 -0
  52. package/dist/legacy/firebase/discord/api/getUser.mjs +54 -0
  53. package/dist/legacy/firebase/discord/api/getUserConnections.cjs +57 -0
  54. package/dist/legacy/firebase/discord/api/getUserConnections.d.mts +26 -0
  55. package/dist/legacy/firebase/discord/api/getUserConnections.mjs +53 -0
  56. package/dist/legacy/firebase/discord/api/getUserGuilds.cjs +56 -0
  57. package/dist/legacy/firebase/discord/api/getUserGuilds.d.mts +25 -0
  58. package/dist/legacy/firebase/discord/api/getUserGuilds.mjs +52 -0
  59. package/dist/legacy/firebase/discord/api/index.cjs +24 -0
  60. package/dist/legacy/firebase/discord/api/index.d.mts +19 -0
  61. package/dist/legacy/firebase/discord/api/index.mjs +20 -0
  62. package/dist/legacy/firebase/discord/api/refreshToken.cjs +77 -0
  63. package/dist/legacy/firebase/discord/api/refreshToken.d.mts +45 -0
  64. package/dist/legacy/firebase/discord/api/refreshToken.mjs +73 -0
  65. package/dist/legacy/firebase/discord/api/revokeToken.cjs +61 -0
  66. package/dist/legacy/firebase/discord/api/revokeToken.d.mts +29 -0
  67. package/dist/legacy/firebase/discord/api/revokeToken.mjs +58 -0
  68. package/dist/legacy/firebase/discord/config.cjs +21 -0
  69. package/dist/legacy/firebase/discord/config.d.mts +27 -0
  70. package/dist/legacy/firebase/discord/config.mjs +17 -0
  71. package/dist/legacy/firebase/discord/firebase_redirect/index.cjs +11 -0
  72. package/dist/legacy/firebase/discord/firebase_redirect/index.d.mts +7 -0
  73. package/dist/legacy/firebase/discord/firebase_redirect/index.mjs +7 -0
  74. package/dist/legacy/firebase/discord/firebase_redirect/login.cjs +110 -0
  75. package/dist/legacy/firebase/discord/firebase_redirect/login.d.mts +4 -0
  76. package/dist/legacy/firebase/discord/firebase_redirect/login.mjs +107 -0
  77. package/dist/legacy/firebase/discord/firebase_redirect/logout.cjs +100 -0
  78. package/dist/legacy/firebase/discord/firebase_redirect/logout.d.mts +4 -0
  79. package/dist/legacy/firebase/discord/firebase_redirect/logout.mjs +97 -0
  80. package/dist/legacy/firebase/discord/get/authURLGenerator.cjs +76 -0
  81. package/dist/legacy/firebase/discord/get/authURLGenerator.d.mts +23 -0
  82. package/dist/legacy/firebase/discord/get/authURLGenerator.mjs +67 -0
  83. package/dist/legacy/firebase/discord/get/cookie-session.cjs +32 -0
  84. package/dist/legacy/firebase/discord/get/cookie-session.d.mts +20 -0
  85. package/dist/legacy/firebase/discord/get/cookie-session.mjs +28 -0
  86. package/dist/legacy/firebase/discord/get/credentials.cjs +24 -0
  87. package/dist/legacy/firebase/discord/get/credentials.d.mts +19 -0
  88. package/dist/legacy/firebase/discord/get/credentials.mjs +20 -0
  89. package/dist/legacy/firebase/discord/get/errorValidator.cjs +60 -0
  90. package/dist/legacy/firebase/discord/get/errorValidator.d.mts +28 -0
  91. package/dist/legacy/firebase/discord/get/errorValidator.mjs +55 -0
  92. package/dist/legacy/firebase/discord/get/index.cjs +17 -0
  93. package/dist/legacy/firebase/discord/get/index.d.mts +13 -0
  94. package/dist/legacy/firebase/discord/get/index.mjs +13 -0
  95. package/dist/legacy/firebase/discord/get/randomAvatar.cjs +37 -0
  96. package/dist/legacy/firebase/discord/get/randomAvatar.d.mts +22 -0
  97. package/dist/legacy/firebase/discord/get/randomAvatar.mjs +30 -0
  98. package/dist/legacy/firebase/discord/http/index.cjs +15 -0
  99. package/dist/legacy/firebase/discord/http/index.d.mts +11 -0
  100. package/dist/legacy/firebase/discord/http/index.mjs +11 -0
  101. package/dist/legacy/firebase/discord/http/login.cjs +127 -0
  102. package/dist/legacy/firebase/discord/http/login.d.mts +21 -0
  103. package/dist/legacy/firebase/discord/http/login.mjs +123 -0
  104. package/dist/legacy/firebase/discord/http/logout.cjs +155 -0
  105. package/dist/legacy/firebase/discord/http/logout.d.mts +22 -0
  106. package/dist/legacy/firebase/discord/http/logout.mjs +143 -0
  107. package/dist/legacy/firebase/discord/http/redirect.cjs +188 -0
  108. package/dist/legacy/firebase/discord/http/redirect.d.mts +24 -0
  109. package/dist/legacy/firebase/discord/http/redirect.mjs +178 -0
  110. package/dist/legacy/firebase/discord/http/refreshToken.cjs +133 -0
  111. package/dist/legacy/firebase/discord/http/refreshToken.d.mts +24 -0
  112. package/dist/legacy/firebase/discord/http/refreshToken.mjs +121 -0
  113. package/dist/legacy/firebase/discord/index.cjs +19 -0
  114. package/dist/legacy/firebase/discord/index.d.mts +15 -0
  115. package/dist/legacy/firebase/discord/index.mjs +15 -0
  116. package/dist/legacy/firebase/discord/template/cookie-session.cjs +1430 -0
  117. package/dist/legacy/firebase/discord/template/cookie-session.d.mts +22 -0
  118. package/dist/legacy/firebase/discord/template/cookie-session.mjs +1159 -0
  119. package/dist/legacy/firebase/domainRedirect.cjs +35 -0
  120. package/dist/legacy/firebase/domainRedirect.d.mts +12 -0
  121. package/dist/legacy/firebase/domainRedirect.mjs +27 -0
  122. package/dist/legacy/firebase/escape.cjs +75 -0
  123. package/dist/legacy/firebase/escape.d.mts +17 -0
  124. package/dist/legacy/firebase/escape.mjs +58 -0
  125. package/dist/legacy/firebase/getDBAsync.cjs +33 -0
  126. package/dist/legacy/firebase/getDBAsync.d.mts +10 -0
  127. package/dist/legacy/firebase/getDBAsync.mjs +26 -0
  128. package/dist/legacy/firebase/getDBData.cjs +21 -0
  129. package/dist/legacy/firebase/getDBData.d.mts +1 -0
  130. package/dist/legacy/firebase/getDBData.mjs +17 -0
  131. package/dist/legacy/firebase/getDBValue.cjs +17 -0
  132. package/dist/legacy/firebase/getDBValue.d.mts +9 -0
  133. package/dist/legacy/firebase/getDBValue.mjs +14 -0
  134. package/dist/legacy/firebase/index.cjs +261 -0
  135. package/dist/legacy/firebase/index.d.mts +51 -0
  136. package/dist/legacy/firebase/index.mjs +234 -0
  137. package/dist/legacy/firebase/isEmulator.cjs +14 -0
  138. package/dist/legacy/firebase/isEmulator.d.mts +8 -0
  139. package/dist/legacy/firebase/isEmulator.mjs +10 -0
  140. package/dist/legacy/firebase/logger.cjs +137 -0
  141. package/dist/legacy/firebase/logger.d.mts +7 -0
  142. package/dist/legacy/firebase/logger.mjs +125 -0
  143. package/dist/legacy/firebase/mySQL.cjs +26 -0
  144. package/dist/legacy/firebase/mySQL.d.mts +10 -0
  145. package/dist/legacy/firebase/mySQL.mjs +22 -0
  146. package/dist/legacy/firebase/mysqlConnector/create.cjs +119 -0
  147. package/dist/legacy/firebase/mysqlConnector/create.d.mts +36 -0
  148. package/dist/legacy/firebase/mysqlConnector/create.mjs +109 -0
  149. package/dist/legacy/firebase/mysqlConnector/index.cjs +23 -0
  150. package/dist/legacy/firebase/mysqlConnector/index.d.mts +11 -0
  151. package/dist/legacy/firebase/mysqlConnector/index.mjs +16 -0
  152. package/dist/legacy/firebase/mysqlConnector/nextPrev.cjs +75 -0
  153. package/dist/legacy/firebase/mysqlConnector/nextPrev.d.mts +31 -0
  154. package/dist/legacy/firebase/mysqlConnector/nextPrev.mjs +63 -0
  155. package/dist/legacy/firebase/mysqlConnector/pagination.cjs +91 -0
  156. package/dist/legacy/firebase/mysqlConnector/pagination.d.mts +33 -0
  157. package/dist/legacy/firebase/mysqlConnector/pagination.mjs +87 -0
  158. package/dist/legacy/firebase/mysqlConnector/sameUser.cjs +28 -0
  159. package/dist/legacy/firebase/mysqlConnector/sameUser.d.mts +12 -0
  160. package/dist/legacy/firebase/mysqlConnector/sameUser.mjs +23 -0
  161. package/dist/legacy/firebase/transactionDBAsync.cjs +33 -0
  162. package/dist/legacy/firebase/transactionDBAsync.d.mts +11 -0
  163. package/dist/legacy/firebase/transactionDBAsync.mjs +27 -0
  164. package/dist/legacy/get/countObj.cjs +24 -0
  165. package/dist/legacy/get/countObj.d.mts +11 -0
  166. package/dist/legacy/get/countObj.mjs +21 -0
  167. package/dist/legacy/get/decimalColor.cjs +60 -0
  168. package/dist/legacy/get/decimalColor.d.mts +12 -0
  169. package/dist/legacy/get/decimalColor.mjs +54 -0
  170. package/dist/legacy/get/objType.cjs +43 -0
  171. package/dist/legacy/get/objType.d.mts +19 -0
  172. package/dist/legacy/get/objType.mjs +40 -0
  173. package/dist/legacy/get/pagination.cjs +100 -0
  174. package/dist/legacy/get/pagination.d.mts +25 -0
  175. package/dist/legacy/get/pagination.mjs +91 -0
  176. package/dist/legacy/get/queryUrlByName.cjs +31 -0
  177. package/dist/legacy/get/queryUrlByName.d.mts +20 -0
  178. package/dist/legacy/get/queryUrlByName.mjs +28 -0
  179. package/dist/legacy/get/queryUrlJSON.cjs +54 -0
  180. package/dist/legacy/get/queryUrlJSON.d.mts +23 -0
  181. package/dist/legacy/get/queryUrlJSON.mjs +57 -0
  182. package/dist/legacy/get/super_string_filter.cjs +97 -0
  183. package/dist/legacy/get/super_string_filter.d.mts +25 -0
  184. package/dist/legacy/get/super_string_filter.mjs +83 -0
  185. package/dist/legacy/get/versionCheck.cjs +49 -0
  186. package/dist/legacy/get/versionCheck.d.mts +17 -0
  187. package/dist/legacy/get/versionCheck.mjs +38 -0
  188. package/dist/legacy/http/HTTP-1.0.cjs +151 -0
  189. package/dist/legacy/http/HTTP-1.0.d.mts +8 -0
  190. package/dist/legacy/http/HTTP-1.0.mjs +136 -0
  191. package/dist/legacy/http/auth.cjs +70 -0
  192. package/dist/legacy/http/auth.d.mts +41 -0
  193. package/dist/legacy/http/auth.mjs +63 -0
  194. package/dist/legacy/http/check_domain.cjs +84 -0
  195. package/dist/legacy/http/check_domain.d.mts +10 -0
  196. package/dist/legacy/http/check_domain.mjs +82 -0
  197. package/dist/legacy/http/csrfTokenAnalyze.cjs +46 -0
  198. package/dist/legacy/http/csrfTokenAnalyze.d.mts +21 -0
  199. package/dist/legacy/http/csrfTokenAnalyze.mjs +40 -0
  200. package/dist/legacy/http/domainValidator.cjs +98 -0
  201. package/dist/legacy/http/domainValidator.d.mts +30 -0
  202. package/dist/legacy/http/domainValidator.mjs +82 -0
  203. package/dist/legacy/http/errorsCallback.cjs +55 -0
  204. package/dist/legacy/http/errorsCallback.d.mts +29 -0
  205. package/dist/legacy/http/errorsCallback.mjs +48 -0
  206. package/dist/legacy/http/fetch/json.cjs +48 -0
  207. package/dist/legacy/http/fetch/json.d.mts +22 -0
  208. package/dist/legacy/http/fetch/json.mjs +41 -0
  209. package/dist/legacy/http/fetch/text.cjs +47 -0
  210. package/dist/legacy/http/fetch/text.d.mts +21 -0
  211. package/dist/legacy/http/fetch/text.mjs +40 -0
  212. package/dist/legacy/http/fileCache.cjs +79 -0
  213. package/dist/legacy/http/fileCache.d.mts +35 -0
  214. package/dist/legacy/http/fileCache.mjs +70 -0
  215. package/dist/legacy/http/getDomainURL.cjs +59 -0
  216. package/dist/legacy/http/getDomainURL.d.mts +18 -0
  217. package/dist/legacy/http/getDomainURL.mjs +54 -0
  218. package/dist/legacy/http/userIP.cjs +59 -0
  219. package/dist/legacy/http/userIP.d.mts +21 -0
  220. package/dist/legacy/http/userIP.mjs +48 -0
  221. package/dist/legacy/index.cjs +122 -0
  222. package/dist/legacy/index.d.mts +89 -0
  223. package/dist/legacy/index.mjs +92 -0
  224. package/dist/legacy/libs/arraySortPositions.cjs +30 -0
  225. package/dist/legacy/libs/arraySortPositions.d.mts +16 -0
  226. package/dist/legacy/libs/arraySortPositions.mjs +27 -0
  227. package/dist/legacy/libs/capitalize.cjs +21 -0
  228. package/dist/legacy/libs/capitalize.d.mts +13 -0
  229. package/dist/legacy/libs/capitalize.mjs +17 -0
  230. package/dist/legacy/libs/convertBytes.cjs +64 -0
  231. package/dist/legacy/libs/convertBytes.d.mts +17 -0
  232. package/dist/legacy/libs/convertBytes.mjs +55 -0
  233. package/dist/legacy/libs/custom_module_loader.cjs +82 -0
  234. package/dist/legacy/libs/custom_module_loader.d.mts +5 -0
  235. package/dist/legacy/libs/custom_module_loader.mjs +79 -0
  236. package/dist/legacy/libs/dice.cjs +35 -0
  237. package/dist/legacy/libs/dice.d.mts +5 -0
  238. package/dist/legacy/libs/dice.mjs +31 -0
  239. package/dist/legacy/libs/markdown.cjs +85 -0
  240. package/dist/legacy/libs/markdown.d.mts +75 -0
  241. package/dist/legacy/libs/markdown.mjs +78 -0
  242. package/dist/legacy/libs/percentage.cjs +22 -0
  243. package/dist/legacy/libs/percentage.d.mts +4 -0
  244. package/dist/legacy/libs/percentage.mjs +19 -0
  245. package/dist/legacy/libs/regex/getLetter.cjs +22 -0
  246. package/dist/legacy/libs/regex/getLetter.d.mts +12 -0
  247. package/dist/legacy/libs/regex/getLetter.mjs +19 -0
  248. package/dist/legacy/libs/replaceAsync.cjs +32 -0
  249. package/dist/legacy/libs/replaceAsync.d.mts +15 -0
  250. package/dist/legacy/libs/replaceAsync.mjs +25 -0
  251. package/dist/legacy/libs/rule3.cjs +58 -0
  252. package/dist/legacy/libs/rule3.d.mts +5 -0
  253. package/dist/legacy/libs/rule3.mjs +54 -0
  254. package/dist/legacy/libs/userLevel.cjs +134 -0
  255. package/dist/legacy/libs/userLevel.d.mts +69 -0
  256. package/dist/legacy/libs/userLevel.mjs +123 -0
  257. package/dist/legacy/momentjs/getAge.cjs +28 -0
  258. package/dist/legacy/momentjs/getAge.d.mts +8 -0
  259. package/dist/legacy/momentjs/getAge.mjs +22 -0
  260. package/dist/legacy/momentjs/index.cjs +9 -0
  261. package/dist/legacy/momentjs/index.d.mts +3 -0
  262. package/dist/legacy/momentjs/index.mjs +3 -0
  263. package/dist/legacy/momentjs/timeDuration.cjs +29 -0
  264. package/dist/legacy/momentjs/timeDuration.d.mts +9 -0
  265. package/dist/legacy/momentjs/timeDuration.mjs +23 -0
  266. package/dist/legacy/socket.io/antiFlood/index.cjs +9 -0
  267. package/dist/legacy/socket.io/antiFlood/index.d.mts +3 -0
  268. package/dist/legacy/socket.io/antiFlood/index.mjs +3 -0
  269. package/dist/legacy/socket.io/antiFlood/install.cjs +32 -0
  270. package/dist/legacy/socket.io/antiFlood/install.d.mts +14 -0
  271. package/dist/legacy/socket.io/antiFlood/install.mjs +27 -0
  272. package/dist/legacy/socket.io/antiFlood/verify.cjs +87 -0
  273. package/dist/legacy/socket.io/antiFlood/verify.d.mts +15 -0
  274. package/dist/legacy/socket.io/antiFlood/verify.mjs +73 -0
  275. package/dist/legacy/socket.io/cookie-session.cjs +25 -0
  276. package/dist/legacy/socket.io/cookie-session.d.mts +9 -0
  277. package/dist/legacy/socket.io/cookie-session.mjs +20 -0
  278. package/dist/legacy/socket.io/discord.cjs +61 -0
  279. package/dist/legacy/socket.io/discord.d.mts +10 -0
  280. package/dist/legacy/socket.io/discord.mjs +52 -0
  281. package/dist/legacy/socket.io/index.cjs +13 -0
  282. package/dist/legacy/socket.io/index.d.mts +9 -0
  283. package/dist/legacy/socket.io/index.mjs +9 -0
  284. package/dist/v1/basics/array.cjs +31 -0
  285. package/dist/v1/basics/array.d.mts +10 -0
  286. package/dist/v1/basics/array.mjs +22 -0
  287. package/dist/v1/basics/clock.cjs +187 -0
  288. package/dist/v1/basics/clock.d.mts +37 -0
  289. package/dist/v1/basics/clock.mjs +152 -0
  290. package/dist/v1/basics/objFilter.cjs +55 -0
  291. package/dist/v1/basics/objFilter.d.mts +27 -0
  292. package/dist/v1/basics/objFilter.mjs +52 -0
  293. package/dist/v1/basics/simpleMath.cjs +88 -0
  294. package/dist/v1/basics/simpleMath.d.mts +54 -0
  295. package/dist/v1/basics/simpleMath.mjs +75 -0
  296. package/dist/v1/basics/text.cjs +34 -0
  297. package/dist/v1/basics/text.d.mts +20 -0
  298. package/dist/v1/basics/text.mjs +25 -0
  299. package/dist/v1/index.cjs +26 -0
  300. package/dist/v1/index.d.mts +15 -0
  301. package/dist/v1/index.mjs +8 -0
  302. package/package.json +72 -0
@@ -0,0 +1,151 @@
1
+ 'use strict';
2
+
3
+ /**
4
+ * @module http_base
5
+ *
6
+ * HTTP status utility for sending standardized HTTP responses using Express.
7
+ * Includes a comprehensive list of HTTP status codes and helper methods for sending responses.
8
+ */
9
+
10
+ const http_base = {
11
+ /**
12
+ * A list of standard HTTP status codes and their default messages.
13
+ * Follows the format { [statusCode]: message }.
14
+ *
15
+ * @readonly
16
+ * @type {Object<number, string>}
17
+ */
18
+ list: {
19
+ // Informational
20
+ 100: 'Continue',
21
+ 101: 'Switching Protocols',
22
+
23
+ // Successful
24
+ 200: 'OK',
25
+ 201: 'Created',
26
+ 202: 'Accepted',
27
+ 203: 'Non-Authoritative Information',
28
+ 204: 'No Content',
29
+ 205: 'Reset Content',
30
+ 206: 'Partial Content',
31
+
32
+ // Redirection
33
+ 300: 'Multiple Choices',
34
+ 301: 'Moved Permanently',
35
+ 302: 'Found',
36
+ 303: 'See Other',
37
+ 304: 'Not Modified',
38
+ 305: 'Use Proxy',
39
+ 306: 'Unused',
40
+ 307: 'Temporary Redirect',
41
+
42
+ // Client Error
43
+ 400: 'Bad Request',
44
+ 401: 'Unauthorized',
45
+ 402: 'Payment Required',
46
+ 403: 'Forbidden',
47
+ 404: 'Not Found',
48
+ 405: 'Method Not Allowed',
49
+ 406: 'Not Acceptable',
50
+ 407: 'Proxy Authentication Required',
51
+ 408: 'Request Timeout',
52
+ 409: 'Conflict',
53
+ 410: 'Gone',
54
+ 411: 'Length Required',
55
+ 412: 'Precondition Failed',
56
+ 413: 'Request Entity Too Large',
57
+ 414: 'Request-URI Too Long',
58
+ 415: 'Unsupported Media Type',
59
+ 416: 'Requested Range Not Satisfiable',
60
+ 417: 'Expectation Failed',
61
+
62
+ // Server Error
63
+ 500: 'Internal Server Error',
64
+ 501: 'Not Implemented',
65
+ 502: 'Bad Gateway',
66
+ 503: 'Service Unavailable',
67
+ 504: 'Gateway Timeout',
68
+ 505: 'HTTP Version Not Supported',
69
+ },
70
+
71
+ /**
72
+ * Sends an HTTP response with the given status code.
73
+ * If a callback is provided, it will be called instead of sending an empty response.
74
+ *
75
+ * @function send
76
+ * @param {import('express').Response} res - Express response object.
77
+ * @param {number} http_code - HTTP status code to send.
78
+ * @param {function(number): void} [callback] - Optional callback to handle response body manually.
79
+ *
80
+ * @returns {*} The result of `res.send()` or the callback function.
81
+ *
82
+ * @example
83
+ * http_base.send(res, 404); // Sends 404 Not Found with empty body
84
+ */
85
+ send: function (res, http_code, callback) {
86
+ // Exist Error Code?
87
+ if (typeof http_code === 'number' && typeof http_base.list[http_code] === 'string') {
88
+ // Set HTTP Code
89
+ res.status(http_code);
90
+ res.header(`HTTP/1.0 ${http_code} ${http_base.list[http_code]}`);
91
+
92
+ // Send Page
93
+ if (typeof callback !== 'function') {
94
+ return res.send('');
95
+ }
96
+
97
+ // Nope
98
+ else {
99
+ return callback(http_code);
100
+ }
101
+ }
102
+
103
+ // Nope
104
+ else {
105
+ return res.send('');
106
+ }
107
+ },
108
+
109
+ /**
110
+ * Asynchronously sends an HTTP response with the given status code.
111
+ * Awaits the provided callback before completing.
112
+ *
113
+ * @function sendAsync
114
+ * @param {import('express').Response} res - Express response object.
115
+ * @param {number} http_code - HTTP status code to send.
116
+ * @param {function(number): Promise<any>} [callback] - Optional async callback to handle response.
117
+ *
118
+ * @returns {Promise<any>} The result of the async callback or the empty response.
119
+ *
120
+ * @example
121
+ * await http_base.sendAsync(res, 500, async (code) => {
122
+ * res.send('Server error occurred.');
123
+ * });
124
+ */
125
+ sendAsync: async function (res, http_code, callback) {
126
+ // Exist Error Code?
127
+ if (typeof http_code === 'number' && typeof http_base.list[http_code] === 'string') {
128
+ // Set HTTP Code
129
+ res.status(http_code);
130
+ res.header(`HTTP/1.0 ${http_code} ${http_base.list[http_code]}`);
131
+
132
+ // Send Page
133
+ if (typeof callback !== 'function') {
134
+ return res.send('');
135
+ }
136
+
137
+ // Nope
138
+ else {
139
+ const result = await callback(http_code);
140
+ return result;
141
+ }
142
+ }
143
+
144
+ // Nope
145
+ else {
146
+ return res.send('');
147
+ }
148
+ },
149
+ };
150
+
151
+ module.exports = http_base;
@@ -0,0 +1,8 @@
1
+ export default http_base;
2
+ declare namespace http_base {
3
+ let list: {
4
+ [x: number]: string;
5
+ };
6
+ function send(res: import("express").Response, http_code: number, callback?: (arg0: number) => void): any;
7
+ function sendAsync(res: import("express").Response, http_code: number, callback?: (arg0: number) => Promise<any>): Promise<any>;
8
+ }
@@ -0,0 +1,136 @@
1
+ /**
2
+ * @module http_base
3
+ *
4
+ * HTTP status utility for sending standardized HTTP responses using Express.
5
+ * Includes a comprehensive list of HTTP status codes and helper methods for sending responses.
6
+ */
7
+ const http_base = {
8
+ /**
9
+ * A list of standard HTTP status codes and their default messages.
10
+ * Follows the format { [statusCode]: message }.
11
+ *
12
+ * @readonly
13
+ * @type {Object<number, string>}
14
+ */
15
+ list: {
16
+ // Informational
17
+ 100: 'Continue',
18
+ 101: 'Switching Protocols',
19
+ // Successful
20
+ 200: 'OK',
21
+ 201: 'Created',
22
+ 202: 'Accepted',
23
+ 203: 'Non-Authoritative Information',
24
+ 204: 'No Content',
25
+ 205: 'Reset Content',
26
+ 206: 'Partial Content',
27
+ // Redirection
28
+ 300: 'Multiple Choices',
29
+ 301: 'Moved Permanently',
30
+ 302: 'Found',
31
+ 303: 'See Other',
32
+ 304: 'Not Modified',
33
+ 305: 'Use Proxy',
34
+ 306: 'Unused',
35
+ 307: 'Temporary Redirect',
36
+ // Client Error
37
+ 400: 'Bad Request',
38
+ 401: 'Unauthorized',
39
+ 402: 'Payment Required',
40
+ 403: 'Forbidden',
41
+ 404: 'Not Found',
42
+ 405: 'Method Not Allowed',
43
+ 406: 'Not Acceptable',
44
+ 407: 'Proxy Authentication Required',
45
+ 408: 'Request Timeout',
46
+ 409: 'Conflict',
47
+ 410: 'Gone',
48
+ 411: 'Length Required',
49
+ 412: 'Precondition Failed',
50
+ 413: 'Request Entity Too Large',
51
+ 414: 'Request-URI Too Long',
52
+ 415: 'Unsupported Media Type',
53
+ 416: 'Requested Range Not Satisfiable',
54
+ 417: 'Expectation Failed',
55
+ // Server Error
56
+ 500: 'Internal Server Error',
57
+ 501: 'Not Implemented',
58
+ 502: 'Bad Gateway',
59
+ 503: 'Service Unavailable',
60
+ 504: 'Gateway Timeout',
61
+ 505: 'HTTP Version Not Supported',
62
+ },
63
+ /**
64
+ * Sends an HTTP response with the given status code.
65
+ * If a callback is provided, it will be called instead of sending an empty response.
66
+ *
67
+ * @function send
68
+ * @param {import('express').Response} res - Express response object.
69
+ * @param {number} http_code - HTTP status code to send.
70
+ * @param {function(number): void} [callback] - Optional callback to handle response body manually.
71
+ *
72
+ * @returns {*} The result of `res.send()` or the callback function.
73
+ *
74
+ * @example
75
+ * http_base.send(res, 404); // Sends 404 Not Found with empty body
76
+ */
77
+ send: function (res, http_code, callback) {
78
+ // Exist Error Code?
79
+ if (typeof http_code === 'number' && typeof http_base.list[http_code] === 'string') {
80
+ // Set HTTP Code
81
+ res.status(http_code);
82
+ res.header(`HTTP/1.0 ${http_code} ${http_base.list[http_code]}`);
83
+ // Send Page
84
+ if (typeof callback !== 'function') {
85
+ return res.send('');
86
+ }
87
+ // Nope
88
+ else {
89
+ return callback(http_code);
90
+ }
91
+ }
92
+ // Nope
93
+ else {
94
+ return res.send('');
95
+ }
96
+ },
97
+ /**
98
+ * Asynchronously sends an HTTP response with the given status code.
99
+ * Awaits the provided callback before completing.
100
+ *
101
+ * @function sendAsync
102
+ * @param {import('express').Response} res - Express response object.
103
+ * @param {number} http_code - HTTP status code to send.
104
+ * @param {function(number): Promise<any>} [callback] - Optional async callback to handle response.
105
+ *
106
+ * @returns {Promise<any>} The result of the async callback or the empty response.
107
+ *
108
+ * @example
109
+ * await http_base.sendAsync(res, 500, async (code) => {
110
+ * res.send('Server error occurred.');
111
+ * });
112
+ */
113
+ sendAsync: async function (res, http_code, callback) {
114
+ // Exist Error Code?
115
+ if (typeof http_code === 'number' && typeof http_base.list[http_code] === 'string') {
116
+ // Set HTTP Code
117
+ res.status(http_code);
118
+ res.header(`HTTP/1.0 ${http_code} ${http_base.list[http_code]}`);
119
+ // Send Page
120
+ if (typeof callback !== 'function') {
121
+ return res.send('');
122
+ }
123
+ // Nope
124
+ else {
125
+ const result = await callback(http_code);
126
+ return result;
127
+ }
128
+ }
129
+ // Nope
130
+ else {
131
+ return res.send('');
132
+ }
133
+ },
134
+ };
135
+ // Module
136
+ export default http_base;
@@ -0,0 +1,70 @@
1
+ 'use strict';
2
+
3
+ /**
4
+ * Creates an Express middleware for Basic HTTP Authentication.
5
+ *
6
+ * This middleware checks for an `Authorization` header and validates
7
+ * the username and password using base64-decoded credentials.
8
+ *
9
+ * If the credentials match, `next()` is called to proceed to the next middleware.
10
+ * If the credentials are invalid or missing, a 401 Unauthorized response is sent.
11
+ *
12
+ * @function auth
13
+ * @param {Object} data - Configuration object.
14
+ * @param {string} data.login - The expected username.
15
+ * @param {string} data.password - The expected password.
16
+ * @param {Function} [data.customError] - Optional function `(req, res) => {}` called on auth failure.
17
+ * @param {Function} [callback] - Optional fallback function `(req, res, next) => {}` executed after customError.
18
+ *
19
+ * @returns {Function} Express middleware function.
20
+ *
21
+ * @example
22
+ * import express from 'express';
23
+ * import auth from './auth.mjs';
24
+ *
25
+ * const app = express();
26
+ *
27
+ * app.use(auth({
28
+ * login: 'admin',
29
+ * password: '1234',
30
+ * customError: (req, res) => {
31
+ * res.send('Custom unauthorized message');
32
+ * }
33
+ * }));
34
+ *
35
+ * app.get('/', (req, res) => {
36
+ * res.send('Hello, authenticated user!');
37
+ * });
38
+ */
39
+ function auth(data, callback) {
40
+ // Simple Basic Auth with vanilla JavaScript (ES6)
41
+ // https://stackoverflow.com/questions/23616371/basic-http-authentication-with-node-and-express-4
42
+ return async (req, res, next) => {
43
+ // -----------------------------------------------------------------------
44
+ // authentication middleware
45
+
46
+ const auth = { login: data.login, password: data.password };
47
+
48
+ // Parse credentials from Authorization header
49
+ const b64auth = (req.headers.authorization || '').split(' ')[1] || '';
50
+ const [login, password] = Buffer.from(b64auth, 'base64').toString().split(':');
51
+
52
+ // Check credentials
53
+ if (login && password && login === auth.login && password === auth.password) {
54
+ return next(); // Access granted
55
+ }
56
+
57
+ // Access denied
58
+ res.set('WWW-Authenticate', 'Basic realm="401"');
59
+ res.status(401);
60
+ if (typeof data.customError === 'function') await data.customError(req, res);
61
+
62
+ // Optional fallback
63
+ if (typeof callback === 'function') return callback(req, res, next);
64
+ else res.send('');
65
+
66
+ // -----------------------------------------------------------------------
67
+ };
68
+ }
69
+
70
+ module.exports = auth;
@@ -0,0 +1,41 @@
1
+ /**
2
+ * Creates an Express middleware for Basic HTTP Authentication.
3
+ *
4
+ * This middleware checks for an `Authorization` header and validates
5
+ * the username and password using base64-decoded credentials.
6
+ *
7
+ * If the credentials match, `next()` is called to proceed to the next middleware.
8
+ * If the credentials are invalid or missing, a 401 Unauthorized response is sent.
9
+ *
10
+ * @function auth
11
+ * @param {Object} data - Configuration object.
12
+ * @param {string} data.login - The expected username.
13
+ * @param {string} data.password - The expected password.
14
+ * @param {Function} [data.customError] - Optional function `(req, res) => {}` called on auth failure.
15
+ * @param {Function} [callback] - Optional fallback function `(req, res, next) => {}` executed after customError.
16
+ *
17
+ * @returns {Function} Express middleware function.
18
+ *
19
+ * @example
20
+ * import express from 'express';
21
+ * import auth from './auth.mjs';
22
+ *
23
+ * const app = express();
24
+ *
25
+ * app.use(auth({
26
+ * login: 'admin',
27
+ * password: '1234',
28
+ * customError: (req, res) => {
29
+ * res.send('Custom unauthorized message');
30
+ * }
31
+ * }));
32
+ *
33
+ * app.get('/', (req, res) => {
34
+ * res.send('Hello, authenticated user!');
35
+ * });
36
+ */
37
+ export default function auth(data: {
38
+ login: string;
39
+ password: string;
40
+ customError?: Function | undefined;
41
+ }, callback?: Function): Function;
@@ -0,0 +1,63 @@
1
+ /**
2
+ * Creates an Express middleware for Basic HTTP Authentication.
3
+ *
4
+ * This middleware checks for an `Authorization` header and validates
5
+ * the username and password using base64-decoded credentials.
6
+ *
7
+ * If the credentials match, `next()` is called to proceed to the next middleware.
8
+ * If the credentials are invalid or missing, a 401 Unauthorized response is sent.
9
+ *
10
+ * @function auth
11
+ * @param {Object} data - Configuration object.
12
+ * @param {string} data.login - The expected username.
13
+ * @param {string} data.password - The expected password.
14
+ * @param {Function} [data.customError] - Optional function `(req, res) => {}` called on auth failure.
15
+ * @param {Function} [callback] - Optional fallback function `(req, res, next) => {}` executed after customError.
16
+ *
17
+ * @returns {Function} Express middleware function.
18
+ *
19
+ * @example
20
+ * import express from 'express';
21
+ * import auth from './auth.mjs';
22
+ *
23
+ * const app = express();
24
+ *
25
+ * app.use(auth({
26
+ * login: 'admin',
27
+ * password: '1234',
28
+ * customError: (req, res) => {
29
+ * res.send('Custom unauthorized message');
30
+ * }
31
+ * }));
32
+ *
33
+ * app.get('/', (req, res) => {
34
+ * res.send('Hello, authenticated user!');
35
+ * });
36
+ */
37
+ export default function auth(data, callback) {
38
+ // Simple Basic Auth with vanilla JavaScript (ES6)
39
+ // https://stackoverflow.com/questions/23616371/basic-http-authentication-with-node-and-express-4
40
+ return async (req, res, next) => {
41
+ // -----------------------------------------------------------------------
42
+ // authentication middleware
43
+ const auth = { login: data.login, password: data.password };
44
+ // Parse credentials from Authorization header
45
+ const b64auth = (req.headers.authorization || '').split(' ')[1] || '';
46
+ const [login, password] = Buffer.from(b64auth, 'base64').toString().split(':');
47
+ // Check credentials
48
+ if (login && password && login === auth.login && password === auth.password) {
49
+ return next(); // Access granted
50
+ }
51
+ // Access denied
52
+ res.set('WWW-Authenticate', 'Basic realm="401"');
53
+ res.status(401);
54
+ if (typeof data.customError === 'function')
55
+ await data.customError(req, res);
56
+ // Optional fallback
57
+ if (typeof callback === 'function')
58
+ return callback(req, res, next);
59
+ else
60
+ res.send('');
61
+ // -----------------------------------------------------------------------
62
+ };
63
+ }
@@ -0,0 +1,84 @@
1
+ 'use strict';
2
+
3
+ /**
4
+ * @module check_domain
5
+ *
6
+ * Utility module to validate or retrieve the domain from a request object.
7
+ * It supports multiple methods to check the domain, including:
8
+ * - `x-forwarded-host`
9
+ * - `req.hostname`
10
+ * - `req.headers.host`
11
+ *
12
+ * Can be used to check if the incoming request matches a specific domain or to
13
+ * simply retrieve the current domain of the request.
14
+ */
15
+ const check_domain = {
16
+ /**
17
+ * A list of domain validators using different request properties.
18
+ *
19
+ * Each validator includes a `type` and a `callback` function that checks or returns the domain.
20
+ * If a domain (`the_domain`) is passed, the function returns a boolean.
21
+ * If not, it returns the found domain string or `null`.
22
+ *
23
+ * @type {Array<{type: string, callback: function(req: Object, the_domain?: string): (boolean|string|null)}>}
24
+ */
25
+ validators: [
26
+ {
27
+ type: 'x-forwarded-host',
28
+ callback: function (req, the_domain) {
29
+ const isString = typeof req.headers['x-forwarded-host'] === 'string';
30
+ if (the_domain) return isString && req.headers['x-forwarded-host'] === the_domain;
31
+
32
+ return isString ? req.headers['x-forwarded-host'] : null;
33
+ },
34
+ },
35
+ {
36
+ type: 'hostname',
37
+ callback: function (req, the_domain) {
38
+ const isString = typeof req.hostname === 'string';
39
+ if (the_domain) return isString && req.hostname === the_domain;
40
+
41
+ return isString ? req.hostname : null;
42
+ },
43
+ },
44
+ {
45
+ type: 'hostname',
46
+ callback: function (req, the_domain) {
47
+ const isString = typeof req.headers.host === 'string';
48
+ if (the_domain) return isString && req.headers.host === the_domain;
49
+ return isString ? req.headers.host : null;
50
+ },
51
+ },
52
+ ],
53
+
54
+ /**
55
+ * Validates the request against a given domain using all available validators.
56
+ *
57
+ * @function
58
+ * @param {Object} req - The request object from Express.
59
+ * @param {string} the_domain - The domain to validate against.
60
+ * @returns {boolean} True if any validator matches the domain.
61
+ */
62
+ validator: function (req, the_domain) {
63
+ for (const item in check_domain.validators)
64
+ if (check_domain.validators[item].callback(req, the_domain)) return true;
65
+ return false;
66
+ },
67
+
68
+ /**
69
+ * Returns the domain found from the first valid source in the request object.
70
+ *
71
+ * @function
72
+ * @param {Object} req - The request object from Express.
73
+ * @returns {string|null} The found domain string or `null` if none matched.
74
+ */
75
+ get: function (req) {
76
+ for (const item in check_domain.validators) {
77
+ const result = check_domain.validators[item].callback(req);
78
+ if (result) return result;
79
+ }
80
+ return null;
81
+ },
82
+ };
83
+
84
+ module.exports = check_domain;
@@ -0,0 +1,10 @@
1
+ export default check_domain;
2
+ declare namespace check_domain {
3
+ let validators: Array<{
4
+ type: string;
5
+ callback: (arg0: req) => Object;
6
+ the_domain?: string;
7
+ }>;
8
+ function validator(req: Object, the_domain: string): boolean;
9
+ function get(req: Object): string | null;
10
+ }
@@ -0,0 +1,82 @@
1
+ /**
2
+ * @module check_domain
3
+ *
4
+ * Utility module to validate or retrieve the domain from a request object.
5
+ * It supports multiple methods to check the domain, including:
6
+ * - `x-forwarded-host`
7
+ * - `req.hostname`
8
+ * - `req.headers.host`
9
+ *
10
+ * Can be used to check if the incoming request matches a specific domain or to
11
+ * simply retrieve the current domain of the request.
12
+ */
13
+ const check_domain = {
14
+ /**
15
+ * A list of domain validators using different request properties.
16
+ *
17
+ * Each validator includes a `type` and a `callback` function that checks or returns the domain.
18
+ * If a domain (`the_domain`) is passed, the function returns a boolean.
19
+ * If not, it returns the found domain string or `null`.
20
+ *
21
+ * @type {Array<{type: string, callback: function(req: Object, the_domain?: string): (boolean|string|null)}>}
22
+ */
23
+ validators: [
24
+ {
25
+ type: 'x-forwarded-host',
26
+ callback: function (req, the_domain) {
27
+ const isString = typeof req.headers['x-forwarded-host'] === 'string';
28
+ if (the_domain)
29
+ return isString && req.headers['x-forwarded-host'] === the_domain;
30
+ return isString ? req.headers['x-forwarded-host'] : null;
31
+ },
32
+ },
33
+ {
34
+ type: 'hostname',
35
+ callback: function (req, the_domain) {
36
+ const isString = typeof req.hostname === 'string';
37
+ if (the_domain)
38
+ return isString && req.hostname === the_domain;
39
+ return isString ? req.hostname : null;
40
+ },
41
+ },
42
+ {
43
+ type: 'hostname',
44
+ callback: function (req, the_domain) {
45
+ const isString = typeof req.headers.host === 'string';
46
+ if (the_domain)
47
+ return isString && req.headers.host === the_domain;
48
+ return isString ? req.headers.host : null;
49
+ },
50
+ },
51
+ ],
52
+ /**
53
+ * Validates the request against a given domain using all available validators.
54
+ *
55
+ * @function
56
+ * @param {Object} req - The request object from Express.
57
+ * @param {string} the_domain - The domain to validate against.
58
+ * @returns {boolean} True if any validator matches the domain.
59
+ */
60
+ validator: function (req, the_domain) {
61
+ for (const item in check_domain.validators)
62
+ if (check_domain.validators[item].callback(req, the_domain))
63
+ return true;
64
+ return false;
65
+ },
66
+ /**
67
+ * Returns the domain found from the first valid source in the request object.
68
+ *
69
+ * @function
70
+ * @param {Object} req - The request object from Express.
71
+ * @returns {string|null} The found domain string or `null` if none matched.
72
+ */
73
+ get: function (req) {
74
+ for (const item in check_domain.validators) {
75
+ const result = check_domain.validators[item].callback(req);
76
+ if (result)
77
+ return result;
78
+ }
79
+ return null;
80
+ },
81
+ };
82
+ export default check_domain;