@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,40 +0,0 @@
1
- const assert = require('assert');
2
- const urlmod = require('./urlmod');
3
-
4
- describe('urlmod', function () {
5
- it('should take no args', function () {
6
- assert.deepEqual(urlmod(), '');
7
- });
8
- it('should take basic args', function () {
9
- assert.deepEqual(urlmod('?a=1'), '?a=1');
10
- assert.deepEqual(urlmod('?a=1', {a: 2}), '?a=2');
11
- assert.deepEqual(urlmod('?a=1', {a: null}), '');
12
- assert.deepEqual(urlmod('?a=1', {b: 1}), '?a=1&b=1');
13
- assert.deepEqual(urlmod('?a=1', {b: 1, a: 2}), '?a=2&b=1');
14
- assert.deepEqual(urlmod('?a=1', {a: true}), '?a=1');
15
- assert.deepEqual(urlmod('?a=1', {a: false, b: true}), '?a=0&b=1');
16
- });
17
- it('should take `location`', function () {
18
- // const elem = document.createElement('A');
19
- // elem.href = 'http://www.example.com/some/path?a=1';
20
- // const location = elem.href;
21
- const location = {
22
- toString: function () {
23
- return 'http://www.example.com/some/path?a=1';
24
- },
25
- };
26
- assert.deepEqual(urlmod(location, {b: 2}), 'http://www.example.com/some/path?a=1&b=2');
27
- });
28
- it('should keep hash part', function () {
29
- assert.deepEqual(urlmod('#ex', {b: 2}), '?b=2#ex');
30
- assert.deepEqual(urlmod('#ex?a=1#ex', {b: 2}), '?b=2#ex?a=1#ex');
31
- assert.deepEqual(urlmod('?a=1#ex', {b: 2}), '?a=1&b=2#ex');
32
- assert.deepEqual(urlmod('/#ex', {b: 2}), '/?b=2#ex');
33
- assert.deepEqual(urlmod('http://www.example.com/some/path?a=1#ex', {b: 2}), 'http://www.example.com/some/path?a=1&b=2#ex');
34
- });
35
- it('should keep port', function () {
36
- const actual = urlmod('http://localhost:3000/auth/sign-in', {return: '/auth/profile'});
37
- const expected = 'http://localhost:3000/auth/sign-in?return=%2Fauth%2Fprofile';
38
- assert.strictEqual(actual, expected);
39
- })
40
- });
@@ -1,294 +0,0 @@
1
- const assert = require('assert');
2
- const edge_values = require('@vbarbarosh/type-helpers/src/edge_values');
3
- const urlparts = require('./urlparts');
4
-
5
- const extra_edge_values = [
6
- // whitespace strings
7
- {label: '" "', value: ' '},
8
- {label: '"\\t"', value: '\t'},
9
- {label: '"\\n"', value: '\n'},
10
- {label: '"\\r\\n"', value: '\r\n'},
11
-
12
- // numeric strings
13
- {label: '"0"', value: '0'},
14
- {label: '"1"', value: '1'},
15
- {label: '"NaN"', value: 'NaN'},
16
- {label: '"Infinity"', value: 'Infinity'},
17
-
18
- // weird unicode
19
- {label: '"💩"', value: '💩'},
20
- {label: '"😀"', value: '😀'},
21
- {label: '"привет"', value: 'привет'},
22
- {label: '"こんにちは"', value: 'こんにちは'},
23
-
24
- // dangerous chars
25
- {label: '"<script>"', value: '<script>'},
26
- {label: '"../"', value: '../'},
27
- {label: '"%20"', value: '%20'},
28
- {label: '"a?b=c"', value: 'a?b=c'},
29
- {label: '"a#b"', value: 'a#b'},
30
-
31
- // arrays
32
- {label: '[1,2,3]', value: [1, 2, 3]},
33
- {label: '[null]', value: [null]},
34
- {label: '[undefined]', value: [undefined]},
35
- {label: 'new Array(5)', value: new Array(5)},
36
-
37
- // typed arrays
38
- {label: 'Uint8Array', value: new Uint8Array([1, 2, 3])},
39
- {label: 'Buffer', value: Buffer.from('abc')},
40
-
41
- // objects
42
- {label: '{a:1}', value: {a: 1}},
43
- {label: 'Object.create(null)', value: Object.create(null)},
44
-
45
- // custom coercion
46
- {label: 'toString() => x', value: {toString() {return 'x';}}},
47
- {label: 'valueOf() => 123', value: {valueOf() {return 123;}}},
48
-
49
- // dates
50
- {label: 'new Date()', value: new Date()},
51
- {label: 'Invalid Date', value: new Date('invalid')},
52
-
53
- // regexp
54
- {label: '/foo/g', value: /foo/g},
55
-
56
- // maps/sets
57
- {label: 'Map', value: new Map()},
58
- {label: 'Set', value: new Set()},
59
- {label: 'WeakMap', value: new WeakMap()},
60
- {label: 'WeakSet', value: new WeakSet()},
61
-
62
- // promises
63
- {label: 'Promise.resolve(1)', value: Promise.resolve(1)},
64
-
65
- // errors
66
- {label: 'Error', value: new Error('boom')},
67
- {label: 'TypeError', value: new TypeError('boom')},
68
-
69
- // wrappers
70
- {label: 'new String()', value: new String('abc')},
71
- {label: 'new Number()', value: new Number(123)},
72
- {label: 'new Boolean()', value: new Boolean(false)},
73
-
74
- // url-like
75
- {label: 'new URL("https://example.com")', value: new URL('https://example.com')},
76
-
77
- // bigint
78
- {label: '1n', value: 1n},
79
- {label: '-1n', value: -1n},
80
-
81
- // special numbers
82
- {label: 'Number.EPSILON', value: Number.EPSILON},
83
-
84
- // proxy
85
- {label: 'Proxy', value: new Proxy({}, {})},
86
- ];
87
-
88
- const happy_paths = [
89
- {
90
- label: 'parses full https url',
91
- input: 'https://john:secret@example.com:8080/users/15?page=2#top',
92
- expected: {
93
- href: 'https://john:secret@example.com:8080/users/15?page=2#top',
94
- protocol: 'https:',
95
- hostname: 'example.com',
96
- username: 'john',
97
- password: 'secret',
98
- host: 'example.com:8080',
99
- port: '8080',
100
- path: '/users/15',
101
- search: '?page=2',
102
- hash: '#top',
103
- },
104
- },
105
- {
106
- label: 'parses https url without auth',
107
- input: 'https://example.com/users',
108
- expected: {
109
- href: 'https://example.com/users',
110
- protocol: 'https:',
111
- hostname: 'example.com',
112
- username: '',
113
- password: '',
114
- host: 'example.com',
115
- port: '',
116
- path: '/users',
117
- search: '',
118
- hash: '',
119
- },
120
- },
121
- {
122
- label: 'parses root url',
123
- input: 'https://example.com',
124
- expected: {
125
- href: 'https://example.com/',
126
- protocol: 'https:',
127
- hostname: 'example.com',
128
- username: '',
129
- password: '',
130
- host: 'example.com',
131
- port: '',
132
- path: '/',
133
- search: '',
134
- hash: '',
135
- },
136
- },
137
- {
138
- label: 'parses relative path',
139
- input: '/users?page=5',
140
- expected: {
141
- href: 'fake://fake/users?page=5',
142
- protocol: 'fake:',
143
- hostname: 'fake',
144
- username: '',
145
- password: '',
146
- host: 'fake',
147
- port: '',
148
- path: '/users',
149
- search: '?page=5',
150
- hash: '',
151
- },
152
- },
153
- {
154
- label: 'parses hash',
155
- input: 'https://example.com/docs#intro',
156
- expected: {
157
- href: 'https://example.com/docs#intro',
158
- protocol: 'https:',
159
- hostname: 'example.com',
160
- username: '',
161
- password: '',
162
- host: 'example.com',
163
- port: '',
164
- path: '/docs',
165
- search: '',
166
- hash: '#intro',
167
- },
168
- },
169
- {
170
- label: 'parses query string',
171
- input: 'https://example.com?a=1&b=2',
172
- expected: {
173
- href: 'https://example.com/?a=1&b=2',
174
- protocol: 'https:',
175
- hostname: 'example.com',
176
- username: '',
177
- password: '',
178
- host: 'example.com',
179
- port: '',
180
- path: '/',
181
- search: '?a=1&b=2',
182
- hash: '',
183
- },
184
- },
185
- {
186
- label: 'parses localhost with port',
187
- input: 'http://localhost:3000/foo',
188
- expected: {
189
- href: 'http://localhost:3000/foo',
190
- protocol: 'http:',
191
- hostname: 'localhost',
192
- username: '',
193
- password: '',
194
- host: 'localhost:3000',
195
- port: '3000',
196
- path: '/foo',
197
- search: '',
198
- hash: '',
199
- },
200
- },
201
- {
202
- label: 'parses ftp url',
203
- input: 'ftp://example.com/file.txt',
204
- expected: {
205
- href: 'ftp://example.com/file.txt',
206
- protocol: 'ftp:',
207
- hostname: 'example.com',
208
- username: '',
209
- password: '',
210
- host: 'example.com',
211
- port: '',
212
- path: '/file.txt',
213
- search: '',
214
- hash: '',
215
- },
216
- },
217
- ];
218
-
219
- describe('urlparts', function () {
220
- it('no args', function () {
221
- assert.deepStrictEqual(urlparts(), {
222
- href: 'fake://fake/',
223
- protocol: 'fake:',
224
- hostname: 'fake',
225
- username: '',
226
- password: '',
227
- host: 'fake',
228
- port: '',
229
- path: '/',
230
- search: '',
231
- hash: '',
232
- });
233
- });
234
-
235
- describe('happy paths', function () {
236
- for (const item of happy_paths) {
237
- it(item.label, function () {
238
- const actual = urlparts(item.input);
239
- assert.deepStrictEqual(actual, item.expected);
240
- });
241
- }
242
- });
243
-
244
- describe('edge values', function () {
245
- for (const item of [...edge_values, ...extra_edge_values]) {
246
- it(item.label, function () {
247
- if (typeof item.value === 'string') {
248
- const tmp = new URL(item.value, 'fake://fake/');
249
- assert.deepStrictEqual(urlparts(item.value), {
250
- href: tmp.href,
251
- protocol: tmp.protocol,
252
- hostname: tmp.hostname,
253
- username: tmp.username,
254
- password: tmp.password,
255
- host: tmp.host,
256
- port: tmp.port,
257
- path: tmp.pathname,
258
- search: tmp.search,
259
- hash: tmp.hash,
260
- });
261
- }
262
- else if (item.value instanceof URL) {
263
- const tmp = item.value;
264
- assert.deepStrictEqual(urlparts(item.value), {
265
- href: tmp.href,
266
- protocol: tmp.protocol,
267
- hostname: tmp.hostname,
268
- username: tmp.username,
269
- password: tmp.password,
270
- host: tmp.host,
271
- port: tmp.port,
272
- path: tmp.pathname,
273
- search: tmp.search,
274
- hash: tmp.hash,
275
- });
276
- }
277
- else {
278
- assert.deepStrictEqual(urlparts(item.value), {
279
- href: 'fake://fake/',
280
- protocol: 'fake:',
281
- hostname: 'fake',
282
- username: '',
283
- password: '',
284
- host: 'fake',
285
- port: '',
286
- path: '/',
287
- search: '',
288
- hash: '',
289
- });
290
- }
291
- });
292
- }
293
- });
294
- });