@vbarbarosh/node-helpers 3.75.0 → 3.76.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 (367) hide show
  1. package/README.md +29 -3
  2. package/dist/browser.js +1 -2504
  3. package/package.json +31 -11
  4. package/src/HeartbeatServer.js +24 -3
  5. package/src/HeartbeatServer.md +33 -0
  6. package/src/array_chunk.js +1 -1
  7. package/src/array_chunk.md +8 -0
  8. package/src/array_chunk_balanced.md +14 -0
  9. package/src/array_fps.md +12 -0
  10. package/src/array_gcd.js +4 -2
  11. package/src/array_gcd.md +2 -1
  12. package/src/array_group.js +3 -3
  13. package/src/array_group.md +14 -0
  14. package/src/array_group_map.js +3 -3
  15. package/src/array_group_map.md +13 -0
  16. package/src/array_index.js +2 -2
  17. package/src/array_index.md +9 -0
  18. package/src/array_lcm.js +4 -2
  19. package/src/array_lcm.md +2 -1
  20. package/src/array_max.js +11 -4
  21. package/src/array_max.md +1 -1
  22. package/src/array_min.js +11 -4
  23. package/src/array_min.md +1 -1
  24. package/src/array_permutations.js +4 -0
  25. package/src/array_permutations.md +13 -0
  26. package/src/array_sort.js +7 -2
  27. package/src/array_sort.md +13 -0
  28. package/src/array_sort_other.js +8 -5
  29. package/src/array_sort_other.md +11 -0
  30. package/src/array_sum.js +2 -2
  31. package/src/array_sum.md +8 -0
  32. package/src/array_unique.js +2 -2
  33. package/src/array_unique_last.js +2 -2
  34. package/src/assert_valid_expires_at.md +10 -0
  35. package/src/clamp.md +9 -0
  36. package/src/cli-apps/watchdog.js +5 -0
  37. package/src/cli.js +3 -1
  38. package/src/cli.md +15 -0
  39. package/src/const_stream.md +7 -0
  40. package/src/const_type.md +5 -0
  41. package/src/countdown.js +22 -5
  42. package/src/countdown.md +21 -0
  43. package/src/crypto_decrypt_aes256.md +13 -0
  44. package/src/crypto_encrypt_aes256.md +13 -0
  45. package/src/crypto_hash_md5.md +10 -0
  46. package/src/crypto_hash_sha256.md +10 -0
  47. package/src/crypto_hmac_sha256.md +11 -0
  48. package/src/date_add_hours.md +8 -0
  49. package/src/date_add_milliseconds.md +4 -0
  50. package/src/date_add_minutes.md +4 -0
  51. package/src/date_add_months.md +13 -0
  52. package/src/date_add_seconds.md +4 -0
  53. package/src/date_diff_seconds.md +4 -0
  54. package/src/date_is_leap_year.md +9 -0
  55. package/src/escape_content_disposition.js +6 -3
  56. package/src/escape_content_disposition.md +13 -0
  57. package/src/escape_regexp.md +7 -0
  58. package/src/eta.js +7 -1
  59. package/src/eta.md +18 -0
  60. package/src/factorize_ms.js +3 -0
  61. package/src/factorize_ms.md +10 -0
  62. package/src/fastdl.js +14 -3
  63. package/src/fcmp_dates.md +12 -0
  64. package/src/fcmp_default.js +7 -0
  65. package/src/fcmp_default.md +29 -0
  66. package/src/fcmp_default_desc.js +4 -7
  67. package/src/fcmp_default_desc.md +10 -0
  68. package/src/fcmp_from_spec.md +13 -0
  69. package/src/fcmp_numbers.md +11 -0
  70. package/src/fcmp_tuples.md +17 -0
  71. package/src/fcmp_utf8_bin.md +14 -0
  72. package/src/fcmp_utf8_ci.md +14 -0
  73. package/src/fcmp_utf8_cs.md +15 -0
  74. package/src/fcmp_utf8_natural_bin.js +38 -0
  75. package/src/fcmp_utf8_natural_bin.md +8 -0
  76. package/src/fcmp_utf8_natural_ci.md +13 -0
  77. package/src/fcmp_utf8_natural_cs.md +13 -0
  78. package/src/fcmpx.md +26 -9
  79. package/src/filter1_from_spec.js +3 -3
  80. package/src/format_bytes.md +15 -0
  81. package/src/format_date.md +7 -0
  82. package/src/format_date_fs.md +7 -0
  83. package/src/format_date_human.md +6 -0
  84. package/src/format_date_ymd.md +6 -0
  85. package/src/format_error_report.js +3 -3
  86. package/src/format_error_report.md +12 -0
  87. package/src/format_kilo.md +13 -0
  88. package/src/format_ms.js +3 -2
  89. package/src/format_ms.md +12 -0
  90. package/src/format_ms2.js +6 -3
  91. package/src/format_ms2.md +12 -0
  92. package/src/format_ms3.js +3 -2
  93. package/src/format_ms3.md +12 -0
  94. package/src/format_percents.md +10 -0
  95. package/src/format_progress_bytes.md +13 -0
  96. package/src/format_progress_kilo.md +10 -0
  97. package/src/format_seconds.md +11 -0
  98. package/src/format_thousands.md +9 -0
  99. package/src/fs_append.md +7 -0
  100. package/src/fs_append_json.md +8 -0
  101. package/src/fs_append_utf8.md +6 -0
  102. package/src/fs_assert_file_exists.md +3 -0
  103. package/src/fs_assert_file_readable.js +1 -1
  104. package/src/fs_assert_file_readable.md +3 -0
  105. package/src/fs_assert_file_socket.md +2 -0
  106. package/src/fs_copy.md +7 -0
  107. package/src/fs_copy_excl.md +2 -0
  108. package/src/fs_exists.md +6 -0
  109. package/src/fs_fclose.md +5 -0
  110. package/src/fs_fi.js +13 -1
  111. package/src/fs_fi.md +11 -0
  112. package/src/fs_file_md5.md +8 -0
  113. package/src/fs_find.md +7 -0
  114. package/src/fs_fopen.md +6 -0
  115. package/src/fs_fread.js +2 -2
  116. package/src/fs_fread.md +11 -0
  117. package/src/fs_fsize.md +2 -0
  118. package/src/fs_fstat.md +2 -0
  119. package/src/fs_fwrite.js +2 -2
  120. package/src/fs_fwrite.md +9 -0
  121. package/src/fs_list.md +5 -0
  122. package/src/fs_list_deep.md +5 -0
  123. package/src/fs_ls.md +2 -0
  124. package/src/fs_lsr.md +4 -0
  125. package/src/fs_lstat.md +3 -0
  126. package/src/fs_mkdir.md +3 -0
  127. package/src/fs_mkdirp.js +3 -30
  128. package/src/fs_mkdirp.md +7 -0
  129. package/src/fs_path_basename.md +2 -0
  130. package/src/fs_path_dirname.md +2 -0
  131. package/src/fs_path_extname.md +9 -0
  132. package/src/fs_path_join.md +2 -0
  133. package/src/fs_path_relative.md +2 -0
  134. package/src/fs_path_resolve.md +2 -0
  135. package/src/fs_path_tempdir.md +2 -0
  136. package/src/fs_path_untildify.md +8 -0
  137. package/src/fs_read.md +3 -0
  138. package/src/fs_read_buffer.md +5 -0
  139. package/src/fs_read_json.md +6 -0
  140. package/src/fs_read_lines.md +7 -0
  141. package/src/fs_read_stream.md +2 -0
  142. package/src/fs_read_utf8.md +5 -0
  143. package/src/fs_readdir.md +3 -0
  144. package/src/fs_readlink.md +6 -0
  145. package/src/fs_rename.md +6 -0
  146. package/src/fs_rm.md +4 -0
  147. package/src/fs_rmdir.md +3 -0
  148. package/src/fs_rmf.md +2 -0
  149. package/src/fs_rmrf.md +8 -0
  150. package/src/fs_sha256.js +16 -0
  151. package/src/fs_sha256.md +9 -0
  152. package/src/fs_size.js +2 -2
  153. package/src/fs_size.md +6 -0
  154. package/src/fs_stat.md +2 -0
  155. package/src/fs_tempdir.js +20 -5
  156. package/src/fs_touch.md +6 -0
  157. package/src/fs_walk.js +2 -2
  158. package/src/fs_walk.md +14 -0
  159. package/src/fs_write.md +3 -0
  160. package/src/fs_write_json.md +7 -0
  161. package/src/fs_write_stream.md +2 -0
  162. package/src/gettype.md +13 -0
  163. package/src/http_delete.md +11 -0
  164. package/src/http_get_blob.md +8 -0
  165. package/src/http_get_buffer.md +10 -0
  166. package/src/http_get_file.js +8 -8
  167. package/src/http_get_file.md +14 -0
  168. package/src/http_get_json.md +10 -0
  169. package/src/http_get_stream.md +14 -0
  170. package/src/http_get_stream_range.js +27 -9
  171. package/src/http_get_stream_range.md +22 -0
  172. package/src/http_get_utf8.md +9 -0
  173. package/src/http_head.md +9 -0
  174. package/src/http_patch_json.md +10 -0
  175. package/src/http_post_json.md +11 -0
  176. package/src/http_post_multipart.md +15 -0
  177. package/src/http_post_urlencoded.md +11 -0
  178. package/src/http_put_buffer.md +9 -0
  179. package/src/http_put_file.js +9 -6
  180. package/src/http_put_file.md +16 -0
  181. package/src/http_put_json.md +11 -0
  182. package/src/http_put_utf8.md +9 -0
  183. package/src/http_range_parse.js +6 -3
  184. package/src/http_range_parse.md +18 -0
  185. package/src/http_stream_range.js +35 -22
  186. package/src/http_stream_range.md +29 -0
  187. package/src/identity.md +2 -0
  188. package/src/ignore.md +2 -0
  189. package/src/json_stringify_safe.md +10 -0
  190. package/src/json_stringify_stable.md +9 -0
  191. package/src/logger.js +2 -3
  192. package/src/logger.md +15 -0
  193. package/src/make_progress.js +8 -5
  194. package/src/make_progress.md +20 -0
  195. package/src/math_gcd.js +2 -1
  196. package/src/mongo_stream_upsert.js +10 -3
  197. package/src/mongo_stream_upsert.md +17 -0
  198. package/src/mongo_stream_write.js +10 -3
  199. package/src/mongo_stream_write.md +16 -0
  200. package/src/msval.md +10 -0
  201. package/src/now_fs.md +7 -0
  202. package/src/now_human.md +6 -0
  203. package/src/object_defaults.md +11 -0
  204. package/src/object_schema.js +2 -1
  205. package/src/object_schema.md +12 -0
  206. package/src/object_walk_preorder.md +16 -0
  207. package/src/parallel.js +23 -10
  208. package/src/parse_bytes.js +4 -2
  209. package/src/parse_bytes.md +15 -0
  210. package/src/parse_hms.js +1 -1
  211. package/src/parse_http_content_range.js +9 -5
  212. package/src/parse_http_content_range.md +16 -0
  213. package/src/perf_end_human.md +10 -0
  214. package/src/perf_end_ms.md +8 -0
  215. package/src/perf_measure.md +10 -0
  216. package/src/perf_measure_human.md +8 -0
  217. package/src/perf_start.md +9 -0
  218. package/src/pgid_exists.md +6 -0
  219. package/src/pgid_kill_grace.js +1 -1
  220. package/src/pgid_kill_grace.md +15 -0
  221. package/src/pid_exists.md +5 -0
  222. package/src/pid_kill_grace.js +1 -1
  223. package/src/pid_kill_grace.md +14 -0
  224. package/src/plural.md +13 -0
  225. package/src/random_hex.md +9 -0
  226. package/src/random_int.md +8 -0
  227. package/src/range.js +4 -2
  228. package/src/range.md +2 -0
  229. package/src/redis_connect.js +1 -1
  230. package/src/redis_connect.md +10 -0
  231. package/src/redis_lshift.md +14 -0
  232. package/src/redis_poll.js +1 -0
  233. package/src/redis_poll.md +17 -0
  234. package/src/redis_poll_zshift_callback_rpush.js +1 -2
  235. package/src/redis_poll_zshift_callback_rpush.md +17 -0
  236. package/src/redis_poll_zshift_spawn_rpush.js +2 -1
  237. package/src/redis_poll_zshift_spawn_rpush.md +20 -0
  238. package/src/redis_zshift.md +14 -0
  239. package/src/round.js +7 -8
  240. package/src/round.md +15 -0
  241. package/src/sanitize_dash_name.md +13 -0
  242. package/src/sanitize_filename.md +9 -0
  243. package/src/sanitize_var_name.md +14 -0
  244. package/src/sftp_get_file_info.js +2 -2
  245. package/src/sftp_get_file_info.md +14 -0
  246. package/src/sftp_get_stream_range.js +32 -22
  247. package/src/sftp_get_stream_range.md +20 -0
  248. package/src/shell_curl_progress.js +2 -1
  249. package/src/shell_curl_progress.md +17 -0
  250. package/src/shell_lines.js +2 -2
  251. package/src/shell_lines.md +1 -1
  252. package/src/shell_spawn.js +7 -0
  253. package/src/shell_ytdlp_progress.js +2 -1
  254. package/src/shell_ytdlp_progress.md +17 -0
  255. package/src/str_camel_to_snake.md +11 -0
  256. package/src/str_parse_kv.md +11 -0
  257. package/src/stream_curl_progress.md +14 -0
  258. package/src/stream_data_ln.js +7 -1
  259. package/src/stream_discard.md +8 -0
  260. package/src/stream_group.md +3 -0
  261. package/src/stream_gunzip.md +7 -0
  262. package/src/stream_hash.md +10 -0
  263. package/src/stream_map.js +8 -1
  264. package/src/stream_map_parallel.js +9 -1
  265. package/src/stream_md5.md +9 -0
  266. package/src/stream_multiplex.js +11 -0
  267. package/src/stream_multiplex.md +16 -0
  268. package/src/stream_through.md +3 -0
  269. package/src/stream_transform.md +2 -0
  270. package/src/stream_xml_analyze.js +9 -1
  271. package/src/stream_xml_parse.js +9 -1
  272. package/src/stream_ytdlp_progress.js +1 -1
  273. package/src/stream_ytdlp_progress.md +18 -0
  274. package/src/strtr.js +15 -5
  275. package/src/strtr.md +11 -0
  276. package/src/urlclean.js +9 -2
  277. package/src/urlmod.js +5 -0
  278. package/src/urlparts.md +17 -0
  279. package/src/wait_while.js +1 -1
  280. package/src/wait_while.md +1 -1
  281. package/src/HeartbeatServer.test.js +0 -31
  282. package/src/array_chunk.test.js +0 -24
  283. package/src/array_chunk_balanced.test.js +0 -37
  284. package/src/array_fps.test.js +0 -72
  285. package/src/array_gcd.test.js +0 -10
  286. package/src/array_index.test.js +0 -14
  287. package/src/array_lcm.test.js +0 -12
  288. package/src/array_max.test.js +0 -20
  289. package/src/array_min.test.js +0 -20
  290. package/src/array_permutations.test.js +0 -20
  291. package/src/array_sort.test.js +0 -85
  292. package/src/array_sort_other.test.js +0 -9
  293. package/src/array_sum.test.js +0 -11
  294. package/src/cli-apps/watchdog.d/connect_close.js +0 -17
  295. package/src/cli-apps/watchdog.d/connect_close2.js +0 -20
  296. package/src/cli-apps/watchdog.d/connect_close3.js +0 -25
  297. package/src/cli-apps/watchdog.d/connect_no_ping.js +0 -13
  298. package/src/cli-apps/watchdog.d/early_exit.js +0 -7
  299. package/src/cli-apps/watchdog.d/flood.js +0 -13
  300. package/src/cli-apps/watchdog.d/flood2.js +0 -15
  301. package/src/cli-apps/watchdog.d/hang.js +0 -8
  302. package/src/cli-apps/watchdog.d/huge_delay.js +0 -18
  303. package/src/cli-apps/watchdog.d/ignore_sigterm.js +0 -29
  304. package/src/cli-apps/watchdog.d/late_heartbeat.js +0 -21
  305. package/src/cli-apps/watchdog.d/my-exit-after-2-pings.js +0 -16
  306. package/src/cli-apps/watchdog.d/my-happy-path.js +0 -16
  307. package/src/cli-apps/watchdog.d/my-ignore-sigterm.js +0 -22
  308. package/src/cli-apps/watchdog.d/my-never-ping.js +0 -15
  309. package/src/cli-apps/watchdog.d/no_heartbeat.js +0 -5
  310. package/src/cli-apps/watchdog.d/ok.js +0 -17
  311. package/src/cli-apps/watchdog.d/quick-exit-after-2-pings.js +0 -15
  312. package/src/cli-apps/watchdog.d/quick-hang-after-1-ping.js +0 -15
  313. package/src/cli-apps/watchdog.d/spawn_children.js +0 -14
  314. package/src/cli-apps/watchdog.test.js +0 -48
  315. package/src/crypto_encrypt_aes256.test.js +0 -10
  316. package/src/crypto_hash_sha256.test.js +0 -10
  317. package/src/date_add_months.test.js +0 -40
  318. package/src/date_is_leap_year.test.js +0 -14
  319. package/src/escape_content_disposition.test.js +0 -22
  320. package/src/fcmp_from_spec.test.js +0 -91
  321. package/src/fcmpx.test.js +0 -173
  322. package/src/filter1_from_spec.test.js +0 -31
  323. package/src/format_bytes.test.js +0 -22
  324. package/src/format_error_report.d/src/1.js +0 -26
  325. package/src/format_error_report.d/src/2.js +0 -29
  326. package/src/format_kilo.test.js +0 -25
  327. package/src/format_ms.test.js +0 -33
  328. package/src/format_ms2.test.js +0 -33
  329. package/src/format_ms3.test.js +0 -33
  330. package/src/format_percents.test.js +0 -22
  331. package/src/format_progress_bytes.test.js +0 -19
  332. package/src/format_progress_kilo.test.js +0 -19
  333. package/src/format_seconds.test.js +0 -42
  334. package/src/format_thousands.test.js +0 -28
  335. package/src/fs_file_md5.test.js +0 -11
  336. package/src/fs_mkdirp.test.js +0 -24
  337. package/src/fs_path_extname.test.js +0 -22
  338. package/src/gettype.test.js +0 -27
  339. package/src/object_schema.test.js +0 -15
  340. package/src/object_walk_preorder.test.js +0 -17
  341. package/src/parallel.test.js +0 -11
  342. package/src/parse_bytes.test.js +0 -21
  343. package/src/parse_hms.test.js +0 -32
  344. package/src/parse_http_content_range.test.js +0 -14
  345. package/src/pid_kill_grace.d/ignore-sigterm-for-10ms.js +0 -33
  346. package/src/pid_kill_grace.d/ignore-sigterm.js +0 -22
  347. package/src/pid_kill_grace.test.js +0 -63
  348. package/src/ping_socket.test.js +0 -58
  349. package/src/plural.test.js +0 -20
  350. package/src/range.test.js +0 -41
  351. package/src/redis_lshift.test.js +0 -57
  352. package/src/redis_zshift.test.js +0 -58
  353. package/src/round.test.js +0 -56
  354. package/src/sanitize_dash_name.test.js +0 -59
  355. package/src/sanitize_var_name.test.js +0 -39
  356. package/src/shell_spawn.test.js +0 -30
  357. package/src/str_camel_to_snake.test.js +0 -17
  358. package/src/stream_curl_progress.d/basic +0 -3
  359. package/src/stream_curl_progress.d/basic.json +0 -42
  360. package/src/stream_curl_progress.test.js +0 -17
  361. package/src/stream_data_ln.test.js +0 -24
  362. package/src/stream_map_parallel.test.js +0 -26
  363. package/src/stream_multiplex.test.js +0 -67
  364. package/src/stream_strpbrk.test.js +0 -29
  365. package/src/urlclean.test.js +0 -18
  366. package/src/urlmod.test.js +0 -40
  367. package/src/urlparts.test.js +0 -294
@@ -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
- });
@@ -1,57 +0,0 @@
1
- const assert = require('assert');
2
- const redis_lshift = require('./redis_lshift');
3
-
4
- const REDIS_HOST = '127.0.0.1';
5
- const REDIS_PORT = 6379;
6
- const REDIS_AUTH = null;
7
- const REDIS_QUEUE = 'TESTING';
8
-
9
- describe('redis_lshift', function () {
10
- it('should work with redis@1', async function () {
11
- await test_1_2_3(require('redis-v1'));
12
- });
13
- it('should work with redis@2', async function () {
14
- await test_1_2_3(require('redis-v2'));
15
- });
16
- it('should work with redis@3', async function () {
17
- await test_1_2_3(require('redis-v3'));
18
- });
19
- it('should work with redis@4', async function () {
20
- await test_4(require('redis-v4'));
21
- });
22
- });
23
-
24
- async function test_1_2_3(redis)
25
- {
26
- const r = redis.createClient(REDIS_PORT, REDIS_HOST, {password: REDIS_AUTH || undefined});
27
- try {
28
- const expected = 'aa,bb,cc,dd,ee'.split(',');
29
- await new Promise(function (resolve, reject) {
30
- r.del(REDIS_QUEUE, (e,v) => e ? reject(e) : resolve(v));
31
- });
32
- await new Promise(function (resolve, reject) {
33
- r.rpush(REDIS_QUEUE, ...expected, (e,v) => e ? reject(e) : resolve(v));
34
- });
35
- const actual = await redis_lshift(r, REDIS_QUEUE, expected.length);
36
- await assert.deepStrictEqual(actual, expected);
37
- }
38
- finally {
39
- await r.quit();
40
- }
41
- }
42
-
43
- async function test_4(redis)
44
- {
45
- const r = redis.createClient(REDIS_PORT, REDIS_HOST, {password: REDIS_AUTH || undefined});
46
- await r.connect();
47
- try {
48
- const expected = 'aa,bb,cc,dd,ee'.split(',');
49
- await r.DEL(REDIS_QUEUE);
50
- await r.RPUSH(REDIS_QUEUE, expected);
51
- const actual = await redis_lshift(r, REDIS_QUEUE, expected.length);
52
- await assert.deepStrictEqual(actual, expected);
53
- }
54
- finally {
55
- await r.quit();
56
- }
57
- }
@@ -1,58 +0,0 @@
1
- const assert = require('assert');
2
- const redis_zshift = require('./redis_zshift');
3
-
4
- const REDIS_HOST = '127.0.0.1';
5
- const REDIS_PORT = 6379;
6
- const REDIS_AUTH = null;
7
- const REDIS_QUEUE = 'TESTING';
8
-
9
- describe('redis_zshift', function () {
10
- it('should work with redis@1', async function () {
11
- await test_1_2_3(require('redis-v1'));
12
- });
13
- it('should work with redis@2', async function () {
14
- await test_1_2_3(require('redis-v2'));
15
- });
16
- it('should work with redis@3', async function () {
17
- await test_1_2_3(require('redis-v3'));
18
- });
19
- it('should work with redis@4', async function () {
20
- await test_4(require('redis-v4'));
21
- });
22
- });
23
-
24
- async function test_1_2_3(redis)
25
- {
26
- const r = redis.createClient(REDIS_PORT, REDIS_HOST, {password: REDIS_AUTH || undefined});
27
- try {
28
- const expected = 'aa,bb,cc,dd,ee'.split(',');
29
- await new Promise(function (resolve, reject) {
30
- r.del(REDIS_QUEUE, (e,v) => e ? reject(e) : resolve(v));
31
- });
32
- await new Promise(function (resolve, reject) {
33
- const args = [REDIS_QUEUE, ...expected.map((v,i) => [i,v]).flat()];
34
- r.zadd(args, (e,v) => e ? reject(e) : resolve(v));
35
- });
36
- const actual = await redis_zshift(r, REDIS_QUEUE, expected.length);
37
- await assert.deepStrictEqual(actual, expected);
38
- }
39
- finally {
40
- await r.quit();
41
- }
42
- }
43
-
44
- async function test_4(redis)
45
- {
46
- const r = redis.createClient(REDIS_PORT, REDIS_HOST, {password: REDIS_AUTH || undefined});
47
- await r.connect();
48
- try {
49
- const expected = 'aa,bb,cc,dd,ee'.split(',');
50
- await r.DEL(REDIS_QUEUE);
51
- await r.ZADD(REDIS_QUEUE, expected.map((value,i) => ({score: i, value})));
52
- const actual = await redis_zshift(r, REDIS_QUEUE, 5);
53
- await assert.deepStrictEqual(actual, expected);
54
- }
55
- finally {
56
- await r.quit();
57
- }
58
- }
package/src/round.test.js DELETED
@@ -1,56 +0,0 @@
1
- const assert = require('assert');
2
- const round = require('./round');
3
-
4
- const items = [
5
- [34, 25, 25],
6
- [37.5, 25, 50],
7
- [34.037531, 0.001, 34.038],
8
- [1.005, 0.01, 1.01],
9
- [0.99999, 0.00001, 0.99999],
10
-
11
- // Synthetic cases generated by DeepSeek
12
- [1.005, 0.001, 1.005], // More precise rounding
13
- [1.005, 0.1, 1.0], // Less precise rounding
14
- [1.015, 0.01, 1.02], // Another edge case with 5
15
- [1.025, 0.01, 1.03], // Yet another edge case
16
- [0.5, 1, 1], // Round to nearest integer
17
- [0.4, 1, 0], // Round down to integer
18
- [123.456, 0.01, 123.46], // Standard decimal rounding
19
- [123.456, 0.1, 123.5], // Different precision
20
- [123.456, 1, 123], // Round to whole number
21
- [123.456, 10, 120], // Round to tens
22
- [123.456, 100, 100], // Round to hundreds
23
- [0, 0.01, 0], // Zero value
24
- [-1.005, 0.01, -1.01], // Negative numbers
25
- [-1.015, 0.01, -1.02], // Negative edge case
26
- [-37.5, 25, -50], // Negative with integer precision
27
- [1.2345e-5, 1e-6, 0.000012], // Very small numbers
28
- [999.999, 0.001, 999.999], // Rounding that causes carry-over
29
- [0.0000000000001, 0.01, 0], // Extremely small number
30
- [Number.MAX_SAFE_INTEGER, 1000, 9007199254741000], // Large numbers
31
-
32
- [0.005, 0.01, 0.01],
33
- [-1.5, 1, -2], // Symmetric negative rounding (Math.abs is critical here)
34
- [-0.5, 1, -1], // Symmetric negative rounding for half
35
- [123456789123.45, 1000, 123456789000], // Testing very large numbers
36
- [1.2345e-20, 1e-20, 1e-20], // Testing very small numbers
37
- [1.0000000000000001, 0.0000000000000001, 1.0000000000000000], // Testing rounding near Number.EPSILON range
38
-
39
- [9007199254740992, 1, 9007199254740992],
40
- [9007199254740991.5, 1, 9007199254740992],
41
- [Number.MIN_SAFE_INTEGER, 1, Number.MIN_SAFE_INTEGER],
42
- [Number.MAX_SAFE_INTEGER, 1, Number.MAX_SAFE_INTEGER],
43
-
44
- // Out of scope of standard JS
45
- // [0.004999999999999999, 0.01, 0.0],
46
- // [Number.MIN_SAFE_INTEGER, 0.1, Number.MIN_SAFE_INTEGER],
47
- // [Number.MAX_SAFE_INTEGER, 0.1, Number.MAX_SAFE_INTEGER],
48
- ];
49
-
50
- describe('round', function () {
51
- items.forEach(function ([value, precision, expected],) {
52
- it(`${value} [${precision}] → ${expected}`, function () {
53
- assert.deepStrictEqual(round(value, precision), expected);
54
- });
55
- });
56
- });