@vbarbarosh/node-helpers 3.75.0 → 3.76.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 (369) hide show
  1. package/README.md +29 -3
  2. package/dist/browser.js +1 -2504
  3. package/dist/index.html +1 -1
  4. package/package.json +33 -12
  5. package/src/HeartbeatServer.js +24 -3
  6. package/src/HeartbeatServer.md +33 -0
  7. package/src/array_chunk.js +1 -1
  8. package/src/array_chunk.md +8 -0
  9. package/src/array_chunk_balanced.md +14 -0
  10. package/src/array_fps.md +12 -0
  11. package/src/array_gcd.js +4 -2
  12. package/src/array_gcd.md +2 -1
  13. package/src/array_group.js +3 -3
  14. package/src/array_group.md +14 -0
  15. package/src/array_group_map.js +3 -3
  16. package/src/array_group_map.md +13 -0
  17. package/src/array_index.js +2 -2
  18. package/src/array_index.md +9 -0
  19. package/src/array_lcm.js +4 -2
  20. package/src/array_lcm.md +2 -1
  21. package/src/array_max.js +11 -4
  22. package/src/array_max.md +1 -1
  23. package/src/array_min.js +11 -4
  24. package/src/array_min.md +1 -1
  25. package/src/array_permutations.js +4 -0
  26. package/src/array_permutations.md +13 -0
  27. package/src/array_sort.js +7 -2
  28. package/src/array_sort.md +13 -0
  29. package/src/array_sort_other.js +8 -5
  30. package/src/array_sort_other.md +11 -0
  31. package/src/array_sum.js +2 -2
  32. package/src/array_sum.md +8 -0
  33. package/src/array_unique.js +2 -2
  34. package/src/array_unique_last.js +2 -2
  35. package/src/assert_valid_expires_at.md +10 -0
  36. package/src/clamp.md +9 -0
  37. package/src/cli-apps/watchdog.js +5 -0
  38. package/src/cli.js +3 -1
  39. package/src/cli.md +15 -0
  40. package/src/const_stream.md +7 -0
  41. package/src/const_type.md +5 -0
  42. package/src/countdown.js +22 -5
  43. package/src/countdown.md +21 -0
  44. package/src/crypto_decrypt_aes256.md +13 -0
  45. package/src/crypto_encrypt_aes256.md +13 -0
  46. package/src/crypto_hash_md5.md +10 -0
  47. package/src/crypto_hash_sha256.md +10 -0
  48. package/src/crypto_hmac_sha256.md +11 -0
  49. package/src/date_add_hours.md +8 -0
  50. package/src/date_add_milliseconds.md +4 -0
  51. package/src/date_add_minutes.md +4 -0
  52. package/src/date_add_months.md +13 -0
  53. package/src/date_add_seconds.md +4 -0
  54. package/src/date_diff_seconds.md +4 -0
  55. package/src/date_is_leap_year.md +9 -0
  56. package/src/escape_content_disposition.js +6 -3
  57. package/src/escape_content_disposition.md +13 -0
  58. package/src/escape_regexp.md +7 -0
  59. package/src/eta.js +7 -1
  60. package/src/eta.md +18 -0
  61. package/src/factorize_ms.js +3 -0
  62. package/src/factorize_ms.md +10 -0
  63. package/src/fastdl.js +14 -3
  64. package/src/fcmp_dates.md +12 -0
  65. package/src/fcmp_default.js +7 -0
  66. package/src/fcmp_default.md +29 -0
  67. package/src/fcmp_default_desc.js +4 -7
  68. package/src/fcmp_default_desc.md +10 -0
  69. package/src/fcmp_from_spec.md +13 -0
  70. package/src/fcmp_numbers.md +11 -0
  71. package/src/fcmp_tuples.md +17 -0
  72. package/src/fcmp_utf8_bin.md +14 -0
  73. package/src/fcmp_utf8_ci.md +14 -0
  74. package/src/fcmp_utf8_cs.md +15 -0
  75. package/src/fcmp_utf8_natural_bin.js +38 -0
  76. package/src/fcmp_utf8_natural_bin.md +8 -0
  77. package/src/fcmp_utf8_natural_ci.md +13 -0
  78. package/src/fcmp_utf8_natural_cs.md +13 -0
  79. package/src/fcmpx.md +26 -9
  80. package/src/filter1_from_spec.js +3 -3
  81. package/src/format_bytes.md +15 -0
  82. package/src/format_date.md +7 -0
  83. package/src/format_date_fs.md +7 -0
  84. package/src/format_date_human.md +6 -0
  85. package/src/format_date_ymd.md +6 -0
  86. package/src/format_error_report.js +3 -3
  87. package/src/format_error_report.md +12 -0
  88. package/src/format_kilo.md +13 -0
  89. package/src/format_ms.js +3 -2
  90. package/src/format_ms.md +12 -0
  91. package/src/format_ms2.js +6 -3
  92. package/src/format_ms2.md +12 -0
  93. package/src/format_ms3.js +3 -2
  94. package/src/format_ms3.md +12 -0
  95. package/src/format_percents.md +10 -0
  96. package/src/format_progress_bytes.md +13 -0
  97. package/src/format_progress_kilo.md +10 -0
  98. package/src/format_seconds.md +11 -0
  99. package/src/format_thousands.md +9 -0
  100. package/src/fs_append.md +7 -0
  101. package/src/fs_append_json.md +8 -0
  102. package/src/fs_append_utf8.md +6 -0
  103. package/src/fs_assert_file_exists.md +3 -0
  104. package/src/fs_assert_file_readable.js +1 -1
  105. package/src/fs_assert_file_readable.md +3 -0
  106. package/src/fs_assert_file_socket.md +2 -0
  107. package/src/fs_copy.md +7 -0
  108. package/src/fs_copy_excl.md +2 -0
  109. package/src/fs_exists.md +6 -0
  110. package/src/fs_fclose.md +5 -0
  111. package/src/fs_fi.js +13 -1
  112. package/src/fs_fi.md +11 -0
  113. package/src/fs_file_md5.md +8 -0
  114. package/src/fs_find.md +7 -0
  115. package/src/fs_fopen.md +6 -0
  116. package/src/fs_fread.js +2 -2
  117. package/src/fs_fread.md +11 -0
  118. package/src/fs_fsize.md +2 -0
  119. package/src/fs_fstat.md +2 -0
  120. package/src/fs_fwrite.js +2 -2
  121. package/src/fs_fwrite.md +9 -0
  122. package/src/fs_list.md +5 -0
  123. package/src/fs_list_deep.md +5 -0
  124. package/src/fs_ls.md +2 -0
  125. package/src/fs_lsr.md +4 -0
  126. package/src/fs_lstat.md +3 -0
  127. package/src/fs_mkdir.md +3 -0
  128. package/src/fs_mkdirp.js +3 -30
  129. package/src/fs_mkdirp.md +7 -0
  130. package/src/fs_path_basename.md +2 -0
  131. package/src/fs_path_dirname.md +2 -0
  132. package/src/fs_path_extname.md +9 -0
  133. package/src/fs_path_join.md +2 -0
  134. package/src/fs_path_relative.md +2 -0
  135. package/src/fs_path_resolve.md +2 -0
  136. package/src/fs_path_tempdir.md +2 -0
  137. package/src/fs_path_untildify.md +8 -0
  138. package/src/fs_read.md +3 -0
  139. package/src/fs_read_buffer.md +5 -0
  140. package/src/fs_read_json.md +6 -0
  141. package/src/fs_read_lines.md +7 -0
  142. package/src/fs_read_stream.md +2 -0
  143. package/src/fs_read_utf8.md +5 -0
  144. package/src/fs_readdir.md +3 -0
  145. package/src/fs_readlink.md +6 -0
  146. package/src/fs_rename.md +6 -0
  147. package/src/fs_rm.md +4 -0
  148. package/src/fs_rmdir.md +3 -0
  149. package/src/fs_rmf.md +2 -0
  150. package/src/fs_rmrf.md +8 -0
  151. package/src/fs_sha256.js +16 -0
  152. package/src/fs_sha256.md +9 -0
  153. package/src/fs_size.js +2 -2
  154. package/src/fs_size.md +6 -0
  155. package/src/fs_stat.md +2 -0
  156. package/src/fs_tempdir.js +20 -5
  157. package/src/fs_touch.md +6 -0
  158. package/src/fs_walk.js +2 -2
  159. package/src/fs_walk.md +14 -0
  160. package/src/fs_write.md +3 -0
  161. package/src/fs_write_json.md +7 -0
  162. package/src/fs_write_stream.md +2 -0
  163. package/src/gettype.md +13 -0
  164. package/src/http_delete.md +11 -0
  165. package/src/http_get_blob.md +8 -0
  166. package/src/http_get_buffer.md +10 -0
  167. package/src/http_get_file.js +8 -8
  168. package/src/http_get_file.md +14 -0
  169. package/src/http_get_json.md +10 -0
  170. package/src/http_get_stream.md +14 -0
  171. package/src/http_get_stream_range.js +27 -9
  172. package/src/http_get_stream_range.md +22 -0
  173. package/src/http_get_utf8.md +9 -0
  174. package/src/http_head.md +9 -0
  175. package/src/http_patch_json.md +10 -0
  176. package/src/http_post_json.md +11 -0
  177. package/src/http_post_multipart.md +15 -0
  178. package/src/http_post_urlencoded.md +11 -0
  179. package/src/http_put_buffer.md +9 -0
  180. package/src/http_put_file.js +9 -6
  181. package/src/http_put_file.md +16 -0
  182. package/src/http_put_json.md +11 -0
  183. package/src/http_put_utf8.md +9 -0
  184. package/src/http_range_parse.js +6 -3
  185. package/src/http_range_parse.md +18 -0
  186. package/src/http_stream_range.js +35 -22
  187. package/src/http_stream_range.md +29 -0
  188. package/src/identity.md +2 -0
  189. package/src/ignore.md +2 -0
  190. package/src/json_stringify_safe.md +10 -0
  191. package/src/json_stringify_stable.md +9 -0
  192. package/src/logger.js +2 -3
  193. package/src/logger.md +15 -0
  194. package/src/make_progress.js +8 -5
  195. package/src/make_progress.md +20 -0
  196. package/src/math_gcd.js +2 -1
  197. package/src/mongo_stream_upsert.js +10 -3
  198. package/src/mongo_stream_upsert.md +17 -0
  199. package/src/mongo_stream_write.js +10 -3
  200. package/src/mongo_stream_write.md +16 -0
  201. package/src/msval.md +10 -0
  202. package/src/now_fs.md +7 -0
  203. package/src/now_human.md +6 -0
  204. package/src/object_defaults.md +11 -0
  205. package/src/object_schema.js +2 -1
  206. package/src/object_schema.md +12 -0
  207. package/src/object_walk_preorder.md +16 -0
  208. package/src/parallel.js +23 -10
  209. package/src/parse_bytes.js +4 -2
  210. package/src/parse_bytes.md +15 -0
  211. package/src/parse_hms.js +1 -1
  212. package/src/parse_http_content_range.js +9 -5
  213. package/src/parse_http_content_range.md +16 -0
  214. package/src/perf_end_human.md +10 -0
  215. package/src/perf_end_ms.md +8 -0
  216. package/src/perf_measure.md +10 -0
  217. package/src/perf_measure_human.md +8 -0
  218. package/src/perf_start.md +9 -0
  219. package/src/pgid_exists.md +6 -0
  220. package/src/pgid_kill_grace.js +1 -1
  221. package/src/pgid_kill_grace.md +15 -0
  222. package/src/pid_exists.md +5 -0
  223. package/src/pid_kill_grace.js +1 -1
  224. package/src/pid_kill_grace.md +14 -0
  225. package/src/plural.md +13 -0
  226. package/src/random_hex.md +9 -0
  227. package/src/random_int.md +8 -0
  228. package/src/range.js +4 -2
  229. package/src/range.md +2 -0
  230. package/src/redis_connect.js +1 -1
  231. package/src/redis_connect.md +10 -0
  232. package/src/redis_lshift.md +14 -0
  233. package/src/redis_poll.js +1 -0
  234. package/src/redis_poll.md +17 -0
  235. package/src/redis_poll_zshift_callback_rpush.js +1 -2
  236. package/src/redis_poll_zshift_callback_rpush.md +17 -0
  237. package/src/redis_poll_zshift_spawn_rpush.js +2 -1
  238. package/src/redis_poll_zshift_spawn_rpush.md +20 -0
  239. package/src/redis_zshift.md +14 -0
  240. package/src/round.js +7 -8
  241. package/src/round.md +15 -0
  242. package/src/sanitize_dash_name.md +13 -0
  243. package/src/sanitize_filename.md +9 -0
  244. package/src/sanitize_var_name.md +14 -0
  245. package/src/sftp_get_file_info.js +2 -2
  246. package/src/sftp_get_file_info.md +14 -0
  247. package/src/sftp_get_stream_range.js +32 -22
  248. package/src/sftp_get_stream_range.md +20 -0
  249. package/src/shell_curl_progress.js +2 -1
  250. package/src/shell_curl_progress.md +17 -0
  251. package/src/shell_lines.js +2 -2
  252. package/src/shell_lines.md +1 -1
  253. package/src/shell_spawn.js +7 -0
  254. package/src/shell_ytdlp_progress.js +2 -1
  255. package/src/shell_ytdlp_progress.md +17 -0
  256. package/src/str_camel_to_snake.md +11 -0
  257. package/src/str_parse_kv.md +11 -0
  258. package/src/stream_curl_progress.md +14 -0
  259. package/src/stream_data_ln.js +7 -1
  260. package/src/stream_discard.md +8 -0
  261. package/src/stream_group.md +3 -0
  262. package/src/stream_gunzip.md +7 -0
  263. package/src/stream_hash.md +10 -0
  264. package/src/stream_map.js +8 -1
  265. package/src/stream_map_parallel.js +9 -1
  266. package/src/stream_md5.md +9 -0
  267. package/src/stream_multiplex.js +11 -0
  268. package/src/stream_multiplex.md +16 -0
  269. package/src/stream_through.md +3 -0
  270. package/src/stream_transform.md +2 -0
  271. package/src/stream_xml_analyze.js +9 -1
  272. package/src/stream_xml_parse.js +9 -1
  273. package/src/stream_ytdlp_progress.js +1 -1
  274. package/src/stream_ytdlp_progress.md +18 -0
  275. package/src/strtr.js +15 -5
  276. package/src/strtr.md +11 -0
  277. package/src/urlclean.js +9 -2
  278. package/src/urlmod.js +22 -11
  279. package/src/urlmod.md +15 -3
  280. package/src/urlparts.md +17 -0
  281. package/src/wait_while.js +1 -1
  282. package/src/wait_while.md +1 -1
  283. package/src/HeartbeatServer.test.js +0 -31
  284. package/src/array_chunk.test.js +0 -24
  285. package/src/array_chunk_balanced.test.js +0 -37
  286. package/src/array_fps.test.js +0 -72
  287. package/src/array_gcd.test.js +0 -10
  288. package/src/array_index.test.js +0 -14
  289. package/src/array_lcm.test.js +0 -12
  290. package/src/array_max.test.js +0 -20
  291. package/src/array_min.test.js +0 -20
  292. package/src/array_permutations.test.js +0 -20
  293. package/src/array_sort.test.js +0 -85
  294. package/src/array_sort_other.test.js +0 -9
  295. package/src/array_sum.test.js +0 -11
  296. package/src/cli-apps/watchdog.d/connect_close.js +0 -17
  297. package/src/cli-apps/watchdog.d/connect_close2.js +0 -20
  298. package/src/cli-apps/watchdog.d/connect_close3.js +0 -25
  299. package/src/cli-apps/watchdog.d/connect_no_ping.js +0 -13
  300. package/src/cli-apps/watchdog.d/early_exit.js +0 -7
  301. package/src/cli-apps/watchdog.d/flood.js +0 -13
  302. package/src/cli-apps/watchdog.d/flood2.js +0 -15
  303. package/src/cli-apps/watchdog.d/hang.js +0 -8
  304. package/src/cli-apps/watchdog.d/huge_delay.js +0 -18
  305. package/src/cli-apps/watchdog.d/ignore_sigterm.js +0 -29
  306. package/src/cli-apps/watchdog.d/late_heartbeat.js +0 -21
  307. package/src/cli-apps/watchdog.d/my-exit-after-2-pings.js +0 -16
  308. package/src/cli-apps/watchdog.d/my-happy-path.js +0 -16
  309. package/src/cli-apps/watchdog.d/my-ignore-sigterm.js +0 -22
  310. package/src/cli-apps/watchdog.d/my-never-ping.js +0 -15
  311. package/src/cli-apps/watchdog.d/no_heartbeat.js +0 -5
  312. package/src/cli-apps/watchdog.d/ok.js +0 -17
  313. package/src/cli-apps/watchdog.d/quick-exit-after-2-pings.js +0 -15
  314. package/src/cli-apps/watchdog.d/quick-hang-after-1-ping.js +0 -15
  315. package/src/cli-apps/watchdog.d/spawn_children.js +0 -14
  316. package/src/cli-apps/watchdog.test.js +0 -48
  317. package/src/crypto_encrypt_aes256.test.js +0 -10
  318. package/src/crypto_hash_sha256.test.js +0 -10
  319. package/src/date_add_months.test.js +0 -40
  320. package/src/date_is_leap_year.test.js +0 -14
  321. package/src/escape_content_disposition.test.js +0 -22
  322. package/src/fcmp_from_spec.test.js +0 -91
  323. package/src/fcmpx.test.js +0 -173
  324. package/src/filter1_from_spec.test.js +0 -31
  325. package/src/format_bytes.test.js +0 -22
  326. package/src/format_error_report.d/src/1.js +0 -26
  327. package/src/format_error_report.d/src/2.js +0 -29
  328. package/src/format_kilo.test.js +0 -25
  329. package/src/format_ms.test.js +0 -33
  330. package/src/format_ms2.test.js +0 -33
  331. package/src/format_ms3.test.js +0 -33
  332. package/src/format_percents.test.js +0 -22
  333. package/src/format_progress_bytes.test.js +0 -19
  334. package/src/format_progress_kilo.test.js +0 -19
  335. package/src/format_seconds.test.js +0 -42
  336. package/src/format_thousands.test.js +0 -28
  337. package/src/fs_file_md5.test.js +0 -11
  338. package/src/fs_mkdirp.test.js +0 -24
  339. package/src/fs_path_extname.test.js +0 -22
  340. package/src/gettype.test.js +0 -27
  341. package/src/object_schema.test.js +0 -15
  342. package/src/object_walk_preorder.test.js +0 -17
  343. package/src/parallel.test.js +0 -11
  344. package/src/parse_bytes.test.js +0 -21
  345. package/src/parse_hms.test.js +0 -32
  346. package/src/parse_http_content_range.test.js +0 -14
  347. package/src/pid_kill_grace.d/ignore-sigterm-for-10ms.js +0 -33
  348. package/src/pid_kill_grace.d/ignore-sigterm.js +0 -22
  349. package/src/pid_kill_grace.test.js +0 -63
  350. package/src/ping_socket.test.js +0 -58
  351. package/src/plural.test.js +0 -20
  352. package/src/range.test.js +0 -41
  353. package/src/redis_lshift.test.js +0 -57
  354. package/src/redis_zshift.test.js +0 -58
  355. package/src/round.test.js +0 -56
  356. package/src/sanitize_dash_name.test.js +0 -59
  357. package/src/sanitize_var_name.test.js +0 -39
  358. package/src/shell_spawn.test.js +0 -30
  359. package/src/str_camel_to_snake.test.js +0 -17
  360. package/src/stream_curl_progress.d/basic +0 -3
  361. package/src/stream_curl_progress.d/basic.json +0 -42
  362. package/src/stream_curl_progress.test.js +0 -17
  363. package/src/stream_data_ln.test.js +0 -24
  364. package/src/stream_map_parallel.test.js +0 -26
  365. package/src/stream_multiplex.test.js +0 -67
  366. package/src/stream_strpbrk.test.js +0 -29
  367. package/src/urlclean.test.js +0 -18
  368. package/src/urlmod.test.js +0 -40
  369. package/src/urlparts.test.js +0 -294
@@ -1,33 +0,0 @@
1
- const assert = require('assert');
2
- const format_ms3 = require('./format_ms3');
3
- const msval = require('./msval');
4
-
5
- const items = [
6
- ['00:00.000', ''],
7
- ['00:00.000', null],
8
- ['00:00.000', undefined],
9
- ['00:00.000', msval(0, 0, 0, 0)],
10
- ['00:00.001', msval(0, 0, 0, 1)],
11
- ['00:00.900', msval(0, 0, 0, 900)],
12
- ['00:01.000', msval(0, 0, 1, 0)],
13
- ['00:01.500', msval(0, 0, 1, 500)],
14
- ['00:02.000', msval(0, 0, 2, 0)],
15
- ['00:05.445', msval(0, 0, 5, 445)],
16
- ['01:00.000', msval(0, 1, 0, 0)],
17
- ['12:00.000', msval(0, 12, 0, 0)],
18
- ['12:12.012', msval(0, 12, 12, 12)],
19
- ['01:00:00.000', msval(1, 0, 0, 0)],
20
- ['01:01:00.000', msval(1, 1, 0, 0)],
21
- ['01:01:01.000', msval(1, 1, 1, 0)],
22
- ['01:01:01.001', msval(1, 1, 1, 1)],
23
- ['12:12:12.012', msval(12, 12, 12, 12)],
24
- ['999:00:00.000', msval(999, 0, 0, 0)],
25
- ];
26
-
27
- describe('format_ms3', function () {
28
- items.forEach(function ([expected, input]) {
29
- it(`${input} → ${expected}`, function () {
30
- assert.strictEqual(format_ms3(input), expected);
31
- });
32
- });
33
- });
@@ -1,22 +0,0 @@
1
- const assert = require('assert');
2
- const format_percents = require('./format_percents');
3
-
4
- const items = [
5
- ['', '0%'],
6
- [0, '0%'],
7
- [0.01, '1.00%'],
8
- [0.0101, '1.01%'],
9
- [0.1, '10.00%'],
10
- [0.5, '50.00%'],
11
- [0.99, '99.00%'],
12
- [0.9901, '99.01%'],
13
- [1, '100%'],
14
- ];
15
-
16
- describe('format_percents', function () {
17
- items.forEach(function ([input, expected]) {
18
- it(`${input} → ${expected}`, function () {
19
- assert.strictEqual(format_percents(input), expected);
20
- });
21
- });
22
- });
@@ -1,19 +0,0 @@
1
- const assert = require('assert');
2
- const format_progress_bytes = require('./format_progress_bytes');
3
-
4
- const items = [
5
- ['~', {percents: 0, total: 0, done: 0, rate: 0, eta: 0, duration: 0}],
6
- ['~ duration=00:00:01', {percents: 0, total: 0, done: 0, rate: 0, eta: 0, duration: 1}],
7
- ['25.25% | 5.0MB of 15.0MB at ~ ETA ~ duration=00:00:01', {percents: 0.2525, total: 15*1024*1024, done: 5*1024*1024, rate: 0, eta: 0, duration: 1}],
8
- ['25.25% | 5.0MB of 15.0MB at 10.0MB/s ETA 00:00:05 duration=00:00:01', {percents: 0.2525, total: 15*1024*1024, done: 5*1024*1024, rate: 10*1024*1024, eta: 5, duration: 1}],
9
- // edge case: done > total
10
- ['15.0MB at 10.0MB/s duration=00:00:01', {percents: 5.2525, total: 5*1024*1024, done: 15*1024*1024, rate: 10*1024*1024, eta: 5, duration: 1}],
11
- ];
12
-
13
- describe('format_progress_bytes', function () {
14
- items.forEach(function ([expected, input]) {
15
- it(expected, function () {
16
- assert.strictEqual(format_progress_bytes(input), expected);
17
- });
18
- });
19
- });
@@ -1,19 +0,0 @@
1
- const assert = require('assert');
2
- const format_progress_kilo = require('./format_progress_kilo');
3
-
4
- const items = [
5
- ['~', {percents: 0, total: 0, done: 0, rate: 0, eta: 0, duration: 0}],
6
- ['~ duration=00:00:01', {percents: 0, total: 0, done: 0, rate: 0, eta: 0, duration: 1}],
7
- ['25.25% | 5.00M of 15.00M at ~ ETA ~ duration=00:00:01', {percents: 0.2525, total: 15*1000*1000, done: 5*1000*1000, rate: 0, eta: 0, duration: 1}],
8
- ['25.25% | 5.00M of 15.00M at 10.00M/s ETA 00:00:05 duration=00:00:01', {percents: 0.2525, total: 15*1000*1000, done: 5*1000*1000, rate: 10*1000*1000, eta: 5, duration: 1}],
9
- // edge case: done > total
10
- ['15.00M at 10.00M/s duration=00:00:01', {percents: 5.2525, total: 5*1000*1000, done: 15*1000*1000, rate: 10*1000*1000, eta: 5, duration: 1}],
11
- ];
12
-
13
- describe('format_progress_kilo', function () {
14
- items.forEach(function ([expected, input]) {
15
- it(expected, function () {
16
- assert.strictEqual(format_progress_kilo(input), expected);
17
- });
18
- });
19
- });
@@ -1,42 +0,0 @@
1
- const assert = require('assert');
2
- const format_seconds = require('./format_seconds');
3
-
4
- const items = [
5
- ['-00:00:01', -1],
6
- ['-00:00:10', -10],
7
- ['-00:01:40', -100],
8
- ['-00:16:40', -1000],
9
- ['-02:46:40', -10000],
10
- ['-27:46:40', -100000],
11
- ['-277:46:40', -1000000],
12
- ['00:00:00', 0],
13
- ['00:00:00', 0.1],
14
- ['00:00:00', 0.12345],
15
- ['00:00:00', 0.5],
16
- ['00:00:00', 0.6],
17
- ['00:00:00', 0.9],
18
- ['00:00:00', 0.99],
19
- ['00:00:00', 0.999],
20
- ['00:00:00', -0.1],
21
- ['00:00:00', -0.12345],
22
- ['00:00:00', -0.5],
23
- ['00:00:00', -0.6],
24
- ['00:00:00', -0.9],
25
- ['00:00:00', -0.99],
26
- ['00:00:00', -0.999],
27
- ['00:00:01', 1],
28
- ['00:00:10', 10],
29
- ['00:01:40', 100],
30
- ['00:16:40', 1000],
31
- ['02:46:40', 10000],
32
- ['27:46:40', 100000],
33
- ['277:46:40', 1000000],
34
- ];
35
-
36
- describe('format_seconds', function () {
37
- items.forEach(function ([expected, ...args]) {
38
- it(`${args} → ${expected}`, function () {
39
- assert.strictEqual(format_seconds(...args), expected);
40
- });
41
- });
42
- });
@@ -1,28 +0,0 @@
1
- const assert = require('assert');
2
- const format_thousands = require('./format_thousands');
3
-
4
- const items = [
5
- ['-1', -1],
6
- ['-100', -100],
7
- ['-1,000', -1000],
8
- ['-10,000', -10000],
9
- ['-100,000', -100000],
10
- ['-1,000,000', -1000000],
11
- ['1', 1],
12
- ['100', 100],
13
- ['1,000', 1000],
14
- ['10,000', 10000],
15
- ['100,000', 100000],
16
- ['1,000,000', 1000000],
17
- ['1.55', 1.55],
18
- ['1.1234512345', 1.1234512345],
19
- ['123,456,789.01234', 123456789.01234],
20
- ];
21
-
22
- describe('format_thousands', function () {
23
- items.forEach(function ([expected, ...args]) {
24
- it(`${args} → ${expected}`, function () {
25
- assert.strictEqual(format_thousands(...args), expected);
26
- });
27
- });
28
- });
@@ -1,11 +0,0 @@
1
- const assert = require('assert');
2
- const fs_file_md5 = require('./fs_file_md5');
3
- const fs_path_resolve = require('./fs_path_resolve');
4
-
5
- describe('fs_file_md5', function () {
6
- it('should calculate md5 fs_file_md5.js', async function () {
7
- const actual = await fs_file_md5(fs_path_resolve(__dirname, 'fs_file_md5.js'));
8
- const expected = '103bffdc1df3af79bfd3f4b8b1bd2ed7';
9
- assert.strictEqual(actual, expected);
10
- });
11
- });
@@ -1,24 +0,0 @@
1
- const assert = require('assert');
2
- const fs_fi = require('./fs_fi');
3
- const fs_mkdirp = require('./fs_mkdirp');
4
- const fs_path_resolve = require('./fs_path_resolve');
5
- const fs_tempdir = require('./fs_tempdir');
6
-
7
- describe('fs_mkdirp', function () {
8
- it('should accept empty array', async function () {
9
- await fs_tempdir(async function (d) {
10
- const tmp = fs_path_resolve(d, 'a/b/c/d/e');
11
- await fs_mkdirp(tmp);
12
- assert(await fs_fi(tmp).then(v => v.isDirectory()));
13
- });
14
- });
15
- it('should create the same directory structure in parallel', async function () {
16
- await fs_tempdir(async function (d) {
17
- const tmp = fs_path_resolve(d, 'a/b/c/d/e/f/g/h');
18
- await Promise.all(Array(10).fill(tmp).map(async function () {
19
- await fs_mkdirp(tmp);
20
- assert(await fs_fi(tmp).then(v => v.isDirectory()));
21
- }));
22
- });
23
- });
24
- });
@@ -1,22 +0,0 @@
1
- const assert = require('assert');
2
- const fs_path_extname = require('./fs_path_extname');
3
-
4
- const tests = [
5
- ['.', ''],
6
- ['..', ''],
7
- ['.foo', ''],
8
- ['..foo', '.foo'],
9
- ['.foo.bar', '.bar'],
10
- ['fs_path_extname.js', '.js'],
11
- ['/path/to/file.js', '.js'],
12
- ['/path/to/file.js/foo', ''],
13
- ];
14
-
15
- describe('fs_path_extname', function () {
16
- tests.forEach(function ([input, expected]) {
17
- it(`${input} -> ${expected}`, function () {
18
- const actual = fs_path_extname(input);
19
- assert.strictEqual(actual, expected);
20
- });
21
- });
22
- });
@@ -1,27 +0,0 @@
1
- const assert = require('assert');
2
- const const_type = require('./const_type');
3
- const gettype = require('./gettype');
4
-
5
- const items = [
6
- ['null', null, const_type.null],
7
- ['undefined', undefined, const_type.undefined],
8
- ['boolean', true, const_type.boolean],
9
- ['number', 1, const_type.number],
10
- ['bigint', 1n, const_type.bigint],
11
- ['nan', NaN, const_type.nan],
12
- ['-inf', Number.NEGATIVE_INFINITY, const_type.neg_inf],
13
- ['+inf', Number.POSITIVE_INFINITY, const_type.pos_inf],
14
- ['string', 's', const_type.string],
15
- ['symbol', Symbol(), const_type.symbol],
16
- ['function', () => 1, const_type.function],
17
- ['object', {}, const_type.object],
18
- ['array', [], const_type.array],
19
- ];
20
-
21
- describe('gettype', function () {
22
- items.forEach(function ([title, input, expected]) {
23
- it(title, function () {
24
- assert.deepStrictEqual(gettype(input), expected);
25
- });
26
- });
27
- });
@@ -1,15 +0,0 @@
1
- const assert = require('assert');
2
- const object_schema = require('./object_schema');
3
-
4
- describe('object_schema', function () {
5
- it('basic 1', function () {
6
- const actual = object_schema({aaa: 1, bbb: 2});
7
- const expected = {aaa: 'number', bbb: 'number'};
8
- assert.deepStrictEqual(actual, expected);
9
- });
10
- it('basic 2', function () {
11
- const actual = object_schema({aaa: 1, bbb: [1, 2, 3, 4, 'str']});
12
- const expected = {aaa: 'number', bbb: ['number', 'string']};
13
- assert.deepStrictEqual(actual, expected);
14
- });
15
- });
@@ -1,17 +0,0 @@
1
- const assert = require('assert');
2
- const object_walk_preorder = require('./object_walk_preorder');
3
-
4
- describe('object_walk_preorder', function () {
5
- it('basic 1', function () {
6
- const actual = [];
7
- const expected = ['aaa', 'bbb', 'ccc'];
8
- object_walk_preorder({aaa: 1, bbb: 2, ccc: 3}, (v,p) => actual.push(p.join('/')));
9
- assert.deepStrictEqual(actual, expected);
10
- });
11
- it('basic 2', function () {
12
- const actual = [];
13
- const expected = ['aaa', 'aaa/foo', 'aaa/foo/bar', 'aaa/foo/bar/baz', 'bbb', 'ccc'];
14
- object_walk_preorder({aaa: {foo: {bar: {baz: 1}}}, bbb: 2, ccc: 3}, (v,p) => actual.push(p.join('/')));
15
- assert.deepStrictEqual(actual, expected);
16
- });
17
- });
@@ -1,11 +0,0 @@
1
- const assert = require('assert');
2
- const parallel = require('./parallel');
3
-
4
- describe('parallel', function () {
5
- it('should reject when [spawn] is async function', function () {
6
- assert.rejects(parallel({spawn: async function () {}}));
7
- })
8
- it('should reject when [spawn] is async generator', function () {
9
- assert.rejects(parallel({spawn: async function* () {}}));
10
- })
11
- });
@@ -1,21 +0,0 @@
1
- const assert = require('assert');
2
- const parse_bytes = require('./parse_bytes');
3
-
4
- const items = [
5
- ['', Number.NaN],
6
- [null, Number.NaN],
7
- [undefined, Number.NaN],
8
- ['0KB', 0],
9
- ['1KB', 1024],
10
- ['2KB', 2048],
11
- ['35.45MB', Math.floor(35.45*1024*1024)],
12
- ['3.92GB', Math.floor(3.92*1024*1024*1024)],
13
- ];
14
-
15
- describe('parse_bytes', function () {
16
- items.forEach(function ([input, expected]) {
17
- it(`${input} → ${expected}`, function () {
18
- assert.strictEqual(expected, parse_bytes(input));
19
- });
20
- });
21
- });
@@ -1,32 +0,0 @@
1
- const assert = require('assert');
2
- const parse_hms = require('./parse_hms');
3
-
4
- const items = [
5
- ['', 0],
6
- [null, 0],
7
- [undefined, 0],
8
- ['0', 0],
9
- ['0:5', 5],
10
- ['00:05', 5],
11
- ['0:15', 15],
12
- ['0:15.123', 15.123],
13
- ['0:75.123', 75.123],
14
- [' 5', 5],
15
- [' 0:05 ', 5],
16
- [100, 100],
17
- ['1:2:3:4', NaN, 'Too many segments'],
18
- ['abc', NaN, 'Non-numeric'],
19
- ['0:ab', NaN, 'Non-numeric'],
20
- ['1:x:3', NaN, 'Non-numeric'],
21
- ];
22
-
23
- describe('parse_hms', function () {
24
- items.forEach(function ([input, expected, description]) {
25
- const title = description
26
- ? `${input} → ${expected} | ${description}`
27
- : `${input} → ${expected}`;
28
- it(title, function () {
29
- assert.strictEqual(expected, parse_hms(input));
30
- });
31
- });
32
- });
@@ -1,14 +0,0 @@
1
- const assert = require('assert');
2
- const parse_http_content_range = require('./parse_http_content_range');
3
-
4
- const items = [
5
- ['bytes 262144000-272629759/5037662208', {type: 'bytes', first: 262144000, last: 272629759, total: 5037662208}],
6
- ];
7
-
8
- describe('parse_http_content_range', function () {
9
- items.forEach(function ([expr, expected]) {
10
- it(expr, function () {
11
- assert.deepStrictEqual(parse_http_content_range(expr), expected);
12
- });
13
- });
14
- });
@@ -1,33 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- const Promise = require('bluebird');
4
- const cli = require('../cli');
5
- const now_human = require('../now_human');
6
-
7
- // Child ignores SIGTERM for 10 ms, but dies naturally before the grace loop ends
8
-
9
- cli(main);
10
-
11
- async function main()
12
- {
13
- let timer;
14
-
15
- process.on('SIGTERM', function () {
16
- console.log(`[${now_human()}][ignore-sigterm-for-10ms] SIGTERM_ignoring...`);
17
- timer ??= setTimeout(terminate, 10);
18
- });
19
- process.on('SIGINT', function () {
20
- console.log(`[${now_human()}][ignore-sigterm-for-10ms] SIGINT_ignoring...`);
21
- });
22
-
23
- for (let iter = 1, last = 100; iter <= last; ++iter) {
24
- console.log(`[${now_human()}][ignore-sigterm-for-10ms] ${iter} of ${last}`);
25
- await Promise.delay(10);
26
- }
27
- }
28
-
29
- function terminate()
30
- {
31
- console.log(`[${now_human()}][ignore-sigterm-for-10ms] TERMINATE_AFTER_10MS`);
32
- process.exit(0);
33
- }
@@ -1,22 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- const Promise = require('bluebird');
4
- const cli = require('../cli');
5
- const now_human = require('../now_human');
6
-
7
- cli(main);
8
-
9
- async function main()
10
- {
11
- process.on('SIGTERM', function () {
12
- console.log(`[${now_human()}][ignore-sigterm] SIGTERM_ignoring...`);
13
- });
14
- process.on('SIGINT', function () {
15
- console.log(`[${now_human()}][ignore-sigterm] SIGINT_ignoring...`);
16
- });
17
-
18
- for (let iter = 1, last = 100; iter <= last; ++iter) {
19
- console.log(`[${now_human()}][ignore-sigterm] ${iter} of ${last}`);
20
- await Promise.delay(10);
21
- }
22
- }
@@ -1,63 +0,0 @@
1
- const assert = require('assert');
2
- const pid_exists = require('./pid_exists');
3
- const pid_kill_grace = require('./pid_kill_grace');
4
- const shell_spawn = require('./shell_spawn');
5
- const stream = require('stream');
6
- const stream_each = require('./stream_each');
7
- const stream_lines = require('./stream_lines');
8
- const wait_while = require('./wait_while');
9
-
10
- describe('pid_kill_grace', function() {
11
-
12
- it('happy path', async function () {
13
- const proc = await shell_spawn(['sleep', '1m']).init();
14
- assert(pid_exists(proc.pid));
15
- await pid_kill_grace(proc.pid);
16
- assert(!pid_exists(proc.pid));
17
- });
18
-
19
- // handling errors and edge cases
20
-
21
- it('should throw "Failed to send SIGTERM to process 123"', async function () {
22
- const pid = 999999; // 🎲 unlikely to exist
23
- assert(!pid_exists(pid));
24
- await assert.rejects(pid_kill_grace(pid), /Failed to send SIGTERM to process \d+:/);
25
- });
26
-
27
- it.skip('should throw "Process 123 survived SIGKILL"', async function () {
28
- // How to implement this behavior?
29
- });
30
-
31
- it('should KILL process after grace period', async function () {
32
- const logs = [];
33
- const stdout = [];
34
- const proc = shell_spawn([`${__dirname}/pid_kill_grace.d/ignore-sigterm.js`]);
35
- const r = stream.promises.pipeline(proc.stdout, stream_lines(), stream_each(v => stdout.push(v)));
36
- await wait_while(() => !stdout.length);
37
- await Promise.all([
38
- r,
39
- pid_kill_grace(proc.pid, {grace_timeout_ms: 50, log: s => logs.push(s)})
40
- ]);
41
- assert(!pid_exists(proc.pid));
42
- assert(stdout.some(v => v.includes('SIGTERM_ignoring')));
43
- assert(logs.some(v => v.match(/Terminating process \d+: sending SIGTERM/)));
44
- assert(logs.some(v => v.match(/SIGTERM grace period expired for process \d+; sending SIGKILL/)));
45
- });
46
-
47
- it('Child ignores SIGTERM for 10ms, but dies naturally before the grace loop ends', async function () {
48
- const logs = [];
49
- const stdout = [];
50
- const proc = shell_spawn([`${__dirname}/pid_kill_grace.d/ignore-sigterm-for-10ms.js`]);
51
- const r = stream.promises.pipeline(proc.stdout, stream_lines(), stream_each(v => stdout.push(v)));
52
- await wait_while(() => !stdout.length);
53
- await Promise.all([
54
- r,
55
- pid_kill_grace(proc.pid, {grace_timeout_ms: 50, log: s => logs.push(s)})
56
- ]);
57
- assert(!pid_exists(proc.pid));
58
- assert(stdout.some(v => v.includes('SIGTERM_ignoring')));
59
- assert(stdout.some(v => v.includes('TERMINATE_AFTER_10MS')));
60
- assert(logs.some(v => v.match(/Terminating process \d+: sending SIGTERM/)));
61
- assert(!logs.some(v => v.match(/SIGTERM grace period expired for process \d+; sending SIGKILL/)));
62
- });
63
- });
@@ -1,58 +0,0 @@
1
- const Promise = require('bluebird');
2
- const assert = require('assert');
3
- const fs_rmf = require('./fs_rmf');
4
- const net = require('net');
5
- const ping_socket = require('./ping_socket');
6
- const random_hex = require('./random_hex');
7
-
8
- const socket = '/tmp/ping_socket_test.sock';
9
-
10
- describe('ping_socket', function () {
11
-
12
- afterEach(async function () {
13
- await fs_rmf(socket);
14
- });
15
-
16
- it('should receive exact string from server', async function () {
17
- const uid = random_hex();
18
- const server = net.createServer(client => client.resume().end(uid));
19
- try {
20
- await new Promise(resolve => server.listen(socket, resolve));
21
- const buf = await ping_socket(socket);
22
- assert.strictEqual(buf.toString(), uid);
23
- }
24
- finally {
25
- await server_close(server);
26
- }
27
- });
28
-
29
- it('should throw Socket Timeout', async function () {
30
- const clients = [];
31
- const server = net.createServer(client => clients.push(client));
32
- try {
33
- await new Promise(resolve => server.listen(socket, resolve));
34
- await assert.rejects(ping_socket(socket, 'PING', 100), {message: 'Socket Timeout'});
35
- }
36
- finally {
37
- clients.forEach(v => v.resume().end());
38
- await server_close(server);
39
- }
40
- });
41
-
42
- it('should throw ENOENT', async function () {
43
- await assert.rejects(ping_socket(socket), {
44
- code: 'ENOENT',
45
- syscall: 'connect',
46
- address: socket,
47
- });
48
- });
49
- });
50
-
51
- async function server_close(server)
52
- {
53
- return new Promise(function (resolve, reject) {
54
- server.close(function (error) {
55
- error ? reject(error) : resolve();
56
- });
57
- });
58
- }
@@ -1,20 +0,0 @@
1
- const assert = require('assert');
2
- const plural = require('./plural');
3
-
4
- const tests = [
5
- ['1 apple', 1, '# apple', '# apples'],
6
- ['2 apples', 2, '# apple', '# apples'],
7
- ['10 apples', 10, '# apple', '# apples'],
8
- ['21 apple', 21, '# apple', '# apples'],
9
- ['0 apples', 0, '# apple', '# apples'],
10
- ['No apples', 0, '# apple', '# apples', 'No apples'],
11
- ];
12
-
13
- describe('plural', function () {
14
- tests.forEach(function ([expected, ...args],) {
15
- it(expected, function () {
16
- const actual = plural(...args);
17
- assert.deepStrictEqual(actual, expected);
18
- });
19
- });
20
- });
package/src/range.test.js DELETED
@@ -1,41 +0,0 @@
1
- const assert = require('assert');
2
- const range = require('./range');
3
-
4
- const cases = [
5
- // 1-argument: (stop)
6
- {args: [10], expected: [0,1,2,3,4,5,6,7,8,9]},
7
- {args: [-10], expected: []}, // 💎 Consider non-standard semantics: range(-5) -> [0,-1,-2,-3,-4]
8
-
9
- // 2-arguments: (start, stop)
10
- {args: [3, 7], expected: [3,4,5,6]},
11
- {args: [0, 0], expected: []},
12
- {args: [5, 3], expected: []}, // positive direction, start > stop → empty
13
-
14
- // 3-arguments: (start, stop, step)
15
- {args: [3, 10, 2], expected: [3,5,7,9]},
16
- {args: [3, 10, 3], expected: [3,6,9]},
17
-
18
- // Negative step
19
- {args: [10, 3, -2], expected: [10,8,6,4]},
20
- {args: [10, 3, -3], expected: [10,7,4]},
21
-
22
- // Negative step but no progression
23
- {args: [3, 10, -1], expected: []}, // step direction does not match range
24
-
25
- // Step = 1 edge
26
- {args: [5, 5, 1], expected: []},
27
- {args: [5, 6, 1], expected: [5]},
28
-
29
- // Step = -1 edge
30
- {args: [5, 5, -1], expected: []},
31
- {args: [6, 5, -1], expected: [6]},
32
- ];
33
-
34
- describe('range', function () {
35
- cases.forEach(function (item, i) {
36
- it(`range #${i+1}: ${JSON.stringify(item)}`, function () {
37
- const actual = range(...item.args);
38
- assert.deepStrictEqual(actual, item.expected);
39
- })
40
- });
41
- });